rotateX(50deg)
等于rotate3d(1, 0, 0, 50deg)
rotateY(20deg)
等于rotate3d(0, 1, 0, 20deg)
rotateZ(15deg)
等于rotate3d(0, 0, 1, 15deg)
所以...
rotateX(50deg) rotateY(20deg) rotateZ(15deg)
个
相当于
rotate3d(1, 0, 0, 50deg) rotate3d(0, 1, 0, 20deg) rotate3d(0, 0, 1, 15deg)
个
对于一般的rotate3d(x, y, z, α)
,你有矩阵
哪里
现在,你可以得到3rotate3d
个变换的矩阵,然后将它们相乘.所得矩阵是对应于所得单个rotate3d
的矩阵.不确定如何容易从中提取rotate3d
的值,但提取单个matrix3d
的值肯定很容易.
在第一种情况下(rotateX(50deg)
或rotate3d(1, 0, 0, 50deg)
),您有:
x = 1
、y = 0
、z = 0
、α = 50deg
所以在本例中,矩阵的第一行是1 0 0 0
.
第二个是0 cos(50deg) -sin(50deg) 0
.
第三个是0 sin(50deg) cos(50deg) 0
美元.
第四个显然是0 0 0 1
.
在第二种情况下,您有x = 0
,y = 1
,z = 0
,α = 20deg
.
第一排:cos(20deg) 0 sin(20deg) 0
.
第二排:0 1 0 0
.
第三排:-sin(20) 0 cos(20deg) 0
.
第四名:0 0 0 1
在第三种情况下,您有x = 0
,y = 0
,z = 1
,α = 15deg
.
第一排:cos(15deg) -sin(15deg) 0 0
.
第二排sin(15deg) cos(15deg) 0 0
.
第三行和第四行分别是0 0 1 0
和0 0 0 1
.
Note: you may have noticed that the signs of the sin values for the rotateY transform are different than for the other two transforms. It's not a computation mistake. The reason for this is that, for the screen, you have the y-axis pointing down, not up.
这是三个4x4
矩阵,您需要将它们相乘,才能得到得到的单个rotate3d
变换的4x4
矩阵.正如我已经说过的,我不确定取出这4个值有多容易,但是4x4矩阵中的16个元素正好是matrix3d
个等价于链接转换的参数的16个参数.
EDIT:
实际上,事实证明这很容易……您可以计算rotate3d
矩阵的矩阵的迹(对角线元素之和).
4 - 2*2*(1 - cos(α))/2 = 4 - 2*(1 - cos(α)) = 2 + 2*cos(α)
个
然后计算三个4x4
矩阵乘积的轨迹,将结果与2 + 2*cos(α)
相等,然后提取α
.然后计算x
y
z
.
在这种特殊情况下,如果我计算正确,由三个4x4
矩阵的乘积得到的矩阵轨迹将是:
T =
cos(20deg)*cos(15deg) +
cos(50deg)*cos(15deg) - sin(50deg)*sin(20deg)*cos(15deg) +
cos(50deg)*cos(20deg) +
1
所以cos(α) = (T - 2)/2 = T/2 - 1
,也就是α = acos(T/2 - 1)
.