Representation of Rigid Body Pose and Rotation

In the coordinate system, the state of a rigid body can be described by its position and attitude. The position is the spatial position of the rigid body in the coordinate system, which can be expressed by a coordinate vector. To describe the attitude of a rigid body, there are many representation methods, the following are commonly used ones:

1 Rotation matrix (Rotation matrix)

The rotation matrix is ​​a matrix that changes the direction of the vector but does not change the size when it is multiplied by a vector. The rotation matrix can be directly calculated. It uses 9 quantities to express a rotation, but in fact there are only 3 freedoms for a rotation. Spend. Therefore the rotation matrix expression is redundant. At the same time, there are constraints on the rotation matrix itself, it must be an orthogonal matrix, and the determinant is 1, these constraints will make it difficult to solve.
The rotation matrix is ​​easier to understand, not much to say here, it can be seen: coordinate transformation and rotation matrix

2 Euler angles

2.1 Euler angles

The Euler angle is a set of 3 angle parameters that describe the attitude of the rigid body. At the same time, it is necessary to specify the coordinate axes around which the three angles rotate, and the order of rotation. Once these are determined, the description of the Euler angle can be Decomposed into three basic rotations, the rotation matrix of the three basic rotations is: the rotation
matrix of θ around the X axis: RX ( θ ) = [ 1 0 0 0 cos θ − sin θ 0 sin θ cos θ ] R_X(θ )=\left[\begin{matrix} 1&0&0\\ 0&cosθ&-sinθ\\ 0&sinθ&cosθ\\ \end{matrix}\right]RX( i )=1000cosθsinθ0sinθcosθ
Equivalent graph: RY ( θ ) = [ cos θ 0 sin θ 0 1 0 − sin θ 0 cos θ ] R_Y(θ)=\left[\begin{matrix} cosθ&0&sinθ\\ 0&1&0\\ - . sinθ&0&cosθ\\\end{matrix}\right]RY( i )=cosθ0sinθ010sinθ0cosθ
Equation: RZ ( θ ) = [ cos θ − sin θ 0 sin θ cos θ 0 0 0 1 ] R_Z(θ)=\left[\begin{matrix} cosθ&-sinθ&0\\ sinθ&cosθ&0\; \0&0&1\\\end{matrix}\right]RZ( i )=cosθsinθ0sinθcosθ0001
Personal understanding of Euler angles

2.1 Euler angles and rotation matrix

Any rotation matrix about rigid body rotation can be composed of three basic rotation matrices. However, it should be considered that Euler angles are divided into internal rotation and external rotation. The three basic rotation combinations of internal rotation and external rotation are different. The three basic rotation matrices need to be multiplied to the right for internal rotation, and the three basic rotation matrices for external rotation The rotation matrix needs to be multiplied to the left.

Outer rotation Euler angle calculation

任亏三界长x,y,z的欧拉角are respectively a,b,c,外旋,then the rotation matrix is ​​(for the sake of 简洁,使用sin和cos 电影用s和c电影) R ( a , b ,
c ) = R z ( γ ) R y ( β ) R x ( α ) = [ c β c γ c γ s α s β − c α s γ s α s γ + c α c γ s β c β s γ c α c γ + s α s β s γ c α s β s γ − c γ s γ − s β c β s α c α c β ] R(α,β,γ)=R_z(γ)R_y(β) R_x(α)=\left[\begin{matrix} cβcγ&cγsαsβ-cαγ&sαsγ+cαcγsβ\\ cβsγ&cαcγ+sαsβsγ&cαβsγ-cγsγ\\ -sβ&cβsα&cαcβ \end{matrix}\right]R ( α ,b ,c )=Rz( c ) Ry( b ) Rx( a )=cβcγc b s csβc c s a s bcαsγcαcγ+s a s b s cc b s asαsγ+c a c c s bc a s b s ccγsγcαcβ
Conversely, corresponding to this rotation, the known rotation matrix [ r 11 r 12 r 13 r 21 r 22 r 23 r 31 r 32 r 33 ] \left[\begin{matrix} r_{11}&r_{12}&r_{13} \\ r_{21}&r_{22}&r_{23} \\ r_{31}&r_{32}&r_{33} \end{matrix}\right]r11r21r31r12r22r32r13r23r33, Euler angles can be solved to get
α = arctg ( r 32 r 33 ) β = arctg ( − r 31 r 32 2 + r 33 2 ) γ = arctg ( r 21 r 11 ) α=arctg(\frac{r_{32 }}{r_{33}})\\ β=arctg(\frac{-r_{31}}{\sqrt{r_{32}^2+r_{33}^2}})\\ γ=arctg( \frac{r_{21}}{r_{11}})a=a r c t g (r33r32)b=a r c t g (r322+r332 r31)c=a r c t g (r11r21)

Internal Rotation Euler Angles Calculation

Let the internal rotation sequence be ZXY (Z-axis up, Y-axis forward), and the rotation angles are yaw, pitch, roll respectively, then the rotation matrix is ​​R ( yaw , pitch , roll ) = R z ( yaw ) R x (
pitch ) R y ( roll ) R(yaw,pitch,roll)=R_z(yaw)R_x(pitch)R_y(roll)R(yaw,pitch,roll)=Rz(yaw)Rx(pitch)Ry( r o l l )
Conversely, corresponding to this rotation, the known rotation matrix[ r 11 r 12 r 13 r 21 r 22 r 23 r 31 r 32 r 33 ] \left[\begin{matrix} r_{11}&r_{ 12}&r_{13} \\ r_{21}&r_{22}&r_{23} \\ r_{31}&r_{32}&r_{33} \end{matrix}\right]r11r21r31r12r22r32r13r23r33, the internal rotation Euler angle can be solved as
yaw = − arctg ( r 12 r 22 ) pitch = arcsin ( r 32 ) roll = − arctg ( r 31 r 33 ) yaw=-arctg(\frac{r_{12}}{ r_{22}})\\ pitch=arcsin(r_{32})\\ roll=-arctg(\frac{r_{31}}{r_{33}})yaw=- a r c t g (r22r12)pitch=arcsin(r32)roll=- a r c t g (r33r31)

3 Axial angle

3.1 Shaft angle

Axis angles are rotations represented by two parameters: an axis or line, and the angle of rotation around that axis. It is also called rotated exponential coordinates.
Given a vector K ^ = ( kx , ky , kz ) \hat K=(k_x,k_y,k_z)K^=(kx,ky,kz) , with this vectorK ^ \hat KK^ is the rotation axis, rotateθ θθ angle, so we use a four-dimensional vector( kx , ky , kz , θ ) (k_x,k_y,k_z,θ)(kx,ky,kz,θ ) can represent this rotation.

3.2 Rotation vector

The axis angle is sometimes represented by a rotation vector. The axis angle is described above as a four-dimensional vector to express a rotation, and a more compact representation is to use a unit vector to represent the axis, and use the length of the three-dimensional vector to represent the angle value theta. In this way, it can be simplified to represent the rotation with a three-dimensional vector, which is the rotation vector.
That is: the above axial vector K ^ = ( kx , ky , kz ) \hat K=(k_x,k_y,k_z)K^=(kx,ky,kz) is taken as the unit vectorK ^ 0 = ( kx 0 , ky 0 , kz 0 ) \hat K_0=(k_{x0},k_{y0},k_{z0})K^0=(kx 0,ky 0,kz 0) ,determine the following:
R = [ R x R y R z ] = [ θ ⋅ kx 0 θ ⋅ ky 0 θ ⋅ kz 0 ] \mathbf R=\left[\begin{matrix}R_x\\R_y\ \R_z\end{matrix}\right]=\left[\begin{matrix}θ\cdot k_{x0}\\θ\cdot k_{y0}\\θ\cdot k_{z0}\end{matrix}\ right]R=RxRyRz=ikx 0iky 0ikz 0
Similarly, the axis angle parameter
θ = R x 2 + R y 2 + R z 2 can also be obtained by rotating the vector kx 0 = R x / θ , ky 0 = R y / θ , kz 0 = R z / θ θ=\ sqrt{R_x^2+R_y^2+R_z^2}\\ k_{x0}=R_x/θ, k_{y0}=R_y/θ, k_{z0}=R_z/θi=Rx2+Ry2+Rz2 kx 0=Rx/ i ,ky 0=Ry/ i ,kz 0=Rz/ i

3.3 Axis Angle and Rotation Matrix

(k_x,k_y,k_z,θ )(kx,ky,kz,θ ) , in addition to the Rodrigues equation, we obtained the equation
RK ^ ( θ ) = c θ I + ( 1 − c θ ) rr T + s θ [ 0 − kzkykz 0 − kx − kykx 0 ] R_{\hat K}(θ)=cθI+(1-cθ)rr^T+sθ\left[\begin{matrix} 0&-k_z&k_y\\ k_z&0&-k_x\\ -k_y&k_x&0 \end{matrix}\right]RK^( i )=cθI+(1cθ)rrT+sθ0kzkykz0kxkykx0
其中 r = ( k x , k y , k z ) T r=(k_x,k_y,k_z)^T r=(kx,ky,kz)T,即:RK ^ ( θ ) = [ c θ + kx 2 ( 1 − c θ ) kxky ( 1 − c θ ) − kzs θ kxkz ( 1 − c θ ) + kys θ kykx ( 1 − c θ ) + kzs θ c θ + ky 2 ( 1 − c θ ) kykz ( 1 − c θ ) − kxs θ kzkx ( 1 − c θ ) − kys θ kzky ( 1 − c θ ) + kxs θ c θ + kz 2 ( 1 − c θ ) ] R_{\hat K}(θ)=\left[\begin{matrix} cθ+k_x^2(1-cθ)&k_xk_y(1-cθ)-k_zsθ&k_xk_z(1-cθ)+k_ysθ\\ k_yk_x(1-cθ)+k_zsθ&cθ+k_y^2(1-cθ)&k_yk_z(1-cθ)-k_xsθ\\ k_zk_x(1-cθ)-k_ysθ&k_zk_y(1-cθ)+k_xsθ&cθ+k_z^2(1-cθ) )\\ \end{matrix}\right]RK^( i )=c i+kx2(1c i )kykx(1c i )+kzsθkzkx(1c i )kysθkxky(1c i )kzsθc i+ky2(1c i )kzky(1c i )+kxsθkxkz(1c i )+kysθkykz(1c i )kxsθc i+kz2(1c i ).
The above conversion formula has a related implementation function in Opencv: Rodrigues2().
Conversely, the known rotation matrix R = [ r 11 r 12 r 13 r 21 r 22 r 23 r 31 r 32 r 33 ] R=\left[\begin{matrix} r_{11}&r_{12}&r_{13} \\ r_{21}&r_{22}&r_{23} \\ r_{31}&r_{32}&r_{33} \\ \end{matrix}\right]R=r11r21r31r12r22r32r13r23r33,individually define the equation
θ [ 0 − kzkykz 0 − kx − kykx 0 ] = R − RT 2 sθ\left[\begin{matrix} 0&-k_z&k_y\\ k_z&0&-k_x\\ -k_y&k_x&0 \end{; matrix}\right]=\frac{RR^T}{2}sθ0kzkykz0kxkykx0=2RRT

θ = a r c c o s ( r 11 + r 22 + r 33 − 1 2 ) K ^ = [ k x k y k z ] = 1 2 s i n θ [ r 32 − r 23 r 13 − r 31 r 21 − r 12 ] θ=arccos(\frac{r_{11}+r_{22}+r_{33}-1}{2})\\ \hat K=\left[\begin{matrix}k_x\\k_y\\k_z\end{matrix}\right]= \frac{1}{2sinθ}\left[\begin{matrix}r_{32}-r_{23}\\r_{13}-r_{31}\\r_{21}-r_{12}\end{matrix}\right] i=arccos(2r11+r22+r331)K^=kxkykz=2sinθ1r32r23r13r31r21r12
It can be seen that when θ θθ不0或2 Π 2Π2 Π , the axis of rotation cannot be determined and is singular.

4 Quaternions

4.1 Quaternions

Quaternions are introduced to solve the shortcomings of Euler angles, axis angles, rotation matrices, etc.:

  • The gimbal lock problem of Euler angles;
  • The singularity of the axis angle;
  • The 9 values ​​of the rotation matrix are not independent of each other.

Quaternions are simply hypercomplex numbers. Complex numbers are real numbers plus an imaginary unit iii composition, of whichi 2 = − 1 i^2 = -1i2=−1 . _ Similarly, a quaternion is a real number plus three imaginary unitsiii j j j k k k , and they have the following relationship:i 2 = j 2 = k 2 = − 1 , i 0 = j 0 = k 0 = 1 i^2 = j^2 = k^2 = -1, i^0 = j^0 = k^0 = 1i2=j2=k2=1i0=j0=k0=1 , each quaternion is 1,iii j j j andkkThe linear combination of k , that is, the quaternion can generally be expressed asa + bi + cj + dka + bi + cj + dka+bi+cj+d k , whereaaa b b b c c c d d d is a real number.
Let unit quaternionq = ( q 0 , q 1 , q 2 , q 3 ) \mathbf q=(q_0,q_1,q_2,q_3)q=(q0,q1,q2,q3) ,whenq 0 2 + q 1 2 + q 2 2 + q 3 2 = 1 q_0^2+q_1^2+q_2^2+q_3^2=1q02+q12+q22+q32=1 , if there is a unit vector( x , y , z ) (x,y,z)(x,y,z ) is the rotation axis, the rotation angleθ θθ , inherently infinite:q = ( cos θ 2 , xsin θ 2 , ysin θ 2 , zsin θ 2 ) \mathbf q=(cos\frac{θ}{2},xsin\frac{θ} {2},ysin\frac{θ}{2},zsin\frac{θ}{2})q=(cos2i,x s i n2i,y s i n2i,z s i n2i)
Set a pointP 1 = ( px , py , pz ) \mathbf P_1=(p_x,p_y,p_z)P1=(px,py,pz) , we need to use the above rotation quaternion to transform its rotation toP 1 ′ = ( px ′ , py ′ , pz ′ ) \mathbf P_1'=(p_x',p_y',p_z')P1=(px,py,pz) , the calculation process is as follows:

  • 1 Definition: qp = ( 0 , px , py , pz ) = 0 + px ∗ i + py ∗ j + pz ∗ k \mathbf q_p=(0,p_x,p_y,p_z)=0+p_x* i+p_y*j+p_z*kqp=(0,px,py,pz)=0+pxi+pyj+pzk
  • 2 Perform quaternion operations: qp ′ = qqpq − 1 \mathbf q_p'=\mathbf q\mathbf q_p\mathbf q^{-1}qp=qqpq1 , whereq − 1 \mathbf q^{-1}q1oneq \mathbf qq Definition:q − 1 = ( cos θ 2 , − xsin θ 2 , − ysin θ 2 , − zsin θ 2 ) \mathbf q^{-1}=(cos\frac{θ}{2},- xsin\frac{θ}{2},-ysin\frac{θ}{2},-zsin\frac{θ}{2})q1=(cos2i,x s i n2i,y s i n2i,z s i n2i)
  • 3 The resulting qp ′ \mathbf q_p'qpIt must be a pure quaternion, that is to say, its first item is 0, and it has the following form: qp ′ = ( 0 , px ′ , py ′ , pz ′ ) = 0 + px ′ ∗ i + py ′ ∗ j + pz ′ ∗ k \mathbf q_p'=(0,p_x',p_y',p_z')=0+p_x'*i+p_y'*j+p_z'*kqp=(0,px,py,pz)=0+pxi+pyj+pz
    The last three terms of k ( px ′ , py ′ , pz ′ ) (p_x',p_y',p_z')(px,py,pz) is the coordinate vector after rotation transformation.

Therefore, after the introduction of quaternions, the rotation of three-dimensional coordinates can be directly operated by quaternion multiplication, which is equivalent to the operation of the rotation matrix. There is no singularity phenomenon of axis angle calculation, the representation method is more compact, and the calculation amount can also be small. Some.
Similarly, if you have a quaternion: q = ( q 0 , q 1 , q 2 , q 3 ) = ( cos θ 2 , xsin θ 2 , ysin θ 2 , zsin θ 2 ) \mathbf q=(q_0 ,q_1,q_2,q_3)=(cos\frac{θ}{2},xsin\frac{θ}{2},ysin\frac{θ}{2},zsin\frac{θ}{2})q=(q0,q1,q2,q3)=(cos2i,x s i n2i,y s i n2i,z s i n2i) , then it corresponds to a vector( x , y , z ) (x,y,z)(x,y,z ) is the rotation operation of axis rotation θ angle.

4.2 Quaternion and rotation matrix

Known quaternion q = ( q 0 , q 1 , q 2 , q 3 ) \mathbf q=(q_0,q_1,q_2,q_3)q=(q0,q1,q2,q3),可求得旋转矩阵
R = [ 2 q 0 2 + 2 q 1 2 − 1 2 q 1 q 2 + 2 q 0 q 3 2 q 1 q 3 − 2 q 0 q 2 2 q 1 q 2 − 2 q 0 q 3 2 q 0 2 + 2 q 2 2 − 1 2 q 2 q 3 + 2 q 0 q 1 2 q 1 q 3 + 2 q 0 q 2 2 q 2 q 3 − 2 q 0 q 1 2 q 0 2 + 2 q 3 2 − 1 ] R=\left[\begin{matrix} 2q_0^2+2q_1^2-1&2q_1q_2+2q_0q_3&2q_1q_3-2q_0q_2\\ 2q_1q_2-2q_0q_3&2q_0^2+2q_2^2-1&2q_2q_3+2q_0q_1\\ 2q_1q_3+2q_0q_2&2q_2q_3-2q_0q_1&2q_0^2+2q_3^2-1\\ \end{matrix}\right] R=2q02+2q1212q1q22q0q32q1q3+2q0q22q1q2+2q0q32q02+2q2212q2q32q0q12q1q32q0q22q2q3+2q0q12q02+2q321
On the contrary, the known rotation matrix [ r 11 r 12 r 13 r 21 r 22 r 23 r 31 r 32 r 33 ] \left[\begin{matrix} r_{11}&r_{12}&r_{13} \\ r_{ 21}&r_{22}&r_{23} \\ r_{31}&r_{32}&r_{33} \end{matrix}\right]r11r21r31r12r22r32r13r23r33, to find a quaternion, divided into two cases:
Case 1:
q 0 = 1 + r 11 + r 22 + r 33 2 q 1 = r 32 − r 23 4 q 0 , q 2 = r 13 − r 31 4 q 0 , q 3 = r 21 − r 12 4 q 0 , q_0=\frac{\sqrt{1+r_{11}+r_{22}+r_{33}}}{2}\\ q_1=\frac {r_{32}-r_{23}}{4q_0},q_2=\frac{r_{13}-r_{31}}{4q_0},q_3=\frac{r_{21}-r_{12}}{ 4q_0},q0=21+r11+r22+r33 q1=4 q0r32r23,q2=4 q0r13r31,q3=4 q0r21r12,
case 2: ifq 0 q_0q0tends to 0, the process of solving the quaternion is:
2.1 If max ( r 11 , r 22 , r 33 ) = r 11 max(r_{11},r_{22},r_{33})=r_{11 }max(r11,r22,r33)=r11
t = 1 + r 11 − r 22 − r 33 q 0 = r 32 − r 23 t , q 1 = t / 4 , q 2 = r 13 + r 31 t , q 3 = r 12 + r 21 t t=\sqrt{1+r_{11}-r_{22}-r_{33}}\\ q_0=\frac{r_{32}-r_{23}}{t},q_1=t/4,q_2=\frac{r_{13}+r_{31}}{t},q_3=\frac{r_{12}+r_{21}}{t} t=1+r11r22r33 q0=tr32r23,q1=t/4,q2=tr13+r31,q3=tr12+r21
2.2 If max ( r 11 , r 22 , r 33 ) = r 22 max(r_{11},r_{22},r_{33})=r_{22}max(r11,r22,r33)=r22
t = 1 − r 11 + r 22 − r 33 q 0 = r 13 − r 31 t , q 1 = r 12 + r 21 t , q 2 = t / 4 , q 3 = r 32 + r 23 t t=\sqrt{1-r_{11}+r_{22}-r_{33}}\\ q_0=\frac{r_{13}-r_{31}}{t},q_1=\frac{r_{12}+r_{21}}{t},q_2=t/4,q_3=\frac{r_{32}+r_{23}}{t} t=1r11+r22r33 q0=tr13r31,q1=tr12+r21,q2=t/4,q3=tr32+r23
2.3 If max ( r 11 , r 22 , r 33 ) = r 33 max(r_{11},r_{22},r_{33})=r_{33}max(r11,r22,r33)=r33
t = 1 − r 11 − r 22 + r 33 q 0 = r 21 − r 12 t , q 1 = r 13 + r 31 t , q 2 = r 23 − r 32 t , q 3 = t / 4 t=\sqrt{1-r_{11}-r_{22}+r_{33}}\\ q_0=\frac{r_{21}-r_{12}}{t},q_1=\frac{r_{13}+r_{31}}{t},q_2=\frac{r_{23}-r_{32}}{t},q_3=t/4 t=1r11r22+r33 q0=tr21r12,q1=tr13+r31,q2=tr23r32,q3=t/4

reference

Brief book: Attitude description - quaternion, rotation matrix
is ​​known by Euler angle: how to understand quaternion visually?
Rotation matrix, Euler angle, quaternion theory and its conversion relationship
3D reconstruction learning (1): Basic knowledge: rotation matrix and rotation vector

Guess you like

Origin blog.csdn.net/hangl_ciom/article/details/99691694