CH3-5 四元数表示旋转
三维空间中任意点均可用一个纯虚四元数表示即 p = [ 0 , v ] T \boldsymbol{p}=[0,\boldsymbol{v}]^T p=[0,v]T,经一个单位四元数 q \boldsymbol{q} q的旋转后,得到 p ′ \boldsymbol{p'} p′,则
p ′ = q p q − 1 (3-5-1) \boldsymbol{p'}=\boldsymbol{q}\boldsymbol{p}\boldsymbol{q^{-1}} \tag{3-5-1} p′=qpq−1(3-5-1)
最终 p ′ \boldsymbol{p'} p′的虚部即为旋转后点的坐标。
首先证明几个定理。注意这里向量和矩阵的转换。
(1)首先证明 G r a β m a n n \mathrm{Gra \beta mann} Graβmann积定理,也就是四元数乘法规则。
两个四元数
q
1
=
a
+
b
i
⃗
+
c
j
⃗
+
d
k
⃗
q_1=a+b\vec{i}+c\vec{j}+d\vec{k}
q1=a+bi+cj+dk 、
q
2
=
e
+
f
i
⃗
+
g
j
⃗
+
h
k
⃗
q_2=e+f\vec{i}+g\vec{j}+h\vec{k}
q2=e+fi+gj+hk,则
q 1 q 2 = ( a + b i ⃗ + c j ⃗ + d k ⃗ ) ( e + f i ⃗ + g j ⃗ + h k ⃗ ) = a e + a f i ⃗ + a g j ⃗ + a h k ⃗ + b e i ⃗ + b f i ⃗ 2 + b g i ⃗ j ⃗ + b h i ⃗ k ⃗ + + c e j ⃗ + c f j ⃗ i ⃗ + c g j ⃗ 2 + c h j ⃗ k ⃗ + d e k ⃗ + d f k ⃗ i ⃗ + d g k ⃗ j ⃗ + d h k ⃗ 2 = a e + a f i ⃗ + a g j ⃗ + a h k ⃗ + b e i ⃗ − b f + b g k ⃗ − b h j ⃗ + c e j ⃗ − c f k ⃗ − c g + c h i ⃗ + d e k ⃗ + d f j ⃗ − d g i ⃗ − d h = ( a e − b f − c g − d h ) + ( a f − d g + b e + c h ) i ⃗ + ( − b h + c e + d f + a g ) j ⃗ + ( a h + b g − c f + d e ) k ⃗ (3-5-2) \begin{aligned} q_1q_2&=(a+b\vec{i}+c\vec{j}+d\vec{k})(e+f\vec{i}+g\vec{j}+h\vec{k}) \\ &=ae+af\vec{i}+ag\vec{j}+ah\vec{k}+be\vec{i}+bf\vec{i}^2+bg\vec{i}\vec{j}+bh\vec{i}\vec{k}+ \\ &+ce\vec{j}+cf\vec{j}\vec{i}+cg\vec{j}^2+ch\vec{j}\vec{k}+de\vec{k}+df\vec{k}\vec{i}+dg\vec{k}\vec{j}+dh\vec{k}^2 \\ &=ae+af\vec{i}+ag\vec{j}+ah\vec{k}+be\vec{i}-bf+bg\vec{k}-bh\vec{j}+ce\vec{j}-cf\vec{k}-cg+ch\vec{i}+de\vec{k}+df\vec{j}-dg\vec{i}-dh \\ &=(ae-bf-cg-dh)+(af-dg+be+ch)\vec{i}+(-bh+ce+df+ag)\vec{j}+(ah+bg-cf+de)\vec{k} \end{aligned} \tag{3-5-2} q1q2=(a+bi+cj+dk)(e+fi+gj+hk)=ae+afi+agj+ahk+bei+bfi2+bgij+bhik++cej+cfji+cgj2+chjk+dek+dfki+dgkj+dhk2=ae+afi+agj+ahk+bei−bf+bgk−bhj+cej−cfk−cg+chi+dek+dfj−dgi−dh=(ae−bf−cg−dh)+(af−dg+be+ch)i+(−bh+ce+df+ag)j+(ah+bg−cf+de)k(3-5-2)
写成矩阵形式,即
q 1 q 2 = [ a − b − c − d b a − d c c d a − b d − c b a ] [ e f g h ] (3-5-3) q_1q_2=\left[\begin{array}{c} a & -b & -c & -d \\ b & a & -d & c \\ c & d & a & -b \\ d & -c & b & a \end{array}\right]\left[\begin{array}{c} e \\ f\\ g \\ h \end{array}\right] \tag{3-5-3} q1q2= abcd−bad−c−c−dab−dc−ba efgh (3-5-3)
令 v ⃗ = ( b , c , d ) \vec{v}=(b,c,d) v=(b,c,d)、 u ⃗ = ( f , g , h ) \vec{u}=(f,g,h) u=(f,g,h),则有
v ⃗ ⋅ u ⃗ = b f + c g + d h (3-5-4) \vec{v}\cdot\vec{u}=bf+cg+dh \tag{3-5-4} v⋅u=bf+cg+dh(3-5-4)
v ⃗ × u ⃗ = ∣ i ⃗ j ⃗ k ⃗ b c d f g h ∣ = ( c h − d g ) i ⃗ + ( d f − b h ) j ⃗ + ( b g − c f ) k ⃗ (3-5-5) \begin{aligned} \vec{v}\times\vec{u}&=\left|\begin{array}{c} \vec{i} & \vec{j} & \vec{k} \\ b & c & d \\ f & g & h \end{array}\right| \\ &=(ch-dg)\vec{i}+(df-bh)\vec{j}+(bg-cf)\vec{k} \end{aligned} \tag{3-5-5} v×u= ibfjcgkdh =(ch−dg)i+(df−bh)j+(bg−cf)k(3-5-5)
综合式(3-5-2)、式(3-5-4)、式(3-5-5),得
q 1 q 2 = [ a e − v ⃗ ⋅ u ⃗ , a u ⃗ + e v ⃗ + v ⃗ × u ⃗ ] (3-5-6) q_1q_2=[ae-\vec{v}\cdot\vec{u},a\vec{u}+e\vec{v}+\vec{v}\times\vec{u}] \tag{3-5-6} q1q2=[ae−v⋅u,au+ev+v×u](3-5-6)
综上: G r a β m a n n \mathrm{Gra \beta mann} Graβmann积定理
对任意四元数 q 1 = [ s , v ⃗ ] q_1=[s,\vec{v}] q1=[s,v], q 2 = [ t , u ⃗ ] q_2=[t,\vec{u}] q2=[t,u],有
q 1 q 2 = [ s t − v ⃗ ⋅ u ⃗ , s u ⃗ + t v ⃗ + v ⃗ × u ⃗ ] (3-5-7) q_1q_2=[st-\vec{v}\cdot\vec{u},s\vec{u}+t\vec{v}+\vec{v}\times\vec{u}] \tag{3-5-7} q1q2=[st−v⋅u,su+tv+v×u](3-5-7)
对于纯四元数 q 1 = [ 0 , v ⃗ ] q_1=[0,\vec{v}] q1=[0,v], q 2 = [ 0 , u ⃗ ] q_2=[0,\vec{u}] q2=[0,u],有
q 1 q 2 = [ − v ⃗ ⋅ u ⃗ , v ⃗ × u ⃗ ] (3-5-8) q_1q_2=[-\vec{v}\cdot\vec{u},\vec{v}\times\vec{u}] \tag{3-5-8} q1q2=[−v⋅u,v×u](3-5-8)
(2)证明:
q
−
1
=
q
∗
∥
q
∥
2
q^{-1}=\frac{q^*}{\|q\|^2}
q−1=∥q∥2q∗(
q
∗
q^*
q∗为
q
q
q 的共轭).
q q q 为单位四元数,则
q q − 1 = 1 (3-5-9) qq^{-1}=1 \tag{3-5-9} qq−1=1(3-5-9)
将上式左乘或右乘 q ∗ q* q∗,有
q ∗ q q − 1 = q ∗ , q q − 1 q ∗ = q ∗ (3-5-10) q^{*}qq^{-1}=q^*, \quad qq^{-1}q^*=q^* \tag{3-5-10} q∗qq−1=q∗,qq−1q∗=q∗(3-5-10)
不妨设 q = [ s , v ⃗ ] q=[s,\vec{v}] q=[s,v],其中 v ⃗ = [ q 1 , q 2 , q 3 ] \vec{v}=[q_1,q_2,q_3] v=[q1,q2,q3],则根据四元数乘法
q ∗ q = [ s , − v ⃗ ] [ s , v ⃗ ] = [ s 2 − v T v , 0 ] = ( s 2 − v T v ) + 0 i + 0 j + 0 k = s 2 + q 1 2 + q 2 2 + q 3 2 = ∥ q ∥ 2 (3-5-11) \begin{aligned} q^*q&=[s,-\vec{v}][s,\vec{v}] \\ &=[s^2-\boldsymbol{v}^{\mathrm{T}}\boldsymbol{v},0] \\ &=(s^2-\boldsymbol{v}^{\mathrm{T}}\boldsymbol{v})+0\boldsymbol{i}+0\boldsymbol{j}+0\boldsymbol{k} \\ &=s^2+q_1^2+q_2^2+q_3^2 \\ &=\|q\|^2 \end{aligned} \tag{3-5-11} q∗q=[s,−v][s,v]=[s2−vTv,0]=(s2−vTv)+0i+0j+0k=s2+q12+q22+q32=∥q∥2(3-5-11)
则可得
q − 1 = q ∗ ∥ q ∥ 2 (3-5-12) q^{-1}=\frac{q^*}{\|q\|^2} \tag{3-5-12} q−1=∥q∥2q∗(3-5-12)
证毕。
(3)下面讨论四元数和三维旋转矩阵之间的关系
图中向量 v ⃗ \vec{v} v 绕 单位旋转向量 u ⃗ \vec{u} u 旋转 θ \theta θ 度,我们分别来看 v ⃗ ∥ \vec{v}_{\parallel} v∥ 和 v ⃗ ⊥ \vec{v}_{\perp} v⊥ 的旋转。
1)首先看 v ⃗ \vec{v} v 的旋转。图一中,将向量分解
v ⃗ = v ⃗ ∥ + v ⃗ ⊥ \vec{v}=\vec{v}_{\parallel}+\vec{v}_{\perp} v=v∥+v⊥
v ′ ⃗ = v ′ ⃗ ∥ + v ′ ⃗ ⊥ (3-5-13) \vec{v'}=\vec{v'}_{\parallel}+\vec{v'}_{\perp} \tag{3-5-13} v′=v′∥+v′⊥(3-5-13)
图二中,
v ′ ⃗ ⊥ = v ⃗ v ′ + v ⃗ w ′ (3-5-14) \vec{v'}_{\perp} =\vec{v}_{v'}+\vec{v}_{w'} \tag{3-5-14} v′⊥=vv′+vw′(3-5-14)
v ⃗ w \vec{v}_w vw 是辅助向量,且 $\vec{v}w=\vec{u} \times \vec{v}{\perp} $。
由图二,可得
∣ v ⃗ v ′ ∣ = ∣ v ′ ⃗ ⊥ ∣ cos θ = ∣ v ⃗ ⊥ ∣ cos θ |\vec{v}_{v'}|=|\vec{v'}_{\perp}|\cos\theta=|\vec{v}_{\perp}|\cos\theta ∣vv′∣=∣v′⊥∣cosθ=∣v⊥∣cosθ
∣ v ⃗ w ′ ∣ = ∣ v ′ ⃗ ⊥ ∣ sin θ = ∣ v ⃗ w ∣ sin θ (3-5-15) |\vec{v}_{w'}|=|\vec{v'}_{\perp}|\sin\theta=|\vec{v}_{w}|\sin\theta \tag{3-5-15} ∣vw′∣=∣v′⊥∣sinθ=∣vw∣sinθ(3-5-15)
推导,得
v ⃗ v ′ = v ⃗ ⊥ cos θ \vec{v}_{v'}=\vec{v}_{\perp}\cos\theta vv′=v⊥cosθ
v ⃗ w ′ = v ⃗ w sin θ (3-5-16) \vec{v}_{w'}=\vec{v}_{w}\sin\theta \tag{3-5-16} vw′=vwsinθ(3-5-16)
又因为 v ⃗ w = u ⃗ × v ⃗ ⊥ \vec{v}_w=\vec{u}\times \vec{v}_{\perp} vw=u×v⊥,有
v ′ ⃗ ⊥ = v ⃗ v ′ + v ⃗ w ′ = v ⃗ ⊥ cos θ + v ⃗ w sin θ = v ⃗ ⊥ cos θ + sin θ ( u ⃗ × v ⃗ ⊥ ) (3-5-17) \begin{aligned} \vec{v'}_{\perp} &=\vec{v}_{v'}+\vec{v}_{w'} \\ &=\vec{v}_{\perp}\cos\theta+\vec{v}_{w}\sin\theta \\ &=\vec{v}_{\perp}\cos\theta+\sin\theta(\vec{u}\times \vec{v}_{\perp}) \end{aligned} \tag{3-5-17} v′⊥=vv′+vw′=v⊥cosθ+vwsinθ=v⊥cosθ+sinθ(u×v⊥)(3-5-17)
令 v ⊥ = [ 0 , v ⃗ ⊥ ] v_{\perp}=[0, \vec{v}_{\perp}] v⊥=[0,v⊥], u = [ 0 , u ⃗ ] u=[0, \vec{u}] u=[0,u],根据纯四元数乘法法则,有
u v ⊥ = [ − u ⃗ ⋅ v ⃗ ⊥ , u ⃗ × v ⃗ ⊥ ] (3-5-18) uv_{\perp}=[-\vec{u}\cdot\vec{v}_{\perp}, \vec{u}\times \vec{v}_{\perp}] \tag{3-5-18} uv⊥=[−u⋅v⊥,u×v⊥](3-5-18)
因为 u ⃗ \vec{u} u 与 v ⃗ ⊥ \vec{v}_{\perp} v⊥ 垂直,则
u v ⊥ = [ 0 , u ⃗ × v ⃗ ⊥ ] = u ⃗ × v ⃗ ⊥ (3-5-19) uv_{\perp}=[0, \vec{u}\times \vec{v}_{\perp}]=\vec{u}\times \vec{v}_{\perp} \tag{3-5-19} uv⊥=[0,u×v⊥]=u×v⊥(3-5-19)
则式(3-5-17)可写为四元数形式
v ⊥ ′ = v ⊥ cos θ + sin θ ( u v ⊥ ) = ( cos θ + sin θ u ) v ⊥ (3-5-20) \begin{aligned} v'_{\perp}&=v_{\perp}\cos\theta+\sin\theta(uv_{\perp}) \\ &=(\cos\theta+\sin\theta u)v_{\perp} \end{aligned} \tag{3-5-20} v⊥′=v⊥cosθ+sinθ(uv⊥)=(cosθ+sinθu)v⊥(3-5-20)
令 q = cos θ + sin θ u q=\cos\theta+\sin\theta u q=cosθ+sinθu,将其视作本次旋转四元数,得到
v ⊥ ′ = q v ⊥ (3-5-21) v'_{\perp}=qv_{\perp} \tag{3-5-21} v⊥′=qv⊥(3-5-21)
2) v ⃗ \vec{v} v 的平行分量并不会随旋转改变。下面直接推导 v ⃗ \vec{v} v 的旋转。
v ′ ⃗ = v ⃗ ∥ + v ⊥ ′ = v ⃗ ∥ + q v ⊥ (3-5-22) \vec{v'}=\vec{v}_{\parallel}+v'_{\perp}=\vec{v}_{\parallel}+qv_{\perp} \tag{3-5-22} v′=v∥+v⊥′=v∥+qv⊥(3-5-22)
在此之前,先证明几个引理:
① 假设旋转四元数 q = [ cos θ , sin θ u ⃗ ] q=[\cos\theta, \sin\theta\vec{u}] q=[cosθ,sinθu],其中 u ⃗ \vec{u} u 为单位旋转向量。推导可得
q 2 = q q = [ cos θ , sin θ u ⃗ ] [ cos θ , sin θ u ⃗ ] = [ cos 2 θ − sin θ u ⃗ ⋅ sin θ u ⃗ , cos θ sin θ u ⃗ + cos θ sin θ u ⃗ + sin u ⃗ × sin θ u ⃗ ] = [ cos 2 θ − sin 2 θ u ⃗ 2 , 2 cos θ sin θ u ⃗ + 0 ] = [ cos 2 θ − sin 2 θ , 2 cos θ sin θ u ⃗ ] = [ cos ( 2 θ ) , sin ( 2 θ ) u ⃗ ] (3-5-23) \begin{aligned} q^2=qq&=[\cos\theta, \sin\theta\vec{u}][\cos\theta, \sin\theta\vec{u}] \\ &=[\cos^2\theta-\sin\theta\vec{u}\cdot\sin\theta\vec{u}, \cos\theta\sin\theta\vec{u}+\cos\theta\sin\theta\vec{u}+\sin\vec{u} \times \sin\theta\vec{u}] \\ &=[\cos^2\theta-\sin^2\theta\vec{u}^2,2\cos\theta\sin\theta\vec{u}+0] \\ &=[\cos^2\theta-\sin^2\theta,2\cos\theta\sin\theta\vec{u}] \\ &=[\cos(2\theta),\sin(2\theta)\vec{u}] \end{aligned} \tag{3-5-23} q2=qq=[cosθ,sinθu][cosθ,sinθu]=[cos2θ−sinθu⋅sinθu,cosθsinθu+cosθsinθu+sinu×sinθu]=[cos2θ−sin2θu2,2cosθsinθu+0]=[cos2θ−sin2θ,2cosθsinθu]=[cos(2θ),sin(2θ)u](3-5-23)
公式表明,绕 u ⃗ \vec{u} u 连续旋转 θ \theta θ角两次,相当于直接旋转 2 θ 2\theta 2θ 度。
② 接下来将式(3-5-22)变形。根据上式,令 q = p 2 q=p^2 q=p2 ,则 p = [ cos ( θ 2 ) , sin ( θ 2 ) u ⃗ ] p=[\cos(\frac{\theta}{2}),\sin(\frac{\theta}{2})\vec{u}] p=[cos(2θ),sin(2θ)u],则
v ′ ⃗ = v ⃗ ∥ + v ⊥ ′ = v ⃗ ∥ + q v ⊥ = ( p p − 1 ) v ⃗ ∥ + p p v ⃗ ⊥ (3-5-24) \begin{aligned} \vec{v'}&=\vec{v}_{\parallel}+v'_{\perp} \\ &=\vec{v}_{\parallel}+qv_{\perp} \\ &=(pp^{-1})\vec{v}_{\parallel}+pp\vec{v}_{\perp} \end{aligned} \tag{3-5-24} v′=v∥+v⊥′=v∥+qv⊥=(pp−1)v∥+ppv⊥(3-5-24)
因为 p p p是单位四元数,可得
q − 1 = q ∗ ∥ q ∥ 2 = q ∗ (3-5-25) q^{-1}=\frac{q^*}{\|q\|^2}=q^* \tag{3-5-25} q−1=∥q∥2q∗=q∗(3-5-25)
代入上式
v ′ ⃗ = ( p p − 1 ) v ⃗ ∥ + p p v ⃗ ⊥ = ( p p ∗ ) v ⃗ ∥ + p p v ⃗ ⊥ (3-5-26) \begin{aligned} \vec{v'}&=(pp^{-1})\vec{v}_{\parallel}+pp\vec{v}_{\perp} \\ &=(pp^{*})\vec{v}_{\parallel}+pp\vec{v}_{\perp} \end{aligned} \tag{3-5-26} v′=(pp−1)v∥+ppv⊥=(pp∗)v∥+ppv⊥(3-5-26)
③ 证明一个引理:若 v ∥ = [ 0 , v ⃗ ∥ ] v_{\parallel}=[0,\vec{v}_{\parallel}] v∥=[0,v∥], q = [ α , β u ⃗ ] q=[\alpha, \beta \vec{u}] q=[α,βu], u ⃗ \vec{u} u为单位旋转向量,且 v ⃗ ∥ ∥ u ⃗ \vec{v}_{\parallel} \parallel \vec{u} v∥∥u,则有
q v ∥ = v ∥ q (3-5-27) qv_{\parallel}=v_{\parallel}q \tag{3-5-27} qv∥=v∥q(3-5-27)
下面进行证明:
左边 = q v ∥ = [ α , β u ⃗ ] ⋅ [ 0 , v ⃗ ∥ ] = [ − β u ⃗ ⋅ v ⃗ ∥ , α v ⃗ ∥ + 0 + β u ⃗ × v ⃗ ∥ ] = [ − β u ⃗ ⋅ v ⃗ ∥ , α v ⃗ ∥ ] \begin{aligned} 左边=qv_{\parallel}&=[\alpha, \beta \vec{u}]\cdot [0,\vec{v}_{\parallel}] \\ &=[-\beta\vec{u} \cdot \vec{v}_{\parallel}, \alpha \vec{v}_{\parallel}+0+\beta\vec{u} \times \vec{v}_{\parallel}] \\ &=[-\beta\vec{u} \cdot \vec{v}_{\parallel},\alpha \vec{v}_{\parallel}] \end{aligned} 左边=qv∥=[α,βu]⋅[0,v∥]=[−βu⋅v∥,αv∥+0+βu×v∥]=[−βu⋅v∥,αv∥]
右边 = v ∥ q = [ 0 , v ⃗ ∥ ] ⋅ [ α , β u ⃗ ] = [ − β v ⃗ ∥ ⋅ u ⃗ , α v ⃗ ∥ + β v ⃗ ∥ × u ⃗ ] = [ − β v ⃗ ∥ ⋅ u ⃗ , α v ⃗ ∥ ] = 左边 \begin{aligned} 右边=v_{\parallel}q&=[0,\vec{v}_{\parallel}] \cdot [\alpha, \beta \vec{u}] \\ &=[-\beta \vec{v}_{\parallel} \cdot \vec{u},\alpha \vec{v}_{\parallel}+\beta\vec{v}_{\parallel}\times\vec{u}] \\ &=[-\beta \vec{v}_{\parallel} \cdot \vec{u},\alpha \vec{v}_{\parallel}] \\ &=左边 \end{aligned} 右边=v∥q=[0,v∥]⋅[α,βu]=[−βv∥⋅u,αv∥+βv∥×u]=[−βv∥⋅u,αv∥]=左边
证毕。
④ 若 v ⊥ = [ 0 , v ⃗ ⊥ ] v_{\perp}=[0,\vec{v}_{\perp}] v⊥=[0,v⊥], q = [ α , β u ⃗ ] q=[\alpha, \beta \vec{u}] q=[α,βu], u ⃗ \vec{u} u 为单位旋转向量,且 v ⃗ ⊥ ⊥ u ⃗ \vec{v}_{\perp} \perp \vec{u} v⊥⊥u,则有
q v ⊥ = v ⊥ q ∗ (3-5-28) qv_{\perp}=v_{\perp}q^* \tag{3-5-28} qv⊥=v⊥q∗(3-5-28)
证明:
左边
=
q
v
⊥
=
[
α
,
β
u
⃗
]
⋅
[
0
,
v
⃗
⊥
]
=
[
−
β
u
⃗
⋅
v
⃗
⊥
,
α
v
⃗
⊥
+
0
+
β
u
⃗
×
v
⃗
⊥
]
=
[
−
β
u
⃗
⋅
v
⃗
⊥
,
α
v
⃗
⊥
+
β
u
⃗
×
v
⃗
⊥
]
\begin{aligned} 左边=qv_{\perp}&=[\alpha, \beta \vec{u}]\cdot [0,\vec{v}_{\perp}] \\ &=[-\beta\vec{u} \cdot \vec{v}_{\perp}, \alpha \vec{v}_{\perp}+0+\beta\vec{u} \times \vec{v}_{\perp}] \\ &=[-\beta\vec{u} \cdot \vec{v}_{\perp}, \alpha \vec{v}_{\perp}+\beta\vec{u} \times \vec{v}_{\perp}] \end{aligned}
左边=qv⊥=[α,βu]⋅[0,v⊥]=[−βu⋅v⊥,αv⊥+0+βu×v⊥]=[−βu⋅v⊥,αv⊥+βu×v⊥]
右边
=
v
⊥
q
∗
=
[
0
,
v
⃗
⊥
]
⋅
[
α
,
−
β
u
⃗
]
=
[
−
β
v
⃗
⊥
⋅
u
⃗
,
α
v
⃗
⊥
−
β
v
⃗
⊥
×
u
⃗
]
=
[
−
β
v
⃗
⊥
⋅
u
⃗
,
α
v
⃗
⊥
+
β
u
⃗
×
v
⃗
⊥
]
=
左边
\begin{aligned} 右边=v_{\perp}q^* &=[0,\vec{v}_{\perp}] \cdot [\alpha, -\beta \vec{u}] \\ &=[-\beta \vec{v}_{\perp} \cdot \vec{u},\alpha \vec{v}_{\perp}-\beta\vec{v}_{\perp}\times\vec{u}] \\ &=[-\beta \vec{v}_{\perp} \cdot \vec{u},\alpha \vec{v}_{\perp}+\beta\vec{u} \times \vec{v}_{\perp}] &=左边 \end{aligned}
右边=v⊥q∗=[0,v⊥]⋅[α,−βu]=[−βv⊥⋅u,αv⊥−βv⊥×u]=[−βv⊥⋅u,αv⊥+βu×v⊥]=左边
证毕。
3)结合上面两个引理和式(3-5-25),对式(3-5-26)推导(写成四元数形式)
v ′ = ( p p ∗ ) v ∥ + p p v ⊥ = p ( p ∗ v ∥ ) + p ( p v ⊥ ) = p v ∥ p ∗ + p v ⊥ p ∗ = p ( v ∥ + v ⊥ ) p ∗ = p v p ∗ = p v p − 1 (3-5-26) \begin{aligned} v'&=(pp^{*})v_{\parallel}+ppv_{\perp} \\ &=p(p^{*}v_{\parallel})+p(pv_{\perp}) \\ &=pv_{\parallel}p^{*}+pv_{\perp}p^* \\ &=p(v_{\parallel}+v_{\perp})p^* \\ &=pvp^* \\ &=pvp^{-1} \end{aligned} \tag{3-5-26} v′=(pp∗)v∥+ppv⊥=p(p∗v∥)+p(pv⊥)=pv∥p∗+pv⊥p∗=p(v∥+v⊥)p∗=pvp∗=pvp−1(3-5-26)
CH3-6 四元数、旋转向量、旋转矩阵、欧拉角之间的转换
1、四元数和旋转向量的互相转换
由式(3-5-26),
v ′ = p p ∗ v ∥ + p p v ⊥ (3-6-1) v'= pp^{*}v_{\parallel}+ppv_{\perp} \tag{3-6-1} v′=pp∗v∥+ppv⊥(3-6-1)
可以看出, v ∥ v_{\parallel} v∥ 经过` p p p 和 p ∗ p^* p∗ 两次旋转,抵消了;而 v ⊥ v_{\perp} v⊥ 经过两次旋转 θ 2 \frac{\theta}{2} 2θ,变成了 v ⊥ ′ v'_{\perp} v⊥′,这也说明了为什么 p = [ cos θ 2 , sin θ 2 u ⃗ ] p=[\cos\frac{\theta}{2}, \sin\frac{\theta}{2}\vec{u}] p=[cos2θ,sin2θu]。
假设已知单位旋转四元数` p = [ a , b ⃗ ] p=[a, \vec{b}] p=[a,b],根据上面的对应关系,可以提取出旋转角度和旋转向量:
{ θ 2 = arccos a u ⃗ = b ⃗ sin θ 2 = b ⃗ sin ( arccos a ) (3-6-2) \left\{ \begin{matrix} \frac{\theta}{2}=\arccos a\\ \vec{u} = \frac{\vec{b}}{\sin\frac{\theta}{2}}=\frac{\vec{b}}{\sin{(\arccos a})} \end{matrix} \right. \tag{3-6-2} {2θ=arccosau=sin2θb=sin(arccosa)b(3-6-2)
反之,知道旋转向量也可求出四元数。
2、旋转矩阵和四元数相互转换
(1)前面我们已经推导过,左乘四元数 q 1 = a + b i ⃗ + c j ⃗ + d k ⃗ q_1=a+b\vec{i}+c\vec{j}+d\vec{k} q1=a+bi+cj+dk,相当于左乘矩阵
L ( q ) = [ a − b − c − d b a − d c c d a − b d − c b a ] (3-6-3) \boldsymbol{L}(q)=\left[\begin{array}{c} a & -b & -c & -d \\ b & a & -d & c \\ c & d & a & -b \\ d & -c & b & a \end{array}\right] \tag{3-6-3} L(q)= abcd−bad−c−c−dab−dc−ba (3-6-3)
类似的,右乘矩阵为
R ( q ) = [ a − b − c − d b a d − c c − d a b d c − b a ] (3-6-4) \boldsymbol{R}(q)=\left[\begin{array}{c} a & -b & -c & -d \\ b & a & d & -c \\ c & -d & a & b \\ d & c & -b & a \end{array}\right] \tag{3-6-4} R(q)= abcd−ba−dc−cda−b−d−cba (3-6-4)
利用这两个式子,将 v ′ = q v q ∗ v'=qvq^* v′=qvq∗ (式3-5-26)写成矩阵乘法形式。已知 p = [ cos θ 2 , sin θ 2 u ⃗ ] p=[\cos\frac{\theta}{2}, \sin\frac{\theta}{2}\vec{u}] p=[cos2θ,sin2θu],令 u ⃗ = [ u x , u y , u z ] \vec{u}=[u_x, u_y, u_z] u=[ux,uy,uz],则
q = cos θ 2 + sin θ 2 u x i ⃗ + sin θ 2 u y j ⃗ + sin θ 2 u z k ⃗ (3-6-5) q=\cos\frac{\theta}{2}+\sin\frac{\theta}{2}u_x\vec{i}+\sin\frac{\theta}{2}u_y\vec{j}+\sin\frac{\theta}{2}u_z\vec{k} \tag{3-6-5} q=cos2θ+sin2θuxi+sin2θuyj+sin2θuzk(3-6-5)
根据对应关系
{ a = cos θ 2 b = sin θ 2 u x c = sin θ 2 u y d = sin θ 2 u z (3-6-6) \left\{ \begin{matrix} a=\cos\frac{\theta}{2}\\ b=\sin\frac{\theta}{2}u_x \\ c=\sin\frac{\theta}{2}u_y \\ d=\sin\frac{\theta}{2}u_z \end{matrix} \right. \tag{3-6-6} ⎩ ⎨ ⎧a=cos2θb=sin2θuxc=sin2θuyd=sin2θuz(3-6-6)
将四元数乘法写为矩阵乘法形式
v ′ = q v q ∗ = L ( q ) R ( q ∗ ) v = [ 1 0 0 0 0 1 − 2 c 2 − 2 d 2 2 b c − 2 a d 2 a c + 2 b d 0 2 b c + 2 a d 1 − 2 b 2 − 2 d 2 2 c d − 2 a b 0 2 b d − 2 a c 2 a b + 2 c d 1 − 2 b 2 − 2 c 2 ] [ 0 v x v y v z ] (3-6-7) \begin{aligned} v'=qvq^*=& \boldsymbol{L}(q)\boldsymbol{R}(q^*)\boldsymbol{v} \\ =& \left[\begin{array}{c} 1 & 0 & 0 & 0 \\ 0 & 1-2c^2-2d^2 & 2bc-2ad & 2ac+2bd \\ 0 & 2bc+2ad & 1-2b^2-2d^2 & 2cd-2ab \\ 0 & 2bd-2ac & 2ab+2cd & 1-2b^2-2c^2 \end{array}\right]\left[\begin{array}{c} 0 \\ v_x\\ v_y\\ v_z \end{array}\right] \end{aligned} \tag{3-6-7} v′=qvq∗==L(q)R(q∗)v 100001−2c2−2d22bc+2ad2bd−2ac02bc−2ad1−2b2−2d22ab+2cd02ac+2bd2cd−2ab1−2b2−2c2 0vxvyvz (3-6-7)
矩阵外围不会对变换产生影响,整理为
v
′
⃗
=
[
1
−
2
c
2
−
2
d
2
2
b
c
−
2
a
d
2
a
c
+
2
b
d
2
b
c
+
2
a
d
1
−
2
b
2
−
2
d
2
2
c
d
−
2
a
b
2
b
d
−
2
a
c
2
a
b
+
2
c
d
1
−
2
b
2
−
2
c
2
]
v
⃗
(3-6-7)
\vec{v'}=\left[\begin{array}{c} 1-2c^2-2d^2 & 2bc-2ad & 2ac+2bd \\ 2bc+2ad & 1-2b^2-2d^2 & 2cd-2ab \\ 2bd-2ac & 2ab+2cd & 1-2b^2-2c^2 \end{array}\right] \vec{v} \tag{3-6-7}
v′=
1−2c2−2d22bc+2ad2bd−2ac2bc−2ad1−2b2−2d22ab+2cd2ac+2bd2cd−2ab1−2b2−2c2
v(3-6-7)
至此,我们由旋转向量得到了单位四元数,再得到了旋转矩阵。
(2)再由旋转矩阵恢复四元数,注意单位四元数( a 2 + b 2 + c 2 + d 2 = 1 a^2+b^2+c^2+d^2=1 a2+b2+c2+d2=1)
q 0 = t r ( R ) + 1 2 = ( 3 − 4 b 2 − 4 c 2 − 4 d 2 ) + 1 2 = 4 − 4 b 2 − 4 c 2 − 4 d 2 2 = 4 ( 1 − b 2 − c 2 − d 2 ) 2 = 4 a 2 2 = a (3-6-8) \begin{aligned} q_0&=\frac{\sqrt{tr(\boldsymbol{R})+1}}{2} \\ &=\frac{\sqrt{(3-4b^2-4c^2-4d^2)+1}}{2}=\frac{\sqrt{4-4b^2-4c^2-4d^2}}{2} \\ &=\frac{\sqrt{4(1-b^2-c^2-d^2)}}{2}=\frac{\sqrt{4a^2}}{2}\\ &=a \end{aligned} \tag{3-6-8} q0=2tr(R)+1=2(3−4b2−4c2−4d2)+1=24−4b2−4c2−4d2=24(1−b2−c2−d2)=24a2=a(3-6-8)
其余三项分别为
q 1 = m 32 − m 23 4 q 0 = 4 a b 4 a = b q_1=\frac{m_{32}-m_{23}}{4q_0}=\frac{4ab}{4a}=b q1=4q0m32−m23=4a4ab=b
q 2 = m 13 − m 31 4 q 0 = 4 a c 4 a = c q_2=\frac{m_{13}-m_{31}}{4q_0}=\frac{4ac}{4a}=c q2=4q0m13−m31=4a4ac=c
q 1 = m 21 − m 12 4 q 0 = 4 a d 4 a = d (3-6-9) q_1=\frac{m_{21}-m_{12}}{4q_0}=\frac{4ad}{4a}=d \tag{3-6-9} q1=4q0m21−m12=4a4ad=d(3-6-9)
证毕。
3、旋转矩阵和相互转换
(1)欧拉角转旋转矩阵
假设绕 XYZ 三个轴的旋转角度分别为 α \alpha α β \beta β γ \gamma γ,则三次旋转的旋转矩阵分别为
R x ( α ) = [ 1 0 0 0 cos α − sin α 0 sin α cos α ] R y ( β ) = [ cos β 0 sin β 0 1 0 − sin β 0 cos β ] R z ( γ ) = [ cos γ − sin γ 0 sin γ cos γ 0 0 1 ] \begin{aligned} & R_x(\alpha)=\left[\begin{array}{ccc} 1 & 0 & 0 \\ 0 & \cos \alpha & -\sin \alpha \\ 0 & \sin \alpha & \cos \alpha \end{array}\right] \\ & R_y(\beta)=\left[\begin{array}{ccc} \cos \beta & 0 & \sin \beta \\ 0 & 1 & 0 \\ -\sin \beta & 0 & \cos \beta \end{array}\right] \\ & R_z(\gamma)=\left[\begin{array}{ccc} \cos \gamma & -\sin \gamma & 0 \\ \sin \gamma & \cos \gamma & \\ 0 & 0 & 1 \end{array}\right] \end{aligned} Rx(α)= 1000cosαsinα0−sinαcosα Ry(β)= cosβ0−sinβ010sinβ0cosβ Rz(γ)= cosγsinγ0−sinγcosγ001
可得旋转矩阵为
R = R z ( γ ) ∗ R y ( β ) ∗ R x ( α ) = [ cos β cos γ sin α sin β cos γ − cos α sin γ cos α sin β cos γ + sin α sin γ cos β sin γ sin α sin β sin γ + cos α cos γ cos α sin β sin γ − sin α cos γ − sin β sin α cos β cos α cos β ] R=R_z(\gamma) * R_y(\beta) * R_x(\alpha) =\left[\begin{array}{ccc} \cos \beta \cos \gamma & \sin \alpha \sin \beta \cos \gamma-\cos \alpha \sin \gamma & \cos \alpha \sin \beta \cos \gamma+\sin \alpha \sin \gamma \\ \cos \beta \sin \gamma & \sin \alpha \sin \beta \sin \gamma+\cos \alpha \cos \gamma & \cos \alpha \sin \beta \sin \gamma-\sin \alpha \cos \gamma \\ -\sin \beta & \sin \alpha \cos \beta & \cos \alpha \cos \beta \end{array}\right] R=Rz(γ)∗Ry(β)∗Rx(α)= cosβcosγcosβsinγ−sinβsinαsinβcosγ−cosαsinγsinαsinβsinγ+cosαcosγsinαcosβcosαsinβcosγ+sinαsinγcosαsinβsinγ−sinαcosγcosαcosβ
(2)旋转矩阵转欧拉角
有旋转矩阵
R = [ r 11 r 12 r 13 r 21 r 22 r 23 r 31 r 32 r 33 ] R=\left[\begin{array}{lll} r_{11} & r_{12} & r_{13} \\ r_{21} & r_{22} & r_{23} \\ r_{31} & r_{32} & r_{33} \end{array}\right] R= r11r21r31r12r22r32r13r23r33
欧拉角为
θ x = atan 2 ( r 32 , r 33 ) θ y = atan 2 ( − r 31 , r 32 2 + r 33 2 ) θ z = atan 2 ( r 21 , r 11 ) \begin{gathered} \theta_x=\operatorname{atan} 2\left(r_{32}, r_{33}\right) \\ \theta_y=\operatorname{atan} 2\left(-r_{31}, \sqrt{r_{32}^2+r_{33}^2}\right) \\ \theta_z=\operatorname{atan} 2\left(r_{21}, r_{11}\right) \end{gathered} θx=atan2(r32,r33)θy=atan2(−r31,r322+r332)θz=atan2(r21,r11)
CH3-7 四元数复合
向量 v v v 分别绕不同轴、 不同角度旋转两次
v ′ = q 1 v q 1 ∗ v ′ ′ = q 2 v ′ q 2 ∗ (3-7-1) v'=q_1vq_1^* \\ v''=q_2v'q_2^* \tag{3-7-1} v′=q1vq1∗v′′=q2v′q2∗(3-7-1)
合起来,写为
v ′ ′ = q 2 q 1 v q 1 ∗ q 2 ∗ (3-7-2) v''=q_2q_1vq_1^*q_2^* \tag{3-7-2} v′′=q2q1vq1∗q2∗(3-7-2)
先证明一个引理:
对任意四元数 q 1 = [ s , v ⃗ ] q_1=[s, \vec{v}] q1=[s,v]、 q 2 = [ t , u ⃗ ] q_2=[t, \vec{u}] q2=[t,u],有
q 1 ∗ q 2 ∗ = ( q 2 q 1 ) ∗ (3-7-3) q_1^*q_2^*=(q_2q_1)^* \tag{3-7-3} q1∗q2∗=(q2q1)∗(3-7-3)
证明:
左边 = q 1 ∗ q 2 ∗ = [ s , − v ⃗ ] [ t , − u ⃗ ] = [ s t − u ⃗ ⋅ v ⃗ , − s u ⃗ − t v ⃗ + v ⃗ × u ⃗ ] \begin{aligned} 左边&=q_1^*q_2^* \\ &=[s, -\vec{v}][t, -\vec{u}] \\ &=[st-\vec{u}\cdot\vec{v},-s\vec{u}-t\vec{v}+\vec{v}\times\vec{u}] \end{aligned} 左边=q1∗q2∗=[s,−v][t,−u]=[st−u⋅v,−su−tv+v×u]
右边 = ( q 2 q 1 ) ∗ = ( [ t , u ⃗ ] [ s , v ⃗ ] ) ∗ = ( [ s t − u ⃗ ⋅ v ⃗ , s u ⃗ + t v ⃗ + u ⃗ × v ⃗ ] ) ∗ = [ s t − u ⃗ ⋅ v ⃗ , − s u ⃗ − t v ⃗ + v ⃗ × u ⃗ ] = 左边 \begin{aligned} 右边&=(q_2q_1)^* \\ &=([t, \vec{u}][s, \vec{v}])^* \\ &=([st-\vec{u}\cdot\vec{v},s\vec{u}+t\vec{v}+\vec{u}\times\vec{v}])^* \\ &=[st-\vec{u}\cdot\vec{v},-s\vec{u}-t\vec{v}+\vec{v}\times\vec{u}] \\ &=左边 \end{aligned} 右边=(q2q1)∗=([t,u][s,v])∗=([st−u⋅v,su+tv+u×v])∗=[st−u⋅v,−su−tv+v×u]=左边
证毕。
对于式(3-7-2)
v ′ ′ = q 2 q 1 v q 1 ∗ q 2 ∗ = ( q 2 q 1 ) v ( q 2 q 1 ) ∗ = q v q ∗ \begin{aligned} v''&=q_2q_1vq_1^*q_2^* \\ &=(q_2q_1)v(q_2q_1)^* \\ &=qvq^* \end{aligned} v′′=q2q1vq1∗q2∗=(q2q1)v(q2q1)∗=qvq∗
也就是说, v v v 绕 q 1 q_1 q1、 q 2 q_2 q2旋转两次等价于绕一个全新的轴旋转一次,且 q = q 2 q 1 q=q_2q_1 q=q2q1