本篇文章主要是解释 如何从数学上刻画 一个向量绕一个轴旋转 得到最终的向量的表达式,主要内容可参见Rodrigues formula.
从2D 谈起
不失一般性,我们考虑下图, 向量1,坐标为
p
1
=
(
x
,
y
)
\mathbf{p}_1 =(x,y)
p1=(x,y) 绕
x
x
x轴 (水平轴) 逆时针旋转
θ
\theta
θ角得到向量2,坐标为
p
2
=
(
x
′
,
y
′
)
\mathbf{p}_2 = (x',y')
p2=(x′,y′),此时向量2在该坐标系下的表示如下图所示
Observation 1
该公式的推导非常简单,假设向量1与
x
x
x轴的夹角为
α
\alpha
α, 利用三角函数求和公式阔以直接得到,故此不再赘述。
观察
p
′
=
(
x
′
,
y
′
)
\mathbf{p}' = (x',y')
p′=(x′,y′)的表达式,跟欧拉公式
e
j
θ
=
cos
(
θ
)
+
j
sin
(
θ
)
,
j
2
=
−
1
e^{j \theta} = \cos(\theta) + j \sin(\theta), j^2= -1
ejθ=cos(θ)+jsin(θ),j2=−1
联系起来,将
x
x
x轴看作
R
e
Re
Re实轴,
y
y
y轴看作
I
m
Im
Im轴,此时向量1可以用一个复数
p
1
=
x
+
j
y
p_1 = x+ jy
p1=x+jy表示,类似地, 向量2可以用一个复数
p
2
=
x
′
+
j
y
′
p_2= x'+ j y'
p2=x′+jy′表示。利用复数乘法, 向量2可以表示为
p
2
=
e
j
θ
p
1
p_2 = e^{j \theta} p_1
p2=ejθp1
此时,我们得到了复数乘法的几何意义,即:一个复数与
e
j
θ
e^{j \theta}
ejθ 相乘,这个复数的相位发生了
θ
\theta
θ的逆时针偏转。
(注:值得注意的是,规定旋转的正方向很重要,这里我们规定逆时针为正方向,否则会造成模糊)
Observation 2
为了方便3D的公式, 我们需要将向量
p
2
\mathbf{p}_2
p2写成向量
p
1
\mathbf{p}_1
p1的形式,观察上图中的公式
[
x
′
y
′
]
=
cos
(
θ
)
[
x
y
]
+
sin
(
θ
)
[
−
y
x
]
=
cos
(
θ
)
p
+
sin
(
θ
)
p
⊥
\begin{align} \left[ \begin{matrix} x' \\ y' \end{matrix} \right] = \cos(\theta) \left[ \begin{matrix} x \\ y \end{matrix} \right] + \sin(\theta) \left[ \begin{matrix} -y \\ x \end{matrix} \right] = \cos(\theta) \mathbf{p} + \sin(\theta) \mathbf{p}_{\perp} \end{align}
[x′y′]=cos(θ)[xy]+sin(θ)[−yx]=cos(θ)p+sin(θ)p⊥
其中
p
⊥
=
[
−
y
,
x
]
T
\mathbf{p}_{\perp} = [-y,x]^T
p⊥=[−y,x]T 与向量
p
\mathbf{p}
p垂直,并且
∥
p
⊥
∥
2
=
∥
p
∥
\| \mathbf{p}_{\perp} \|_2 = \| \mathbf{p}\|
∥p⊥∥2=∥p∥。由此可见,旋转后的向量可以由旋转前的向量与其垂直的向量线性表示出来。
3D 向量旋转
Rodrigues formula
当我们考虑3维空间如下图所示, 选定旋转轴( rotation axis),其方向向量记为 n ^ \mathbf{\hat n} n^, 并且其模值为1。
Special case
为了方便解释, 我们可以先考虑一个简单的场景: 向量
v
→
\mathbf{ \overrightarrow{v}}
v垂直于旋转轴, 记逆时针旋转
θ
\theta
θ之后的向量为
v
→
′
\mathbf{ \overrightarrow{v}}'
v′。
如何得到
v
→
′
\mathbf{ \overrightarrow{v}}'
v′的表达式呢?
为了回答这个问题,我们首先注意到 向量
v
→
′
\mathbf{ \overrightarrow{v}}'
v′ 跟向量
v
→
\mathbf{ \overrightarrow{v}}
v位于同一平面,我们可以用之前得到2D下的公式 来刻画旋转后的向量
v
→
′
\mathbf{ \overrightarrow{v}}'
v′, 但是怎么得到跟向量
v
→
\mathbf{ \overrightarrow{v}}
v 正交的向量呢?
注意到旋转轴
n
^
\mathbf{\hat n}
n^垂直于
v
→
\mathbf{ \overrightarrow{v}}
v, 根据右手法则,向量
n
^
\mathbf{\hat n}
n^叉乘
v
→
\mathbf{ \overrightarrow{v}}
v得到
(
n
^
×
v
→
)
⊥
v
→
,
and
∥
(
n
^
×
v
→
)
∥
=
∥
n
^
∥
v
→
∥
sin
(
π
/
2
)
=
∥
v
→
∥
(\mathbf{\hat n} \times \mathbf{ \overrightarrow{v}} ) \perp \mathbf{ \overrightarrow{v}} , {\text {and } } \| (\mathbf{\hat n} \times \mathbf{ \overrightarrow{v}} ) \| = \| \mathbf{\hat n}\| \mathbf{ \overrightarrow{v}}\| \sin(\pi/2) = \| \mathbf{ \overrightarrow{v}}\|
(n^×v)⊥v,and ∥(n^×v)∥=∥n^∥v∥sin(π/2)=∥v∥
因此,向量
v
→
′
\mathbf{ \overrightarrow{v}}'
v′可以表示为
v
→
′
=
cos
(
θ
)
v
→
+
sin
(
θ
)
(
n
^
×
v
→
)
\mathbf{ \overrightarrow{v}}' = \cos(\theta) \mathbf{ \overrightarrow{v}} + \sin(\theta) (\mathbf{\hat n} \times \mathbf{ \overrightarrow{v}} )
v′=cos(θ)v+sin(θ)(n^×v)
由此可见,3D空间中,旋转后的向量 依然可以表示为原向量于其垂直向量的线性组合,且其系数分别为
cos
(
θ
)
\cos(\theta)
cos(θ)和
sin
(
θ
)
\sin(\theta)
sin(θ)。
任意向量的旋转
在上个小节,我们讨论了向量
v
→
\mathbf{ \overrightarrow{v}}
v 垂直于旋转轴
n
^
\mathbf{\hat n}
n^的特殊情况, 若向量
v
→
\mathbf{ \overrightarrow{v}}
v于旋转轴不垂直呢?如下图所示,向量
v
→
\mathbf{ \overrightarrow{v}}
v可以做分解为
v
→
=
v
→
∥
+
v
→
⊥
\mathbf{ \overrightarrow{v}} = \mathbf{ \overrightarrow{v}} _{\parallel} + \mathbf{ \overrightarrow{v}} _{\perp}
v=v∥+v⊥
同理,旋转后的向量也可以由如下式子合成
v
→
′
=
v
→
′
∥
+
v
→
′
⊥
\mathbf{ \overrightarrow{v}'} = \mathbf{ \overrightarrow{v}'} _{\parallel} + \mathbf{ \overrightarrow{v}'} _{\perp}
v′=v′∥+v′⊥
即,我们只需要找到对应的
v
→
′
∥
↦
v
→
∥
and
v
→
′
⊥
↦
v
→
⊥
\mathbf{ \overrightarrow{v}'} _{\parallel} \mapsto \mathbf{ \overrightarrow{v}} _{\parallel} \text{ and } \mathbf{ \overrightarrow{v}'} _{\perp} \mapsto \mathbf{ \overrightarrow{v}} _{\perp}
v′∥↦v∥ and v′⊥↦v⊥
的关系式,再拼起来就可以了。
乍一看好像多了步骤,但其实仔细看看就知道,
v
→
∥
\mathbf{ \overrightarrow{v}} _{\parallel}
v∥绕旋转轴不改变其方向和大小,而
v
→
⊥
\mathbf{ \overrightarrow{v}} _{\perp}
v⊥的公式我们已经从之前的special case中得到了。 也就是说
v
→
′
=
v
→
′
∥
+
v
→
′
⊥
=
v
→
∥
+
cos
(
θ
)
v
→
⊥
+
sin
(
θ
)
(
n
^
×
v
→
⊥
)
=
(
a
)
v
→
∥
+
cos
(
θ
)
(
v
→
−
v
→
∥
)
+
sin
(
θ
)
(
n
^
×
v
→
)
=
cos
(
θ
)
v
→
+
(
1
−
cos
(
θ
)
)
v
→
∥
+
sin
(
θ
)
(
n
^
×
v
→
)
=
(
b
)
cos
(
θ
)
v
→
+
(
1
−
cos
(
θ
)
)
(
n
^
⋅
v
→
)
n
^
+
sin
(
θ
)
(
n
^
×
v
→
)
\begin{align} \mathbf{ \overrightarrow{v}'} =& \mathbf{ \overrightarrow{v}'} _{\parallel} + \mathbf{ \overrightarrow{v}'} _{\perp} \\ =&\mathbf{ \overrightarrow{v}} _{\parallel} + \cos(\theta) \mathbf{ \overrightarrow{v}} _{\perp} + \sin(\theta) ( \mathbf{\hat n} \times \mathbf{ \overrightarrow{v}} _{\perp} ) \\ \stackrel{(a)}=& \mathbf{ \overrightarrow{v}} _{\parallel} + \cos(\theta) ( \mathbf{ \overrightarrow{v}} - \mathbf{ \overrightarrow{v}} _{\parallel} ) + \sin(\theta) ( \mathbf{\hat n} \times \mathbf{ \overrightarrow{v}} ) \\ =& \cos(\theta) \mathbf{ \overrightarrow{v}} + (1-\cos(\theta)) \mathbf{ \overrightarrow{v}} _{\parallel} + \sin(\theta) ( \mathbf{\hat n} \times \mathbf{ \overrightarrow{v}} ) \\ \stackrel{(b)}=& \cos(\theta) \mathbf{ \overrightarrow{v}} + (1-\cos(\theta)) \big( \mathbf{\hat n} \cdot \mathbf{ \overrightarrow{v}} \big) \mathbf{\hat n} + \sin(\theta) ( \mathbf{\hat n} \times \mathbf{ \overrightarrow{v}} ) \end{align}
v′===(a)==(b)v′∥+v′⊥v∥+cos(θ)v⊥+sin(θ)(n^×v⊥)v∥+cos(θ)(v−v∥)+sin(θ)(n^×v)cos(θ)v+(1−cos(θ))v∥+sin(θ)(n^×v)cos(θ)v+(1−cos(θ))(n^⋅v)n^+sin(θ)(n^×v)
等号(a)中利用了向量分解
v
→
⊥
=
v
→
−
v
→
∥
\mathbf{ \overrightarrow{v}} _{\perp} = \mathbf{ \overrightarrow{v}} - \mathbf{ \overrightarrow{v}} _{\parallel}
v⊥=v−v∥
而等号(b)中利用向量
v
→
∥
=
(
n
^
⋅
v
→
)
n
^
\mathbf{ \overrightarrow{v}} _{\parallel} = \big( \mathbf{\hat n} \cdot \mathbf{ \overrightarrow{v}} \big) \mathbf{\hat n}
v∥=(n^⋅v)n^
(这里很简单,因为
v
→
∥
\mathbf{ \overrightarrow{v}} _{\parallel}
v∥方向与
n
^
\mathbf{\hat n}
n^相同,而其大小可以由两个向量的点积(即 投影)得到。由此,我们得到了Rodrigues 公式
v
→
′
=
cos
(
θ
)
v
→
+
(
1
−
cos
(
θ
)
)
(
n
^
⋅
v
→
)
n
^
+
sin
(
θ
)
(
n
^
×
v
→
)
\mathbf{ \overrightarrow{v}'} = \cos(\theta) \mathbf{ \overrightarrow{v}} + (1-\cos(\theta)) \big( \mathbf{\hat n} \cdot \mathbf{ \overrightarrow{v}} \big) \mathbf{\hat n} + \sin(\theta) ( \mathbf{\hat n} \times \mathbf{ \overrightarrow{v}} )
v′=cos(θ)v+(1−cos(θ))(n^⋅v)n^+sin(θ)(n^×v)
记忆公式的时候,只要回想一遍推导过程就好了。
Reference:
[1] https://www.youtube.com/watch?v=q-ESzg03mQc&t=6s
[2]https://krasjet.github.io/quaternion/quaternion.pdf