旋转矩阵的具体推理
基本知识绕x轴旋转绕y轴旋转绕z轴旋转
基本知识
首先对于一个坐标系的旋转变换,无论他怎么转,我们可以直接拆分为绕3个轴旋转,绕x轴旋转、绕y轴旋转、绕z轴旋转。(注意,以下公式均以顺时针为标准方向,使用的左手系)
那么如上图,对于绕x轴旋转,x轴本身是不会改变的,所以我们对其只需要关注
y
o
z
yoz
yoz平面就足够了。同理对于绕y轴旋转,我们只需要关注
x
o
z
xoz
xoz平面,对于z轴旋转,我们只需要关注
y
o
z
yoz
yoz平面。
之后我们又知道旋转矩阵本身就是目标坐标系的坐标轴在参考坐标系中的投影矩阵。即:
R
B
A
=
[
X
^
B
A
Y
^
B
A
Z
^
B
A
]
=
[
r
11
r
21
r
31
r
12
r
22
r
32
r
13
r
23
r
33
]
R^A_B=\begin{bmatrix} \hat{X}^A_B & \hat{Y}^A_B & \hat{Z}^A_B & \end{bmatrix}= \begin{bmatrix} r_{11}& r_{21}&r_{31}\\ r_{12}& r_{22}&r_{32}\\ r_{13}& r_{23}&r_{33}\\ \end{bmatrix}
RBA=[X^BAY^BAZ^BA]=
r11r12r13r21r22r23r31r32r33
其中,
R
B
A
R^A_B
RBA的A表示参考坐标系{A},B表示被描述的坐标系{B}。
X
^
B
A
\hat X_B^A
X^BA表示目标坐标系{B}的x轴在参考坐标系{A}的投影,
X
^
B
A
=
[
r
11
r
12
r
13
]
\hat X_B^A=\begin{bmatrix} r_{11}\\ r_{12}\\ r_{13} \end{bmatrix}
X^BA=
r11r12r13
三个r分别对应着在参考坐标系的投影。
进一步,我们设置单位向量
X
^
A
,
Y
^
A
,
Z
^
A
,
X
^
B
,
Y
^
B
,
Z
^
B
\hat{X}_A, \hat{Y}_A,\hat{Z}_A,\hat{X}_B,\hat{Y}_B,\hat{Z}_B
X^A,Y^A,Z^A,X^B,Y^B,Z^B,其中
X
^
B
\hat{X}_B
X^B为表示目标坐标系{B}的x轴。那么如此一来,对于投影计算,我们可以直接使用两向量的点积来表示,如下:
R
B
A
=
[
r
11
r
21
r
31
r
12
r
22
r
32
r
13
r
23
r
33
]
=
[
X
^
B
⋅
X
^
A
Y
^
B
⋅
X
^
A
Z
^
B
⋅
X
^
A
X
^
B
⋅
Y
^
A
Y
^
B
⋅
Y
^
A
Z
^
B
⋅
Y
^
A
X
^
B
⋅
Z
^
A
Y
^
B
⋅
Z
^
A
Z
^
B
⋅
Z
^
A
]
R^A_B= \begin{bmatrix} r_{11}& r_{21}&r_{31}\\ r_{12}& r_{22}&r_{32}\\ r_{13}& r_{23}&r_{33}\\ \end{bmatrix}= \begin{bmatrix} \hat{X}_B\cdot \hat{X}_A & \hat{Y}_B\cdot \hat{X}_A & \hat{Z}_B\cdot \hat{X}_A\\ \hat{X}_B\cdot \hat{Y}_A & \hat{Y}_B\cdot \hat{Y}_A & \hat{Z}_B\cdot \hat{Y}_A\\ \hat{X}_B\cdot \hat{Z}_A & \hat{Y}_B\cdot \hat{Z}_A & \hat{Z}_B\cdot \hat{Z}_A\\ \end{bmatrix}
RBA=
r11r12r13r21r22r23r31r32r33
=
X^B⋅X^AX^B⋅Y^AX^B⋅Z^AY^B⋅X^AY^B⋅Y^AY^B⋅Z^AZ^B⋅X^AZ^B⋅Y^AZ^B⋅Z^A
例如
X
^
B
⋅
X
^
A
\hat{X}_B\cdot \hat{X}_A
X^B⋅X^A表示目标坐标系{B}的x轴在参考坐标系{A}的x轴上的投影。
故有以下计算结果:
绕x轴旋转
R
(
x
,
θ
)
=
[
X
^
B
⋅
X
^
A
Y
^
B
⋅
X
^
A
Z
^
B
⋅
X
^
A
X
^
B
⋅
Y
^
A
Y
^
B
⋅
Y
^
A
Z
^
B
⋅
Y
^
A
X
^
B
⋅
Z
^
A
Y
^
B
⋅
Z
^
A
Z
^
B
⋅
Z
^
A
]
=
[
1
0
0
0
∣
Y
^
B
∣
⋅
∣
Y
^
A
∣
⋅
c
o
s
θ
∣
Z
^
B
∣
⋅
∣
Y
^
A
∣
⋅
c
o
s
(
π
2
+
θ
)
0
∣
Y
^
B
∣
⋅
∣
Z
^
A
∣
⋅
c
o
s
(
π
2
−
θ
)
∣
Z
^
B
∣
⋅
∣
Z
^
A
∣
⋅
c
o
s
θ
]
=
[
1
0
0
0
c
θ
−
s
θ
0
s
θ
c
θ
]
R(x,\theta)= \begin{bmatrix} \hat{X}_B\cdot \hat{X}_A & \hat{Y}_B\cdot \hat{X}_A & \hat{Z}_B\cdot \hat{X}_A\\ \hat{X}_B\cdot \hat{Y}_A & \hat{Y}_B\cdot \hat{Y}_A & \hat{Z}_B\cdot \hat{Y}_A\\ \hat{X}_B\cdot \hat{Z}_A & \hat{Y}_B\cdot \hat{Z}_A & \hat{Z}_B\cdot \hat{Z}_A\\ \end{bmatrix}\\= \begin{bmatrix} 1&0&0\\ 0&|\hat{Y}_B|\cdot |\hat{Y}_A|\cdot cos\theta&|\hat{Z}_B|\cdot |\hat{Y}_A|\cdot cos(\frac{\pi}{2}+\theta) \\ 0&|\hat{Y}_B|\cdot |\hat{Z}_A|\cdot cos(\frac{\pi}{2}-\theta)&|\hat{Z}_B|\cdot |\hat{Z}_A|\cdot cos\theta \end{bmatrix} =\begin{bmatrix} 1 & 0 & 0\\ 0 & c\theta & -s\theta\\ 0 & s\theta & c\theta \end{bmatrix}
R(x,θ)=
X^B⋅X^AX^B⋅Y^AX^B⋅Z^AY^B⋅X^AY^B⋅Y^AY^B⋅Z^AZ^B⋅X^AZ^B⋅Y^AZ^B⋅Z^A
=
1000∣Y^B∣⋅∣Y^A∣⋅cosθ∣Y^B∣⋅∣Z^A∣⋅cos(2π−θ)0∣Z^B∣⋅∣Y^A∣⋅cos(2π+θ)∣Z^B∣⋅∣Z^A∣⋅cosθ
=
1000cθsθ0−sθcθ
这里x轴不变,所以
X
B
X_B
XB在
X
A
X_A
XA的投影为
∣
X
^
B
∣
⋅
∣
X
^
A
∣
⋅
c
o
s
0
|\hat{X}_B|\cdot |\hat{X}_A| \cdot cos0
∣X^B∣⋅∣X^A∣⋅cos0=1,其余都正交,为0。
同理,有其余的:
绕y轴旋转
R
(
y
,
θ
)
=
[
X
^
B
⋅
X
^
A
Y
^
B
⋅
X
^
A
Z
^
B
⋅
X
^
A
X
^
B
⋅
Y
^
A
Y
^
B
⋅
Y
^
A
Z
^
B
⋅
Y
^
A
X
^
B
⋅
Z
^
A
Y
^
B
⋅
Z
^
A
Z
^
B
⋅
Z
^
A
]
=
[
∣
X
^
B
∣
⋅
∣
X
^
A
∣
⋅
c
o
s
θ
0
∣
Z
^
B
∣
⋅
∣
X
^
A
∣
⋅
c
o
s
(
π
2
−
θ
)
0
1
0
∣
X
^
B
∣
⋅
∣
Z
^
A
∣
⋅
c
o
s
(
π
2
+
θ
)
0
∣
Z
^
B
∣
⋅
∣
Z
^
A
∣
⋅
c
o
s
θ
]
=
[
c
θ
0
s
θ
0
1
0
−
s
θ
0
c
θ
]
R(y,\theta)= \begin{bmatrix} \hat{X}_B\cdot \hat{X}_A & \hat{Y}_B\cdot \hat{X}_A & \hat{Z}_B\cdot \hat{X}_A\\ \hat{X}_B\cdot \hat{Y}_A & \hat{Y}_B\cdot \hat{Y}_A & \hat{Z}_B\cdot \hat{Y}_A\\ \hat{X}_B\cdot \hat{Z}_A & \hat{Y}_B\cdot \hat{Z}_A & \hat{Z}_B\cdot \hat{Z}_A\\ \end{bmatrix}\\= \begin{bmatrix} |\hat{X}_B|\cdot |\hat{X}_A|\cdot cos\theta&0&|\hat{Z}_B|\cdot |\hat{X}_A|\cdot cos(\frac{\pi}{2}-\theta)\\ 0&1&0\\ |\hat{X}_B|\cdot |\hat{Z}_A|\cdot cos(\frac{\pi}{2}+\theta)&0&|\hat{Z}_B|\cdot |\hat{Z}_A|\cdot cos\theta \end{bmatrix} =\begin{bmatrix} c\theta&0&s\theta\\ 0&1&0\\ -s\theta&0&c\theta \end{bmatrix}
R(y,θ)=
X^B⋅X^AX^B⋅Y^AX^B⋅Z^AY^B⋅X^AY^B⋅Y^AY^B⋅Z^AZ^B⋅X^AZ^B⋅Y^AZ^B⋅Z^A
=
∣X^B∣⋅∣X^A∣⋅cosθ0∣X^B∣⋅∣Z^A∣⋅cos(2π+θ)010∣Z^B∣⋅∣X^A∣⋅cos(2π−θ)0∣Z^B∣⋅∣Z^A∣⋅cosθ
=
cθ0−sθ010sθ0cθ
绕z轴旋转
R
(
y
,
θ
)
=
[
X
^
B
⋅
X
^
A
Y
^
B
⋅
X
^
A
Z
^
B
⋅
X
^
A
X
^
B
⋅
Y
^
A
Y
^
B
⋅
Y
^
A
Z
^
B
⋅
Y
^
A
X
^
B
⋅
Z
^
A
Y
^
B
⋅
Z
^
A
Z
^
B
⋅
Z
^
A
]
=
[
∣
X
^
B
∣
⋅
∣
X
^
A
∣
⋅
c
o
s
θ
∣
Y
^
B
∣
⋅
∣
X
^
A
∣
⋅
c
o
s
(
π
2
+
θ
)
0
∣
X
^
B
∣
⋅
∣
Y
^
A
∣
⋅
c
o
s
(
π
2
−
θ
)
∣
Y
^
B
∣
⋅
∣
Y
^
A
∣
⋅
c
o
s
θ
0
0
0
1
]
=
[
c
θ
−
s
θ
0
s
θ
c
θ
0
0
0
1
]
R(y,\theta)= \begin{bmatrix} \hat{X}_B\cdot \hat{X}_A & \hat{Y}_B\cdot \hat{X}_A & \hat{Z}_B\cdot \hat{X}_A\\ \hat{X}_B\cdot \hat{Y}_A & \hat{Y}_B\cdot \hat{Y}_A & \hat{Z}_B\cdot \hat{Y}_A\\ \hat{X}_B\cdot \hat{Z}_A & \hat{Y}_B\cdot \hat{Z}_A & \hat{Z}_B\cdot \hat{Z}_A\\ \end{bmatrix}\\= \begin{bmatrix} |\hat{X}_B|\cdot |\hat{X}_A|\cdot cos\theta&|\hat{Y}_B|\cdot |\hat{X}_A|\cdot cos(\frac{\pi}{2}+\theta)&0\\ |\hat{X}_B|\cdot |\hat{Y}_A|\cdot cos(\frac{\pi}{2}-\theta)&|\hat{Y}_B|\cdot |\hat{Y}_A|\cdot cos\theta&0\\ 0&0&1 \end{bmatrix} =\begin{bmatrix} c\theta & -s\theta&0\\ s\theta & c\theta&0\\ 0&0&1 \end{bmatrix}
R(y,θ)=
X^B⋅X^AX^B⋅Y^AX^B⋅Z^AY^B⋅X^AY^B⋅Y^AY^B⋅Z^AZ^B⋅X^AZ^B⋅Y^AZ^B⋅Z^A
=
∣X^B∣⋅∣X^A∣⋅cosθ∣X^B∣⋅∣Y^A∣⋅cos(2π−θ)0∣Y^B∣⋅∣X^A∣⋅cos(2π+θ)∣Y^B∣⋅∣Y^A∣⋅cosθ0001
=
cθsθ0−sθcθ0001