复数
[egin{aligned}
a &= x+yi\
ii&=-1
end{aligned}
]
四元数基础
定义
[egin{aligned}
ii&=jj=kk=-1\
ij&=-ji=k\
jk&=-kj=i\
ki&=-ik=j\
p&=p_w+p_xi+p_yj+p_zk\
q&=q_w+q_xi+q_yj+q_zk\
ppm q:&=(p_wpm q_w+(p_xpm q_x)i+(p_ypm q_y)j+(p_zpm q_z)k\
p*q:&=(p_w+p_xi+p_yj+p_zk)(q_w+q_xi+q_yj+q_zk)\
&=p_wq_w - p_xq_x - p_yq_y - p_zq_z \
&+(p_wq_x + q_wp_x + p_yq_z-p_zq_y)i\
&+(p_wq_y + q_wp_y + p_zq_x-p_xq_z )j\
&+(p_wq_z + q_wp_z + p_xq_y-p_yq_x )k\
|p| :&= sqrt{w^2+x^2+y^2+z^2}
end{aligned}
]
其中:
显然,四元数集在上述加法与数乘的定义下满足向量空间的公理,四元数集合是(R^4)向量空间。同时四元数也满足乘法定义,所以四元数也是(R)代数。
标量、向量型记法
令(xi+yj+zk=vec{v}, q = w + vec{v}), 其中(w,x,y,zin R)
[egin{aligned}
p&=w_p+vec{v_p}\
q&=w_q+vec{v_q}\
ppm q:&=w_ppm w_q + (vec{v_p}pm vec{v_q})\
p* q:&=w_pw_q - vec{v_p}cdot vec{v_q} + w_pvec{v_q} + w_qvec{v_p} + vec{v_p} imes vec{v_q}\
end{aligned}
]
绕任意轴的旋转
以下的推导基于右手坐标系。
向量式
设任意轴单位向量为(n(x,y,z),|n|=1,x,y,zin R),逆时针旋转为( heta),则向量(p(p_x,p_y,p_z))旋转后的向量(p')为:
[egin{aligned}
p_{parallel}&=(ncdot p)n\
p_{perp}&=p-p_{parallel}\
|p_{perp}|&=|p|sin(alpha)\
|n imes p|=|n||p|sin(alpha)&=|p|sin(alpha)=|p_{perp}|\
end{aligned}
]
( herefore p_{perp},n imes p)构成正交基,(p'_⊥)可由(p_{perp},n imes p)线性表示:
[egin{aligned}
p'&=p'_{perp}+p_{parallel}\
&=p_{perp}cos heta+(v imes p)sin heta+p_{parallel}\
&=(p-p_{parallel})cos heta+(v imes p)sin heta+p_{parallel}\
&=pcos heta+p_{parallel}(1-cos heta)+(v imes p)sin heta\
&=pcos heta+(ncdot p)n(1-cos heta)+(v imes p)sin heta
end{aligned}
]
矩阵式
由
[v imes p = egin{pmatrix}0 & -z & y\
z & 0 &-x\
-y & x & 0
end{pmatrix}p
]
[(ncdot p)n= egin{pmatrix}x^2 & xy & xz\
xy & y^2 & yz\
xz & yz & z^2
end{pmatrix}p
]
代入向量式可得:
[egin{aligned}
p'&=[cos heta I_3+sin hetaegin{pmatrix}0 & -z & y\
z & 0 &-x\
-y & x & 0
end{pmatrix}+(1-cos heta)egin{pmatrix}
x^2 & xy & xz\
xy & y^2 & yz\
xz & yz & z^2
end{pmatrix}]p \
&=egin{pmatrix}
cos heta+x^2(1-cos heta) & -zsin heta+xy(1-cos heta) & ysin heta+xz(1-cos heta)\
zsin heta+xy(1-cos heta) & cos heta+y^2(1-cos heta) & -xsin heta+yz(1-cos heta)\
-ysin heta+xz(1-cos heta) & xsin heta+yz(1-cos heta) & cos heta+z^2(1-cos heta)
end{pmatrix}p
end{aligned}
]
从而得到绕(vec{n})轴旋转( heta)的旋转矩阵
[R_n( heta)=egin{pmatrix}
cos heta+x^2(1-cos heta) & -zsin heta+xy(1-cos heta) & ysin heta+xz(1-cos heta)\
zsin heta+xy(1-cos heta) & cos heta+y^2(1-cos heta) & -xsin heta+yz(1-cos heta)\
-ysin heta+xz(1-cos heta) & xsin heta+yz(1-cos heta) & cos heta+z^2(1-cos heta)
end{pmatrix}
]
令(c= cos heta, s= sin heta, n(n_x,n_y,n_z)),代入上式得:
[R_n( heta)=egin{pmatrix}
c+n_x^2(1-c) & -n_zs+n_xn_y(1-c) & n_ys+n_xn_z(1-c)\
n_zs+n_xn_y(1-c) & c+n_y^2(1-c) & -n_xs+n_yn_z(1-c)\
-n_ys+n_xn_z(1-c) & n_xs+n_yn_z(1-c) & c+n_z^2(1-c)
end{pmatrix}
]
四元数与旋转
设(p=s+vec{v})为单位四元数,则(q^{-1}=s-vec{v}),令向量(p(p_x,p_y,p_z))旋转后的向量(p')为:
[egin{aligned}
p'&=qvec{p}q^{-1}\
&= (s+vec{v}) vec{p}(s-vec{v})\
&= (svec{p}-vec{v}cdot vec{p}+vec{v} imes vec{p})(s-vec{v})\
&= s^2vec{p}-underline{svec{v}cdot vec{p}}+svec{v} imes vec{p}+underline{svec{p}cdot vec{v}}-+underbrace{svec{p} imes vec{v}}_{-svec{v} imes vec{p}}+(vec{v}cdot vec{p})vec{v}+underbrace{(vec{v} imes vec{p})cdotvec{v}}_0-vec{v} imes vec{p} imesvec{v}\
&=s^2vec{p}+2s(vec{v} imes vec{p})+(vec{v}cdot vec{p})vec{v}-underbrace{vec{v} imes vec{p} imesvec{v}}_{vec{v}^2vec{p}-(vec{v}cdotvec{p})vec{v}}\
&=(s^2-vec{v}^2)vec{p}+2s(vec{v} imes vec{p})+2(vec{v}cdot vec{p})vec{v}
end{aligned}
]
用单位向量表示(v),令(vec{v}=tvec{n}),代入上式得
[p'=(s^2-t^2)vec{p}+2st(vec{n} imes vec{p})+2t^2(vec{n}cdot vec{p})vec{n}
]
四元数表达式与向量式之间的关系
联立向量式(p'=pcos heta+(ncdot p)n(1-cos heta)+(v imes p)sin heta)和四元数表达式可得:
[egin{cases}
s^2-t^2=cos heta \
2st=sin heta\
2t^2 = 1-cos heta
end{cases}
]
解得:(t=sin( heta/2), s=cos( heta/2)),从而得到由任意轴单位向量为(n(x,y,z),|n|=1,x,y,zin R),逆时针旋转为( heta),的单位四元数:
[p=(s,tvec{n})=(cos( heta/2),(n_xsin heta, n_ysin heta, n_zsin heta ))
]
或
[egin{cases}
s=cos( heta/2)\
v_x=n_xsin( heta/2)\
v_y=n_ysin( heta/2)\
v_z=n_zsin( heta/2)
end{cases}
]
四元数表达式与矩阵式之间的关系
利用旋转四元数中的分量(w^2+v_x^2+v_y^2+v_z^2=1)对旋转矩阵进行化简:
[egin{aligned}
cos( heta/2)&=w\
n_xsin( heta/2)&=v_x=x\
n_ysin( heta/2)&=v_y=y\
n_zsin( heta/2)&=v_z=z\
c=cos heta&=2cos^2( heta/2)-1=2w^2-1\
1-cos heta&=2sin^2( heta/2)\
n_x^2(1-cos heta)&=2n_x^2sin^2( heta/2)=2v_x^2\
n_y^2(1-cos heta)&=2n_y^2sim =2v_y^2\
n_z^2(1-cos heta)&=2n_z^2sim =2v_z^2\
sin heta&=2sin( heta/2)cos( heta/2)=2sin( heta/2)w\
n_xsin( heta)&=n_x2sin( heta/2)w=2wv_x\
n_ysin( heta)&=n_ysim=2wv_y\
n_zsin( heta)&=n_zsim=2wv_z\
n_xn_y(1-cos( heta))&=2n_xn_ysin^2( heta/2)=2v_xv_y\
n_xn_z(1-cos( heta))&=2n_xn_zsim=2v_xv_z\
n_yn_z(1-cos( heta))&=2n_yn_zsim=2v_yv_z\
end{aligned}
]
[egin{aligned}
R_n( heta)&=egin{pmatrix}
c+n_x^2(1-c) & -n_zs+n_xn_y(1-c) & n_ys+n_xn_z(1-c)\
n_zs+n_xn_y(1-c) & c+n_y^2(1-c) & -n_xs+n_yn_z(1-c)\
-n_ys+n_xn_z(1-c) & n_xs+n_yn_z(1-c) & c+n_z^2(1-c)
end{pmatrix}\
&=egin{pmatrix}
2w^2+2x^2-1 & 2xy-2wz & 2xz+2wy\
2xy+2wz & 2w^2+2y^2-1 & 2yz-2wx\
2xz-2wy & 2yz+2wx & 2w^2+2z^2-1
end{pmatrix}\
&=egin{pmatrix}
1-2y^2-2z^2 & 2xy-2wz & 2xz+2wy\
2xy+2wz & 1-2x^2-2z^2 & 2yz-2wx\
2xz-2wy & 2yz+2wx & 1-2x^2-2y^2
end{pmatrix}
end{aligned}
]
分开助记:
[egin{aligned}
R_n( heta)&=[cos heta I_3+sin hetaegin{pmatrix}0 & -n_z & n_y\
n_z & 0 &-n_x\
-n_y & n_x & 0
end{pmatrix}+(1-cos heta)egin{pmatrix}
n_x^2 & n_xn_y & n_xn_z\
n_xn_y & n_y^2 & n_yn_z\
n_xn_z & n_yn_z & n_z^2
end{pmatrix}]\
&=(2w^2-1)egin{pmatrix}
1 & 0 & 0\
0 & 1 & 0\
0 & 0 & 1
end{pmatrix}+2wegin{pmatrix}
0 & -z & y\
z & 0 &-x\
-y & x & 0
end{pmatrix}+egin{pmatrix}
0 & 2xy & 2xz\
2xy & 0 & 2yz\
2xz & 2yz & 0
end{pmatrix}\
&=egin{pmatrix}
2w^2-1 & 0 & 0\
0 & 2w^2-1 & 0\
0 & 0 & 2w^2-1
end{pmatrix}+egin{pmatrix}
0 & -2wz & 2wy\
2wz & 0 & -2wx\
-2wy & 2wx & 0
end{pmatrix}+egin{pmatrix}
0 & 2xy & 2xz\
2xy & 0 & 2yz\
2xz & 2yz & 0
end{pmatrix}
end{aligned}
]
通过四元数,旋转矩阵用了竟然是(对角阵+反称矩阵+对称矩阵),神奇也优美!