内容
- 2D中绕原点旋转
- 2D中绕任意点旋转
- 3D中绕坐标轴旋转
- 3D中绕任意轴旋转
1. 2D中绕原点旋转
在二维坐标系中,物体只能绕点旋转;且逆时针旋转经常(不是必须)被认为是正方向。
设物体在二维坐标系中,绕原点旋转θ度角,求旋转矩阵:
如下图,原坐标系基向量 p,q 绕原点旋转,得到新的基向量 p',q'。
知道了旋转后基向量的值,就可以如下所示用基向量造旋转矩阵:
或者是:
旋转后的坐标为:
2. 2D中绕任意点旋转
已知物体绕原点的旋转矩阵,那么绕任意一点的旋转,可以分解为平移,旋转,反平移这三个过程,可以分别求变换矩阵。
设点,,求点绕点旋转度角的旋转矩阵:
-
平移:将P点坐标平移,平移矩阵如下:
-
旋转:将平移后的P点绕原点旋转度,旋转矩阵如下:
-
反平移:将旋转后的坐标平移回去,平移矩阵如下:
综上,点绕点旋转度得到的坐标点为:d
因此,点的坐标为:
3. 3D中绕坐标轴旋转
在3D场景中,绕轴旋转而不是绕点旋转(轴是指旋转所绕的直线,不一定是笛卡尔坐标系的x,y,z轴)。这里暂不考虑平移,所以只讨论旋转轴穿过原点的情况。
和2D场景中相似,在讨论旋转之前,首先要明确旋转的正方向。这里需要区分左手坐标系和右手坐标系,比如左手坐标系中,定义旋转正方向的法则称为左手法则:伸出左手,大拇指指向旋转轴的正方向,其余四指弯曲的方向就是旋转的正方向。右手坐标系中也有类似的右手法则,不过使用右手代替左手。
- 先从绕x轴旋转开始,如图:
求出旋转后的基向量,可以得到矩阵:
- 绕y轴与之类似,如图:
可得绕y轴旋转的矩阵:
- 最后是绕z轴旋转,如图:
可得绕y轴旋转的矩阵:
4. 3D中绕任意轴旋转
在不考虑平移的情况下,假设旋转轴通过原点,设单位向量n为旋转轴θ为旋转量。我们想要求出绕轴n旋转角度θ的矩阵。也就是说,我们想得到满足下面条件的矩阵R(n,θ),其中v'是向量v绕轴n旋转后的向量:
如何用v,n和θ表示v',我们的想法是在垂直于n的平面中解决这个问题,那么这就转化为了一个简单的2D问题。为了做到这一点,将v分解为两个分向量: 和,分别平行和垂直于n,并且有。因为平行于n ,所以绕n旋转不会影响到它。固只要计算出绕n旋转后的,就能得到。如下图所示,为了计算,我们构造了向量,和临时向量w:
- 是v平行于n的分量。或者说是是v在n上的投影,即:
- 是v垂直于n的分量,也是v投影到垂直于n的平面上的结果:
- w是同时垂直于和的向量。它的长度和的相同。w和同在垂直于n的平面中,w是绕n旋转90°的结果,即:
如上图所示,可以表示为:
代入的表达式,有:
现在,已经得到了v'和v,n,θ的关系式了,可以用它来计算变换后的基向量并构造矩阵。
第一个基向量为:
另外两个基向量的推导与之类似,有:
用这些基向量构造矩阵,可得公式为: