一步步推导由欧拉角到旋转矩阵的计算过程

为了便于理解,我们先来做一道简单的数学题:

如图,坐标系 O X 1 Y 1 OX_1Y_1 OX1Y1经过逆时针旋转 θ \theta θ角变换为坐标系 O X 2 Y 2 OX_2Y_2 OX2Y2,P点坐标由 ( x 1 , y 1 ) (x_1,y_1) (x1,y1) ( x 2 , y 2 ) (x_2,y_2) (x2,y2)
:怎样用用 x 1 , y 1 , θ x_1,y_1,\theta x1,y1,θ表示 x 2 , y 2 x_2,y_2 x2,y2
一步步推导由欧拉角到旋转矩阵的计算过程_第1张图片

由图可得:
(1) a = y 1 − b = y 1 − x 1 t a n θ a=y_1-b=y_1-x_1tan\theta\tag{1} a=y1b=y1x1tanθ(1)
(2) x 2 = c + d = a s i n θ + x 1 c o s θ x_2 = c + d = asin\theta + \frac{x_1}{cos\theta} \tag{2} x2=c+d=asinθ+cosθx1(2)
(3) y 2 = a c o s θ y_2 = a cos\theta \tag{3} y2=acosθ(3)
将(1)式代入(2)、(3)式并化简得:
(4) x 2 = x 1 c o s θ + y 1 s i n θ x_2 = x_1cos\theta+y_1sin\theta \tag{4} x2=x1cosθ+y1sinθ(4)
(5) y 2 = − x 1 s i n θ + y 1 c o s θ y_2 = -x_1sin\theta + y_1cos\theta \tag{5} y2=x1sinθ+y1cosθ(5)
(4)、(5)式的矩阵形式表示:
(6) [ x 2 y 2 ] = [ c o s θ s i n θ − s i n θ c o s θ ] [ x 1 y 1 ] \left[ \begin{matrix} x_2 \\ y_2 \\ \end{matrix} \right]=\\ \left[ \begin{matrix} cos\theta & sin\theta\\ -sin\theta & cos\theta \end{matrix} \right] \left[ \begin{matrix} x_1 \\ y_1 \end{matrix} \right] \tag{6} [x2y2]=[cosθsinθsinθcosθ][x1y1](6)
该式子展开即与(4)、(5)式形式完全相同。

(这个过程希望大家亲手用笔算一下,只是一个简单的几何问题,并没有难以理解的地方,只有深刻理解了这个转换过程才能理解接下来的三维空间直角坐标系)

三维坐标系

其实对于三维空间直角坐标系的旋转变换,形式上和二维空间中的一样,只是二维坐标系中我们只需要旋转一次,而三维坐标系中我们需要旋转3次。即:
(1) 绕 X X X 轴旋转 ε X \varepsilon_X εX 角。
(2) 绕 Y Y Y 轴旋转 ε Y \varepsilon_Y εY 角。
(3) 绕 Z Z Z 轴旋转 ε Z \varepsilon_Z εZ 角。
此处 ε X , ε Y , ε Z \varepsilon_X,\varepsilon_Y,\varepsilon_Z εX,εY,εZ即为三维空间直角坐标变换的三个旋转角,也称为欧拉角

下面进行公式推导

(1) 绕 X X X 轴旋转 ε X \varepsilon_X εX 角。

即:X坐标不变,Y,Z坐标变换,如图:
一步步推导由欧拉角到旋转矩阵的计算过程_第2张图片
现在类比一下我们之前推导的二维坐标系中的情况
不看X轴,把这里的Y、Z轴看成之前的X、Y轴,这里的 ε X \varepsilon_X εX看之前的 θ \theta θ
得:
(7) [ y 2 z 2 ] = [ c o s ε X s i n ε X − s i n ε X c o s ε X ] [ y 1 z 1 ] \left[ \begin{matrix} y_2 \\ z_2 \\ \end{matrix} \right]=\\ \left[ \begin{matrix} cos\varepsilon_X & sin\varepsilon_X\\ -sin\varepsilon_X & cos\varepsilon_X \end{matrix} \right] \left[ \begin{matrix} y_1 \\ z_1 \end{matrix} \right] \tag{7} [y2z2]=[cosεXsinεXsinεXcosεX][y1z1](7)
加上没有变化的 x x x:
(8) [ x 2 y 2 z 2 ] = [ 1 0 0 0 c o s ε X s i n ε X 0 − s i n ε X c o s ε X ] [ x 1 y 1 z 1 ] \left[ \begin{matrix} x_2\\ y_2 \\ z_2 \\ \end{matrix} \right]=\\ \left[ \begin{matrix} 1 & 0 & 0\\ 0 & cos\varepsilon_X & sin\varepsilon_X\\ 0 & -sin\varepsilon_X & cos\varepsilon_X \end{matrix} \right] \left[ \begin{matrix} x_1 \\ y_1 \\ z_1 \end{matrix} \right] \tag{8} x2y2z2=1000cosεXsinεX0sinεXcosεXx1y1z1(8)
(7)式和(8)式的展开形式其实一样,仅仅多了一个 x 2 = x 1 x_2=x_1 x2=x1
到这里,我们找到了第一个旋转矩阵:
(9) R 1 ( ε X ) = [ 1 0 0 0 c o s ε X s i n ε X 0 − s i n ε X c o s ε X ] R_1(\varepsilon_X)= \left[ \begin{matrix} 1 & 0 & 0\\ 0 & cos\varepsilon_X & sin\varepsilon_X\\ 0 & -sin\varepsilon_X & cos\varepsilon_X \end{matrix} \right] \tag{9} R1(εX)=1000cosεXsinεX0sinεXcosεX(9)
至此,完成了第一次旋转操作

(2) 绕 Y Y Y 轴旋转 ε Y \varepsilon_Y εY

与前面同理,找到第二个旋转矩阵:
(10) R 2 ( ε Y ) = [ c o s ε Y 0 − s i n ε Y 0 1 0 s i n ε Y c o s ε Y 0 ] R_2(\varepsilon_Y)= \left[ \begin{matrix} cos\varepsilon_Y & 0 &-sin\varepsilon_Y\\ 0 & 1 &0\\ sin\varepsilon_Y& cos\varepsilon_Y& 0 \end{matrix} \right] \tag{10} R2(εY)=cosεY0sinεY01cosεYsinεY00(10)

(3) 绕 Z Z Z 轴旋转 ε Z \varepsilon_Z εZ

与前面同理,找到第三个旋转矩阵:
(11) R 3 ( ε Z ) = [ c o s ε Z s i n ε Z 0 − s i n ε Z c o s ε Z 0 0 0 1 ] R_3(\varepsilon_Z)= \left[ \begin{matrix} cos\varepsilon_Z & sin\varepsilon_Z &0\\ -sin\varepsilon_Z &cos\varepsilon_Z &0\\ 0& 0& 1 \end{matrix} \right] \tag{11} R3(εZ)=cosεZsinεZ0sinεZcosεZ0001(11)

现在,我们分别找到了绕三个轴旋转的旋转矩阵

(4) 合并三次旋转

令: R 0 = R 1 ( ε X ) R 2 ( ε Y ) R 3 ( ε Z ) R_0 = R_1(\varepsilon_X)R_2(\varepsilon_Y)R_3(\varepsilon_Z) R0=R1(εX)R2(εY)R3(εZ)
有:
(12) [ X 2 Y 2 Z 2 ] = R 1 ( ε X ) R 2 ( ε Y ) R 3 ( ε Z ) [ X 1 Y 1 Z 1 ] = R 0 [ X 1 Y 1 Z 1 ] \left[ \begin{matrix} X_2\\ Y_2\\ Z_2 \end{matrix} \right] =\\ R_1(\varepsilon_X)R_2(\varepsilon_Y)R_3(\varepsilon_Z) \left[ \begin{matrix} X_1\\ Y_1\\ Z_1 \end{matrix} \right]=\\ R_0 \left[ \begin{matrix} X_1\\ Y_1\\ Z_1 \end{matrix} \right] \tag{12} X2Y2Z2=R1(εX)R2(εY)R3(εZ)X1Y1Z1=R0X1Y1Z1(12)
将(9)、(10)、(11)式代入(12)式得:
(13) R 0 = [ c o s ε Y c o s ε Z c o s ε Y s i n ε Z − s i n ε Y − c o s ε X s i n ε Z + s i n ε X s i n ε Y c o s ε Z c o s ε X c o s ε Z + s i n ε X s i n ε Y s i n ε Z s i n ε X c o s ε Y s i n ε X s i n ε Z + c o s ε X s i n ε Y c o s ε Z − s i n ε X c o s ε Z + c o s ε X s i n ε Y s i n ε Z c o s ε X c o s ε Y ] R_0=\\ \left[ \begin{matrix} cos\varepsilon_Ycos\varepsilon_Z & cos\varepsilon_Ysin\varepsilon_Z & -sin\varepsilon_Y\\ -cos\varepsilon_Xsin\varepsilon_Z+sin\varepsilon_Xsin\varepsilon_Ycos\varepsilon_Z & cos\varepsilon_Xcos\varepsilon_Z+sin\varepsilon_Xsin\varepsilon_Ysin\varepsilon_Z & sin\varepsilon_Xcos\varepsilon_Y\\ sin\varepsilon_Xsin\varepsilon_Z+cos\varepsilon_Xsin\varepsilon_Ycos\varepsilon_Z & -sin\varepsilon_Xcos\varepsilon_Z+cos\varepsilon_Xsin\varepsilon_Ysin\varepsilon_Z & cos\varepsilon_Xcos\varepsilon_Y\\ \end{matrix} \right] \tag{13} R0=cosεYcosεZcosεXsinεZ+sinεXsinεYcosεZsinεXsinεZ+cosεXsinεYcosεZcosεYsinεZcosεXcosεZ+sinεXsinεYsinεZsinεXcosεZ+cosεXsinεYsinεZsinεYsinεXcosεYcosεXcosεY(13)
到这里,我们的计算工作就结束了,最终求出的 R 0 R_0 R0就是我们所需要的旋转矩阵

(PS:大家知道,矩阵乘法没有交换律,所以我们进行三次旋转的顺序不同,最终得到的旋转矩阵也不一样,这里用的是X-Y-Z的的旋转顺序。)

你可能感兴趣的:(数学与算法)