|
四元数的运算: 基本的: p=[1 2 3 4] q=[5 6 7 8] p+q=[6 8 10 12] 2p=[2 4 6 8] 2个四元数的积: p=[m,u]q=[n,v]pq=[mn-vu,nu+mv+(v×u)] m,n是标量,u,v是向量 共轭四元数: p=[n,v]~p=[n,-v] 旋转1个四元数( 或向量): p'=q(p)(~q) 旋转向量的话:用向量取代p的向量部分,p的标量部分取零。 四元数到旋转矩阵的变换: |w2+x2-y2-y22xy-2wz2xy+2yn| |2xy+2wzw2-x2+y2-y22yz-2wx| |2xz-2wy2yz-2wxw2-x2-y2+z2| 旋转矩阵到四元数的变换: tr=m11+m22+m33 if(tr>0) { temp=1/2squrt(tr+1); qw=0.25/tempqx=(m23-m32)tempqy=(m31-m13)tempqz=(m12-m21)temp }else { m11,m22,m33中 if(m11 is greatest){ temp=1/2squrt(1+m11-m22+m33) qw=0.25/tempqx=(m21+m12)tempqy=(m13+m31)tempqz=(m32-m23)temp} if(m22 is greatest){ temp=1/squrt(1+m22-m11-m33) qw=(m21+m12tempqx=0.25/tempqy=(m32+m23)tempqz=(m13-m31)temp} if(m33 is greatest){ temp=1/squrt(1+m33-m11-m22) qw=(m13+m31)tempqx=(m32+m23)tempqy=0.25/tempqz=(m21-m12)temp} } Euler Anglesand Quaternions: q=[cos(angle/2),sing(angle/2)axis] axis为一向量,是旋转所绕之轴 sa=squrt(1-qw2)angle=2arccos(qw) axisx=qx/saaxisy=qy/saaxisz=qz/sa 还有四元数的线性和球面插值晚上再打。
|