我们知道,四元数是除了欧拉角,旋转矩阵之外,主要用来描述旋转的量。四元数直观的定义就是
q = [ c o s ( θ 2 ) , s i n ( θ 2 ) N ] q = [cos(\frac{\theta}{2}), sin(\frac{\theta}{2})N] q=[cos(2θ),sin(2θ)N]
其中,N表示旋转轴单位向量, θ \theta θ表示旋转的角度。那么,给定一个任意向量V,绕N旋转 θ \theta θ角度之后的V’可以用四元数乘法表示。令四元数v = [0, V],v’ = [0, V’],那么
v ′ = q v q ∗ v' = qvq^* v′=qvq∗
我们先来推导一下这个公式。
绕任意轴旋转
首先,四元数的乘法公式为
q 1 = [ s , v ] q_1 = [s, \textbf{v}] q1=[s,v]
q 2 = [ t , u ] q_2 = [t, \textbf{u}] q2=[t,u]
q 1 q 2 = [ s t − v ⋅ u , s u + t v + v × u ] q_1q_2 = [st - \textbf{v} \cdot \textbf{u}, s\textbf{u} + t\textbf{v} + \textbf{v} \times \textbf{u}] q1q2=[st−v⋅u,su+tv+v×u]
那么
v q ∗ = [ s i n ( θ 2 ) N ⋅ V , c o s ( θ 2 ) V + s i n ( θ 2 ) N × V ] vq^* = [sin(\frac{\theta}{2})N \cdot V, cos(\frac{\theta}{2}) V + sin(\frac{\theta}{2}) N \times V] vq∗=[sin(2θ)N⋅V,cos(2θ)V+sin(2θ)N×V]
q v q ∗ = [ s i n ( θ 2 ) c o s ( θ 2 ) N ⋅ V − s i n ( θ 2 ) N ⋅ ( c o s ( θ 2 ) V + s i n ( θ 2 ) N × V ) , c o s ( θ 2 ) ( c o s ( θ 2 ) V + s i n ( θ 2 ) N × V ) + s i n 2 ( θ 2 ) ( N ⋅ V ) N + s i n ( θ 2 ) N × ( c o s ( θ 2 ) V + s i n ( θ 2 ) N × V ) ] qvq^* = [ sin(\frac{\theta}{2})cos(\frac{\theta}{2})N \cdot V - sin(\frac{\theta}{2})N \cdot (cos(\frac{\theta}{2}) V + sin(\frac{\theta}{2}) N \times V), \\ cos(\frac{\theta}{2})(cos(\frac{\theta}{2}) V + sin(\frac{\theta}{2}) N \times V) + sin^2(\frac{\theta}{2})(N \cdot V)N + sin(\frac{\theta}{2}) N \times (cos(\frac{\theta}{2}) V + sin(\frac{\theta}{2}) N \times V) ] qvq∗=[sin(2θ)cos(2θ)N⋅V−sin(2θ)N⋅(cos(2θ)V+sin(2θ)N×V),cos(2θ)(cos(2θ)V+sin(2θ)N×V)+sin2(2θ)(N⋅V)N+sin(2θ)N×(cos(2θ)V+sin(2θ)N×V)]
我们先对结果的实部进行化简,因为点乘满足分配律,所以有
s i n ( θ 2 ) c o s ( θ 2 ) N ⋅ V − s i n ( θ 2 ) N ⋅ ( c o s ( θ 2 ) V + s i n ( θ 2 ) N × V ) = s i n ( θ 2 ) c o s ( θ 2 ) N ⋅ V − s i n ( θ 2 ) c o s ( θ 2 ) N ⋅ V − s i n 2 ( θ 2 ) N ⋅ ( N × V ) = − s i n 2 ( θ 2 ) N ⋅ ( N × V ) sin(\frac{\theta}{2})cos(\frac{\theta}{2})N \cdot V - sin(\frac{\theta}{2})N \cdot (cos(\frac{\theta}{2}) V + sin(\frac{\theta}{2}) N \times V) \\ = sin(\frac{\theta}{2})cos(\frac{\theta}{2})N \cdot V - sin(\frac{\theta}{2})cos(\frac{\theta}{2})N \cdot V - sin^2(\frac{\theta}{2})N \cdot (N \times V) \\ = - sin^2(\frac{\theta}{2})N \cdot (N \times V) sin(2θ)cos(2θ)N⋅V−sin(2θ)N⋅(cos(2θ)V+sin(2θ)N×V)=sin(2θ)cos(2θ)N⋅V−sin(2θ)cos(2θ)N⋅V−sin2(2θ)N⋅(N×V)=−sin2(2θ)N⋅(N×V)
N和V的叉乘显然与N垂直,所以点积为0,因此
− s i n 2 ( θ 2 ) N ⋅ ( N × V ) = 0 -sin^2(\frac{\theta}{2})N \cdot (N \times V) = 0 −sin2(2θ)N⋅(N×V)=0
再看虚部,同样叉乘也满足分配律,所以有
c o s ( θ 2 ) ( c o s ( θ 2 ) V + s i n ( θ 2 ) N × V ) + s i n 2 ( θ 2 ) ( N ⋅ V ) N + s i n ( θ 2 ) N × ( c o s ( θ 2 ) V + s i n ( θ 2 ) N × V ) = c o s 2 ( θ 2 ) V + s i n ( θ 2 ) c o s ( θ 2 ) N × V + s i n 2 ( θ 2 ) ( N ⋅ V ) N + s i n ( θ 2 ) c o s ( θ 2 ) N × V + s i n 2 ( θ 2 ) N × ( N × V ) cos(\frac{\theta}{2})(cos(\frac{\theta}{2}) V + sin(\frac{\theta}{2}) N \times V) + sin^2(\frac{\theta}{2})(N \cdot V)N + sin(\frac{\theta}{2}) N \times (cos(\frac{\theta}{2}) V + sin(\frac{\theta}{2}) N \times V) \\ = cos^2(\frac{\theta}{2})V + sin(\frac{\theta}{2})cos(\frac{\theta}{2})N \times V + sin^2(\frac{\theta}{2})(N \cdot V)N + sin(\frac{\theta}{2})cos(\frac{\theta}{2}) N \times V + sin^2(\frac{\theta}{2})N \times (N \times V) cos(2θ)(cos(2θ)V+sin(2θ)N×V)+sin2(2θ)(N⋅V)N+sin(2θ)N×(cos(2θ)V+sin(2θ)N×V)=cos2(2θ)V+sin(2θ)cos(2θ)N×V+sin2(2θ)(N⋅V)N+sin(2θ)cos(2θ)N×V+sin2(2θ)N×(N×V)
注意,叉乘并不满足结合律,且有
a × ( b × c ) = ( a ⋅ c ) b − ( a ⋅ b ) ⋅ c \textbf{a} \times (\textbf{b} \times \textbf{c}) = (\textbf{a} \cdot \textbf{c})\textbf{b} - (\textbf{a} \cdot \textbf{b}) \cdot \textbf{c} a×(b×c)=(a⋅c)b−(a⋅b)⋅c
所以上式进一步化简得到
c o s 2 ( θ 2 ) V + 2 s i n ( θ 2 ) c o s ( θ 2 ) N × V + s i n 2 ( θ 2 ) ( N ⋅ V ) N + s i n 2 ( θ 2 ) ( ( N ⋅ V ) N − V ) = ( c o s 2 ( θ 2 ) − s i n 2 ( θ 2 ) ) V + 2 s i n 2 ( θ 2 ) ( ( N ⋅ V ) N + 2 s i n (