点绕坐标系旋转旋转矩阵推导、理解
开会过程中,翻笔记本时突然发现了之前推导的点绕坐标系旋转的旋转矩阵求解过程。在直觉上,一个点绕3个坐标轴旋转的旋转矩阵在形式上看起来是一致的,观感上比较优雅、整齐,但是一直没有仔细观察背后的原理。因此又对这个过程进行了一次推导,对这种整齐有了更深的理解,同时对记忆也有所帮助。特此记录。
由于我们提到三维坐标系时,常用XYZ
三个字母代替3个轴,为了不失一般性,避免字母先入为主产生的印象,在这里用UVW
来指代右手三维坐标系。
大拇指指向轴线方向,四指方向为旋转的正方向
如下图所示。 坐标系UVW
为右手坐标系,一个点绕W
轴旋转
θ
\theta
θ角度前后的坐标为
(
U
′
,
V
′
)
−
−
−
>
(
U
,
V
)
(U^{'},V^{'})--->(U,V)
(U′,V′)−−−>(U,V) 求解旋转后的坐标(旋转矩阵)。
为了方便求解,定义2个中间变量
R
,
δ
R,\delta
R,δ,R
表示点到原点的距离,在旋转前后,点到原点的距离不变。
则有下列公式成立:
{
U
′
=
R
∗
c
o
s
δ
V
′
=
R
∗
s
i
n
δ
(1)
\left\{ \begin{aligned} U^{'} = R*cos\delta \\ V^{'} = R*sin\delta \\ \tag{1} \end{aligned} \right.
{U′=R∗cosδV′=R∗sinδ(1)
{
U
=
R
∗
c
o
s
(
δ
+
θ
)
=
R
∗
(
c
o
s
δ
c
o
s
θ
−
s
i
n
δ
s
i
n
θ
)
V
=
R
∗
s
i
n
(
δ
+
θ
)
=
R
∗
(
s
i
n
δ
c
o
s
θ
+
c
o
s
δ
s
i
n
θ
)
(2)
\left\{ \begin{aligned} U = R*cos(\delta+\theta) =R*(cos{\delta}cos{\theta}-sin{\delta}sin{\theta})\\ V = R*sin(\delta+\theta) =R*(sin{\delta}cos{\theta}+cos{\delta}sin{\theta}) \\ \tag{2} \end{aligned} \right.
{U=R∗cos(δ+θ)=R∗(cosδcosθ−sinδsinθ)V=R∗sin(δ+θ)=R∗(sinδcosθ+cosδsinθ)(2)
将式(1)
和式(2)
结合:
{
U
=
R
∗
(
c
o
s
δ
c
o
s
θ
−
s
i
n
δ
s
i
n
θ
)
=
U
′
c
o
s
θ
−
V
′
s
i
n
θ
V
=
R
∗
(
s
i
n
δ
c
o
s
θ
+
c
o
s
δ
s
i
n
θ
)
=
U
′
s
i
n
θ
+
V
′
c
o
s
θ
(3)
\left\{ \begin{aligned} U = R*(cos{\delta}cos{\theta}-sin{\delta}sin{\theta})=U^{'}cos{\theta}-V^{'}sin{\theta}\\ V = R*(sin{\delta}cos{\theta}+cos{\delta}sin{\theta})=U^{'}sin{\theta}+V^{'}cos{\theta} \\ \tag{3} \end{aligned} \right.
{U=R∗(cosδcosθ−sinδsinθ)=U′cosθ−V′sinθV=R∗(sinδcosθ+cosδsinθ)=U′sinθ+V′cosθ(3)
旋转前后点的W
坐标不变,那么旋转后点的坐标可表示如下:
{
U
=
U
′
c
o
s
θ
−
V
′
s
i
n
θ
V
=
U
′
s
i
n
θ
+
V
′
c
o
s
θ
W
=
W
′
(4)
\left\{ \begin{aligned} U & =U^{'}cos{\theta}-V^{'}sin{\theta}\\ V &= U^{'}sin{\theta}+V^{'}cos{\theta} \\ W &= W^{'} \\ \tag{4} \end{aligned} \right.
⎩⎪⎪⎨⎪⎪⎧UVW=U′cosθ−V′sinθ=U′sinθ+V′cosθ=W′(4)
将上面写为矩阵的形式:
[
U
V
W
]
=
[
c
o
s
θ
−
s
i
n
θ
0
s
i
n
θ
c
o
s
θ
0
0
0
1
]
[
U
′
V
′
W
′
]
(5)
\begin{bmatrix} U \\ V \\ W \end{bmatrix} = \begin{bmatrix} cos{\theta} & -sin{\theta} & 0 \\ sin{\theta} & cos{\theta} & 0 \\ 0 & 0 & 1 \end{bmatrix} \begin{bmatrix} U^{'} \\ V^{'} \\ W^{'} \tag{5} \end{bmatrix}
⎣⎡UVW⎦⎤=⎣⎡cosθsinθ0−sinθcosθ0001⎦⎤⎣⎡U′V′W′⎦⎤(5)
将式(5)
与图坐标系图放在一起进行考虑,如下图所示:
矩阵的第1行为旋转正方向的起点轴,第2行为旋转正方向的终点轴,第3行为旋转轴.
按照上面说明,我们在来回退到常用的XYZ
代号的坐标系中.
1.点绕Z
轴旋转,那么旋转正方向是由X
指向Y
,因此在上面图中,将UV
分别替换为X,Y
,W
替换为Z
,可得:
[
X
Y
Z
]
=
[
c
o
s
θ
−
s
i
n
θ
0
s
i
n
θ
c
o
s
θ
0
0
0
1
]
[
X
′
Y
′
Z
′
]
(6)
\begin{bmatrix} X \\ Y \\ Z \end{bmatrix} = \begin{bmatrix} cos{\theta} & -sin{\theta} & 0 \\ sin{\theta} & cos{\theta} & 0 \\ 0 & 0 & 1 \end{bmatrix} \begin{bmatrix} X^{'} \\ Y^{'} \\ Z^{'} \tag{6} \end{bmatrix}
⎣⎡XYZ⎦⎤=⎣⎡cosθsinθ0−sinθcosθ0001⎦⎤⎣⎡X′Y′Z′⎦⎤(6)
2.点绕Y
轴旋转,那么旋转正方向是由Z
指向X
,因此在上面图中,将UV
分别替换为Z,X
,W
替换为Y
,可得:
[
Z
X
Y
]
=
[
c
o
s
θ
−
s
i
n
θ
0
s
i
n
θ
c
o
s
θ
0
0
0
1
]
[
Z
′
X
′
Y
′
]
(7)
\begin{bmatrix} Z \\ X \\ Y \end{bmatrix} = \begin{bmatrix} cos{\theta} & -sin{\theta} & 0 \\ sin{\theta} & cos{\theta} & 0 \\ 0 & 0 & 1 \end{bmatrix} \begin{bmatrix} Z^{'} \\ X^{'} \\ Y^{'} \tag{7} \end{bmatrix}
⎣⎡ZXY⎦⎤=⎣⎡cosθsinθ0−sinθcosθ0001⎦⎤⎣⎡Z′X′Y′⎦⎤(7)
将上式展开,然后调整顺序并整理,可得:
[
X
Y
Z
]
=
[
c
o
s
θ
0
s
i
n
θ
0
1
0
−
s
i
n
θ
0
c
o
s
θ
]
[
X
′
Y
′
Z
′
]
(8)
\begin{bmatrix} X \\ Y \\ Z \end{bmatrix} = \begin{bmatrix} cos{\theta} & 0 & sin{\theta} \\ 0 & 1 & 0 \\ -sin{\theta} & 0 & cos{\theta} \end{bmatrix} \begin{bmatrix} X^{'} \\ Y^{'} \\ Z^{'} \tag{8} \end{bmatrix}
⎣⎡XYZ⎦⎤=⎣⎡cosθ0−sinθ010sinθ0cosθ⎦⎤⎣⎡X′Y′Z′⎦⎤(8)
3.点绕X
轴旋转,那么旋转正方向是由Y
指向Z
,因此在上面图中,将UV
分别替换为Y,Z
,W
替换为X
,可得:
[
Y
Z
X
]
=
[
c
o
s
θ
−
s
i
n
θ
0
s
i
n
θ
c
o
s
θ
0
0
0
1
]
[
Y
′
Z
′
X
′
]
(9)
\begin{bmatrix} Y \\ Z \\ X \end{bmatrix} = \begin{bmatrix} cos{\theta} & -sin{\theta} & 0 \\ sin{\theta} & cos{\theta} & 0 \\ 0 & 0 & 1 \end{bmatrix} \begin{bmatrix} Y^{'} \\ Z^{'} \\ X^{'} \tag{9} \end{bmatrix}
⎣⎡YZX⎦⎤=⎣⎡cosθsinθ0−sinθcosθ0001⎦⎤⎣⎡Y′Z′X′⎦⎤(9)
将上式展开,然后调整顺序并整理,可得:
[
X
Y
Z
]
=
[
1
0
0
0
c
o
s
θ
−
s
i
n
θ
0
s
i
n
θ
c
o
s
θ
]
[
X
′
Y
′
Z
′
]
(10)
\begin{bmatrix} X \\ Y \\ Z \end{bmatrix} = \begin{bmatrix} 1 & 0 & 0 \\ 0 & cos{\theta} & -sin{\theta} \\ 0 & sin{\theta} & cos{\theta} \end{bmatrix} \begin{bmatrix} X^{'} \\ Y^{'} \\ Z^{'} \tag{10} \end{bmatrix}
⎣⎡XYZ⎦⎤=⎣⎡1000cosθsinθ0−sinθcosθ⎦⎤⎣⎡X′Y′Z′⎦⎤(10)
综上,可以方便记忆坐标系中一个点绕X,Y,Z
三轴的旋转矩阵.