Euler angles, rotation matrices, and quaternions

1 Introduction

Common attitude parameter expressions include direction cosine matrix, Euler axis/angle parameters, Euler angles, quaternions, and Rodrigue parameters, etc. High-resolution optical remote sensing satellites mainly use Euler angles and quaternions to describe attitude parameters. Here we focus on Euler angles, rotation matrices and quaternions.

2. Euler angles

2.1 Definition of Euler angles

Euler angle is one of the methods to characterize the rotation of a rigid body. The three angles introduced by Leonhard Euler are used to describe the direction of a rigid body relative to a fixed coordinate system. In photogrammetry, space science or other technical fields, a set of (three) Euler angles is generally used to describe the rotation transformation relationship between two space coordinates.

A rotation of a rigid body in three-dimensional space can be defined by around X \mathrm{X}The angle of rotation of the X axis, aroundY \mathrm{Y}The angle of rotation of the Y axis, aroundZ \mathrm{Z}Characterized by the angle of Z- axis rotation, these three angles are the roll angle (roll, symbolφ \varphiφ ), pitch angle (pitch, symbolθ \thetaθ ), heading angle (yaw, symbolψ \psiψ ), or with the symbolα \alphaab \betaβ γ \gamma γ represents the angle of rotation around the XYZ axes (roll, pitch, and heading), respectively. The signs of the three corners can be represented by the right-hand rule.
insert image description here
Compared with other attitude parameter expressions, the Euler angle parameters have obvious geometric meanings, and can describe the attitude dynamic equation more directly. According to Euler's theorem, the displacement of a rigid body around a fixed point can be transformed into the synthesis of several finite rotations. For high-resolution optical remote sensing satellites, the above principles and methods can also be used to realize the conversion between the reference coordinate system (J2000 coordinate system, WGS84 coordinate system) and the satellite body coordinate system. In the conversion process between the reference coordinate system and the body coordinate system, different rotation sequences and methods will result in different forms of Euler angle parameters.

2.2 Right-handed and left-handed

insert image description here
The left and right pictures are left-handed and right-handed, respectively.
For right-handed coordinates, the right thumb points in the positive direction along the z-axis, the index finger points in the x-axis, and the middle finger points in the y-axis.
For left-handed coordinates, the left thumb points in the positive direction along the z-axis, the index finger points in the x-axis, and the middle finger points in the y-axis.

2.3 Conversion process

The orientation of a rigid body can be determined using three basic rotation matrices. In other words, any rotation matrix about rigid body rotation is composed of three basic rotation matrices . By the coordinate system S a S_{a}Sato S b S_{b}SbThe transformation of can be achieved by the following three consecutive rotations:
insert image description here

Step1: Zigzag system O − xayaza O-x_{a} y_{a} z_{a}Oxayazaza z_{a}zaThe shaft is rotated counterclockwise through the angle ψ \psiψ , 称为O − x ′ y ′ za Ox^{\prime} y^{\prime} z_{a}Oxyza;
Step2: O − x ′ y ′ za Ox^{\prime} y^{\prime} z_{a}Oxyzay ′y'y' The axis turns counterclockwise through the angleθ \thetaθ , called asO − xby ′ z ′ ′ O-x_b y^{\prime} z''Oxbyz ;
Step3: Coordinate systemO − xby ′ z ′ ′ O-x_{b} y^{\prime} z^{\prime \prime}Oxbyz aroundxb x_{b}xbThe axis rotates counterclockwise through the angle φ \varphiφ , abbreviated asO − xbybzb O-x_{b} y_{b} z_{b}Oxbybzb

The above rotation angles φ , θ , ψ \varphi, \theta, \psif ,i ,ψ is a set of Euler angles, they completely determineS a S_{a}Sato S b S_{b}SbThe relative attitude between , where the rotation process can be represented by symbols:
S a ⟶ R z ( ψ ) ∘ ⟶ R y ( θ ) ∘ ⟶ R x ( φ ) S b S_{a} \stackrel{R_{z}(\ psi)}{\longrightarrow} \circ \stackrel{R_{y}(\theta)}{\longrightarrow} \circ \stackrel{R_{x}(\varphi)}{\longrightarrow} S_{b}SaRz( ψ )Ry( i )Rx( f )Sb

After three transformations, we get:

[ x b y b z b ] = R x ( φ ) R y ( θ ) R z ( ψ ) [ x a y a z a ] \left[\begin{array}{l} x_{b} \\ y_{b} \\ z_{b} \end{array}\right]=R_{x}(\varphi) R_{y}(\theta) R_{z}(\psi)\left[\begin{array}{l} x_{a} \\ y_{a} \\ z_{a} \end{array}\right] xbybzb=Rx( f ) Ry( i ) Rz( p )xayaza

So by S a S_{a}Sato S b S_{b}SbThe coordinate transformation matrix of is:

R = R x ( φ ) R y ( θ ) R z ( ψ ) R=R_{x}(\varphi) R_{y}(\theta) R_{z}(\psi)R=Rx( f ) Ry( i ) Rz( p )

In general, the coordinate transformation in three-dimensional space can be obtained by multiplying three primitive transformation matrices. When the definition of Euler angles is inconsistent with the above sequence and rotation direction, it can still be handled according to the above principles. When using Euler angles, we must explicitly indicate the order of the included angles. The three rotations are applied sequentially, and different orders produce different results. Therefore, before using Euler angles, a clear definition must be made.

Rotation order: In classical mechanics, Euler angles are often set in yxz order; according to the axis name of the second rotation axis, it is called x order for short. There is also an order, the xyz order, which is commonly used in aerospace engineering .

Any orientation can be achieved by composing three element rotations starting from a known standard orientation. Equivalently, any rotation matrix R can be decomposed into the product of three element rotation matrices. For example:
R = R x ( α ) R y ( β ) R z ( γ ) {\displaystyle R=R_x(\alpha)R_y(\beta)R_z(\gamma)}R=Rxa Ryb Rz( γ )
or
R = R x ( φ ) R y ( θ ) R z ( ψ ) {\displaystyle R=R_x (\varphi )R_y (\theta )R_z (\psi )}R=Rx( f ) Ry( i ) Rz( ψ )

The size range of roll angle is − π — π -\pi—\piπ π . aroundX \mathrm{X}X- axis rotationφ \varphiAfter φ , you can use the rotation matrixR x ( φ ) R_{x}(\varphi)Rx( φ ) is represented by the following formula:

R x ( φ ) = [ 1 0 0 0 cos ⁡ φ sin ⁡ φ 0 − sin ⁡ φ cos ⁡ φ ] \boldsymbol{R}_{x}(\varphi)=\left[\begin{array}{ccc } 1 & 0 & 0 \\ 0 & \cos \varphi & \sin \varphi \\ 0 & -\sin \varphi & \cos \varphi \end{array}\right]Rx( f )=1000cosPhisinf0sinPhicosf

The size of the pitch angle is − π / 2 — π / 2 -\pi / 2—\pi / 2π / 2 — between π / 2 . aroundY \mathrm{Y}Y axis rotationθ \thetaAfter θ , you can useR y ( θ ) \boldsymbol{R}_{\mathrm{y}}(\theta )Ry( θ ) to represent:

R y ( θ ) = [ cos ⁡ θ 0 − sin ⁡ θ 0 1 0 sin ⁡ θ 0 cos ⁡ θ ] \bold symbol{R}_{y}(\theta)=\left[\begin{array}{ccc } \cos \theta & 0 & -\sin \theta \\ 0 & 1 & 0 \\ \sin \theta & 0 & \cos \theta \end{array}\right]Ry( i )=cosi0sini010sini0cosi

The range of heading angle is − π — π -\pi—\piπ π . Rotate around the Z axisφ \varphiAfter φ , the rotation matrix R y ( ψ ) \boldsymbol{R}_{\mathrm{y}}(\psi)can be usedRy( ψ ) to represent:

R z ( ψ ) = [ cos ⁡ ψ sin ⁡ ψ 0 − sin ⁡ ψ cos ⁡ ψ 0 0 0 1 ] \bold symbol{R}_{z}(\psi )=\left[\begin{array}{ccc } \cos \psi & \sin \psi & 0 \\ -\sin \psi & \cos \psi & 0 \\ 0 & 0 & 1 \end{array}\right]Rz( p )=cospsinp0sinpcosp0001

Euler angles along different rotation directions will result in different rotation matrices, so when using Euler angles to represent, the rotation order should be given. The following figure shows the transformation of primitives:
insert image description here

Advantages and disadvantages of Euler angles:
(1) Composed of three angles, intuitive and easy to understand. Rotations greater than 180 degrees from one direction to the other are possible.
(2) It is difficult to interpolate two orientations. Simply interpolating the X, Y, Z angles gives less than ideal results.
(3) Implementing multiple rotations is complex and imprecise, and the final rotation matrix must be calculated, and then the Euler angles can be deduced accordingly.
(4) Deadlock problem .

Reference: Quaternions and Euler angles

3. Rotation matrix

Reference: Conversion between rotation matrices and Euler angles . Euler Angle Formulas gives the transformation matrix of different orders, and the following is the transformation matrix of xyz order. Among them, cx, cy, and cz respectively represent the cosine of the rotation angle around the xyz axis, and sx, sy, and sz respectively represent the sine of the rotation angle around the xyz axis. When the rotation sequence is heading angle-pitch angle-roll angle, the corresponding rotation matrix is ​​the result of multiplying the matrix in order:
R = R x ( φ ) R y ( θ ) R z ( ψ ) = [ cos ⁡ θ cos ⁡ ψ sin ⁡ ψ cos ⁡ θ − sin ⁡ θ − cos ⁡ ψ sin ⁡ ψ cos ⁡ ψ cos ⁡ φ + sin ⁡ ψ sin ⁡ θ sin ⁡ φ cos ⁡ θ sin ⁡ φ sin ⁡ ψ sin ⁡ φ + cos ⁡ ψ sin ⁡ θ cos ⁡ φ − cos ⁡ ψ sin ⁡ φ + sin ⁡ ψ sin ⁡ θ cos ⁡ φ cos ⁡ θ cos ⁡ φ ] = [ R 11 R 12 R 13 R 21 R 22 R 23 R 31 R 32 R 33 ] \begin{aligned} &\boldsymbol{R}=\boldsymbol{R}_{x}(\varphi ) \boldsymbol{R}_{y}(\theta) \boldsymbol{R}_{z}(\psi ) \\ &=\left[\begin{array}{ccc} \cos \theta \cos \psi & \sin \psi \cos \theta & -\sin \theta \\ -\cos \psi \sin \psi & \cos \psi \cos \varphi+\sin \psi \sin \theta \sin \varphi & \cos \ theta \sin \varphi \\ \sin \psi \sin \varphi+\cos \psi \sin \theta \cos \varphi & -\cos \psi \sin \varphi+\sin \psi \sin \theta \cos \varphi & \cos \theta \cos \varphi \end{array}\right] \\ &=\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] \end{aligned}R=Rx( f ) Ry( i ) Rz( p )=cosicospcospsinpsinpsinPhi+cospsinicosfsinpcosicospcosPhi+sinpsinisinPhicospsinPhi+sinpsinicosfsinicosisinPhicosicosf=R11R21R31R12R22R32R13R23R33
或者
R = [ c y c z − c y s z s y c z s x s y + c x s z c x c z − s x s y s z − c y s x − c x c z s y + s x s z c z s x + c x s y s z c x c y ] \mathrm{R}=\left[\begin{array}{ccc} c_y c_z & -c_y s_z & s_y \\ c_z s_x s_y+c_x s_z & c_x c_z-s_x s_y s_z & -c_y s_x \\ -c_x c_z s_y+s_x s_z & c_z s_x+c_x s_y s_z & c_x c_y \end{array}\right] R=cyczczsxsy+cxszcxczsy+sxszcyszcxczsxsyszczsx+cxsyszsycysxcxcy

The formula for transforming the rotation matrix to Euler angles:

{ ψ = tan ⁡ − 1 R 12 R 22 θ = − sin ⁡ − 1 R 13 ϕ = tan ⁡ − 1 R 23 R 33 \left\{\begin{array}{l} \psi=\tan ^{- 1} \frac{R_{12}}{R_{22}}\\\theta=-\sin^{-1}R_{13}\\varphi=\tan^{-1}\frac{R_{ 23}}{R_{33}}\end{array}\right.p=tan1R22R12i=sin1R13Phi=tan1R33R23

4. Quaternions

In 1843, the Irish mathematician WR Hamilton (WR Hamilton) invented the quaternion, which is of the form q ˙ = q 0 + q 1 i + q 2 j + q 3 k \dot{q}=q_{0}+q_{1 } i+q_{2} \boldsymbol{j}+q_{3} kq˙=q0+q1i+q2j+q3The hypercomplex number of k , at the same time, he also gave the addition and multiplication rules of quaternions and the inverse and modulus of quaternions, pointing out that quaternions can transform a given vector into Another vector. In quaternion expression,q 0 , q 1 , q 2 , q 3 q_{0}, q_{1}, q_{2}, q_{3}q0,q1,q2,q3is any real number, i , j , ki, j, ki,j,k is an imaginary unit, satisfyingi 2 = j 2 = k 2 = − 1 , jk = − kj = i , ki = − ik = j , ij = − ji = k ′ i^{2}=j^{2} =k^{2}=-1, jk=-kj=i, ki=-ik=j, ij=-ji=k^{\prime}i2=j2=k2=1,jk=kj=i,i _=i k=j,ij=ji=k 。 其中 q 0 + q 1 i + q 2 j + q 3 k q_{0}+q_{1} i+q_{2} j+q_{3} k q0+q1i+q2j+q3k is the algebraic form of quaternion,q 0 q_{0}q0For the quaternion q ˙ \dot{q}q˙The real part of q 1 i + q 2 j + q 3 k q_{1} \boldsymbol{i}+q_{2} \boldsymbol{j}+q_{3} \boldsymbol{k}q1i+q2j+q3k is the quaternionq ˙ \dot{q}q˙the imaginary part of .

Quaternions are currently used to express the attitude parameters of high-resolution optical remote sensing satellites on-orbit attitude measurement and control. There is no singularity, and the expression method is unique.

4.1 Equivalent transformation between quaternion and Euler angle and rotation matrix

The quaternion and rotation matrix transformation is:

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 ] \boldsymbol{R}=\left[\begin{array}{ccc} 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 \end{array}\right] R=2q02+2q1212q1q2+2q0q32q1q32q0q22q1q22q0q32q02+2q2212q2q3+2q0q12q1q3+2q0q22q2q32q0q12q02+2q321

The transformation from Euler angles to quaternions is:

{ q 0 = cos ⁡ ψ 2 cos ⁡ θ 2 cos ⁡ φ 2 + sin ⁡ ψ 2 sin ⁡ θ 2 sin ⁡ φ 2 q 1 = − cos ⁡ ψ 2 cos ⁡ θ 2 cos ⁡ φ 2 + sin ⁡ ψ 2 sin ⁡ θ 2 sin ⁡ φ 2 q 2 = − cos ⁡ ψ 2 cos ⁡ θ 2 cos ⁡ φ 2 − sin ⁡ ψ 2 sin ⁡ θ 2 sin ⁡ φ 2 q 3 = − cos ⁡ ψ 2 cos ⁡ θ 2 cos ⁡ φ 2 + sin ⁡ ψ 2 sin ⁡ θ 2 sin ⁡ φ 2 \left\{\begin{array}{l} q_{0}=\cos \frac{\psi}{2} \cos \frac{\ theta}{2} \cos \frac{\varphi}{2}+\sin \frac{\psi}{2} \sin \frac{\theta}{2} \sin \frac{\varphi}{2} \\ q_{1}=-\cos \frac{\psi}{2} \cos \frac{\theta}{2} \cos \frac{\varphi}{2}+\sin \frac{\psi} {2} \sin \frac{\theta}{2} \sin \frac{\varphi}{2} \\ q_{2}=-\cos \frac{\psi}{2} \cos \frac{\ theta}{2} \cos \frac{\varphi}{2}-\sin \frac{\psi}{2} \sin \frac{\theta}{2} \sin \frac{\varphi}{2} \\ q_{3}=-\cos \frac{\psi}{2} \cos \frac{\theta}{2} \cos \frac{\varphi}{2}+\sin \frac{\psi} {2} \sin \frac{\theta}{2} \sin\frac{\varphi}{2} \end{array}\right.q0=cos2pcos2icos2f+sin2psin2isin2fq1=cos2pcos2icos2f+sin2psin2isin2fq2=cos2pcos2icos2fsin2psin2isin2fq3=cos2pcos2icos2f+sin2psin2isin2f

Quaternion conversion to Euler angles:

{ ψ = tan ⁡ − 1 2 q 1 q 2 − 2 q 0 q 3 2 q 0 2 + 2 q 1 2 − 1 θ = − sin ⁡ − 1 ( 2 q 1 q 3 + 2 q 0 q 2 ) ϕ = tan ⁡ − 1 2 q 2 q 3 − 2 q 0 q 1 2 q 0 2 + 2 q 3 2 − 1 \left\{\begin{array}{l} \psi=\tan ^{-1}\ frac {2 q_{1} q_{2}-2 q_{0} q_{3}}{2 q_{0}^{2}+2 q_{1}^{2}-1} \\\theta= -\sin ^{-1}\left(2 q_{1} q_{3}+2 q_{0} q_{2}\right) \\\varphi=\tan^{-1} \frac{2 q_ {2} q_{3}-2 q_{0} q_{1}}{2 q_{0}^{2}+2 q_{3}^{2}-1} \end{array}\right.p=tan12q02+2q1212q1q22q0q3i=sin1(2q1q3+2q0q2)Phi=tan12q02+2q3212q2q32q0q1

Quaternions consist of four numbers, however these numbers do not represent angles or axes, and there is usually no need to access them directly. Unless you're particularly interested in diving into quaternion math, all you need to know is that quaternions represent rotations in three-dimensional space, and you generally don't need to know or modify the x, y, and z properties.

Pros: There is no gimbal lock problem with quad rotation.
Advantages: small storage space, high computational efficiency.
Weaknesses: A single quaternion cannot represent rotations greater than 180 degrees in any direction.
Weaknesses: The numeric representation of quaternions is not intuitive.

Reference: [Unity Programming] Quaternion and Euler Angle

4.2 Test Matlab code

Verification Test: 3D Rotation Converter

clc; clear; close all

% Axis rotation sequence for the Euler angles, specified as one of these string scalars:
% "ZYX" (default) – The order of rotation angles is z-axis, y-axis, x-axis.
% "ZYZ" – The order of rotation angles is z-axis, y-axis, z-axis.
% "XYZ" – The order of rotation angles is x-axis, y-axis, z-axis.

% 三个欧拉角
eul = deg2rad([30 60 90]);

% 指定旋转顺序为XYZ
rotm = eul2rotm(eul,'XYZ')  %欧拉角转旋转矩阵
quat = eul2quat(eul,'XYZ')  %欧拉角转四元数

eul = rad2deg(rotm2eul(rotm,'XYZ'))     %旋转矩阵转欧拉角
quat = rotm2quat(rotm)                  %旋转矩阵转四元数

eul = rad2deg(quat2eul(quat,'XYZ'))     %四元数转欧拉角
rotm = quat2rotm(quat)                  %四元数转旋转矩阵

rotation matrix

-2.22044604925031e-16	-0.500000000000000	0.866025403784439
0.866025403784439	-0.433012701892220	-0.250000000000000
0.500000000000000	0.750000000000000	0.433012701892219

Quaternion

0.500000000000000	0.500000000000000	0.183012701892219	0.683012701892219

5. Summary

This paper describes the relationship between quaternion and rotation matrix, Euler angle and quaternion, quaternion and Euler angle. Euler angles, rotation matrices, and quaternions, the three methods of representing poses, each have their own advantages and disadvantages. In some cases, the Euler angle will encounter the gimbal lock problem, that is, the information of one degree of freedom will be lost; there are nine values ​​in the rotation matrix, and only three degrees of freedom are required for a three-dimensional rotation, which will cause a bit of calculation. big. The quaternion does not have the unique singularity of the Euler angle and the rotation matrix, and can well represent the attitude of the moving object, so the quaternion is widely used to represent the attitude.

Guess you like

Origin blog.csdn.net/wokaowokaowokao12345/article/details/127240800