rotate3d速记 [英] rotate3d shorthand

查看:116
本文介绍了rotate3d速记的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何结合 rotateX(50deg)rotateY(20deg)rotateZ(15deg)以简写 rotate3d()

解决方案

rotateX(50deg)等效于 rotate3d(1,0,0,50deg)



rotateY(20deg)相当于 rotate3d(0,1,0,20deg)



rotateZ )等效于 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)






c $ c> rotate3d(x,y,z,α),你有矩阵





其中








现在可以得到3个 rotate3d 变换的矩阵,并将它们相乘。结果矩阵是对应于结果单个 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



row: cos(20deg)0 sin(20deg)0



第二行: 0 1 0 0



第三行: -sin(20)0 cos(20deg)0



第四: 0 0 0 1


$ b b


在第三种情况下,您有 x = 0 y = code>, z = 1 α= 15deg



第一行: cos(15deg)-sin(15deg)0 0



sin(15deg)cos(15deg)0 0



第三行和第四行是 0 0 1 0 0 0 0 1






:您可能已经注意到,rotateY变换的sin值的符号与其他两个变换的符号不同。这不是计算错误。原因是,对于屏幕,您的y轴向下,不向上。




所以这些是三个 4x4 矩阵,你需要乘以以获得 4x4 导致单个 rotate3d 变换。正如我所说,我不知道如何容易得到4值,但4x4矩阵中的16个元素是 matrix3d





b

实际上,它很容易...你可以计算 rotate3d 矩阵的矩阵的轨迹(对角线元素的总和)。



4 - 2 * 2 *(1 - cos(α))/ 2 = 4 - 2 *(1 - cos = 2 + 2 * cos(α)



然后计算三个 4x4 矩阵,您将结果与 2 + 2 * cos(α)等同。α 。然后计算 x y z p>

在这种特殊情况下,如果我正确计算,由三个 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 c $ c>,这意味着α= acos(T / 2-1)


How to combine rotateX(50deg) rotateY(20deg) rotateZ(15deg) in shorthand rotate3d()?

解决方案

rotateX(50deg) is equivalent to rotate3d(1, 0, 0, 50deg)

rotateY(20deg) is equivalent to rotate3d(0, 1, 0, 20deg)

rotateZ(15deg) is equivalent to rotate3d(0, 0, 1, 15deg)

So...

rotateX(50deg) rotateY(20deg) rotateZ(15deg)

is equivalent to

rotate3d(1, 0, 0, 50deg) rotate3d(0, 1, 0, 20deg) rotate3d(0, 0, 1, 15deg)


For a generic rotate3d(x, y, z, α), you have the matrix

where


You now get the matrices for each of the 3 rotate3d transforms and you multiply them. And the resulting matrix is the matrix corresponding to the resulting single rotate3d. Not sure how to easy it is to extract the values for rotate3d out of it, but it's sure easy to extract those for a single matrix3d.


In the first case (rotateX(50deg) or rotate3d(1, 0, 0, 50deg)), you have:

x = 1, y = 0, z = 0, α = 50deg

So the first row of the matrix in this case is 1 0 0 0.

The second one is 0 cos(50deg) -sin(50deg) 0.

The third one 0 sin(50deg) cos(50deg) 0.

And the fourth one is obviously 0 0 0 1.


In the second case, you have x = 0, y = 1, z = 0, α = 20deg.

First row: cos(20deg) 0 sin(20deg) 0.

Second row: 0 1 0 0.

Third row: -sin(20) 0 cos(20deg) 0.

Fourth: 0 0 0 1


In the third case, you have x = 0, y = 0, z = 1, α = 15deg.

First row: cos(15deg) -sin(15deg) 0 0.

Second row sin(15deg) cos(15deg) 0 0.

And the third and the fourth row are 0 0 1 0 and 0 0 0 1 respectively.


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.


So these are the three 4x4 matrices that you need to multiply in order to get the 4x4 matrix for the resulting single rotate3d transform. As I've said, I'm not sure how easy it can be to get the 4 values out, but the 16 elements in the 4x4 matrix are exactly the 16 parameters of the matrix3d equivalent of the chained transform.


EDIT:

Actually, it turns out it's pretty easy... You compute the trace (sum of diagonal elements) of the matrix for the rotate3d matrix.

4 - 2*2*(1 - cos(α))/2 = 4 - 2*(1 - cos(α)) = 2 + 2*cos(α)

You then compute the trace for the product of the three 4x4 matrices, you equate the result with 2 + 2*cos(α) you extract α. Then you compute x, y, z.

In this particular case, if I computed correctly, the trace of the matrix resulting from the product of the three 4x4 matrices is going to be:

T = 
cos(20deg)*cos(15deg) + 
cos(50deg)*cos(15deg) - sin(50deg)*sin(20deg)*cos(15deg) + 
cos(50deg)*cos(20deg) + 
1

So cos(α) = (T - 2)/2 = T/2 - 1, which means that α = acos(T/2 - 1).

这篇关于rotate3d速记的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆