Orientation representation
Orientation in three-dimensional space can be represented using several mathematical models, each with its own strengths and applications. The four most common representations are Euler angles, quaternions, Direction Cosine Matrices (DCMs), and axis-angle representations.
Euler angle
It describes orientation using three sequential rotations about different axes, providing an intuitive understanding but suffering from singularities like gimbal lock. From Figure 1, the fixed coordinate system represented as x, y, z and the rotated coordinate system are X, Y, Z. There is two kinds of possible rotatino method which is intrinsic and extrinsic.
- Intrinsic rotations: Rotations relative to an object’s local, moving coordinate system. Each subsequent rotation is applied relative to the object’s new, rotated position
- Extrinsic rotations: Rotations relative to a fixed global coordinate system. Each rotation is applied relative to the same, fixed global axes.
Quaternion
It composed of four components: one real part and three imaginary parts:, offer a compact and efficient way to represent rotations without singularities, making them ideal for smooth interpolation and computer graphics. Example equation: q = w + xi+ yj + zk, where w is the real (scalar) part, x,y,z are the imaginary (vector) component, i,j,k are the fundamental quaternion units, analogous to complex numbers.
Direction Cosine Matrix (DCM)
It is a 3x3 matrix that describes the orientation of one coordinate frame relative to another through rotation. Rotation sequence represented how the object rotated in 3D world. Based on the rotation sequence, DCM can be represent extrinsic rotation (Fixed Reference Frame) and intrinsic rotation (Body Reference Frame). Right multiplication of rotation sequence refers to extrinsic rotation, while Left multiplication refers to intrinsic rotation. It is an orthogonal matrix, meaning its rows and columns are unit vectors and mutually perpendicular. DCM does not suffer from gimbal lock, which is the loss of one degree of freedom during certain orientations in Euler angles. However, computation cost of DCM more expensive than Euler angles and Quaternion when combining multiple rotations or normalizing the matrix.
Axis-angle
It defines orientation by specifying two components which is unit vector and angle. Unit vector represents the direction around which the rotation occurs. Rotation angle that represents the magnitude of the rotation around the axis. The axis-angle representation can be written as v (unit vector)and θ (Rotation angle). Axis-angle rotation follow right-hand rule.
Euler angle to DCM
We need to define the order of rotations about the axes call rotation sequence. As each axis rotation can be presented as single rotation matrix, we need to multiply three rotation matrix to represent all kind of rotation combination in 3D world. There are 12 rotation sequences in total, included 6 Tait–Bryan angles (3 axis rotation) and 6 Proper Euler angles (2 axis rotation). Figure 3 shows how to obtain DCM from Euler angles in xyz order.
Euler angle to Quaternion
Since Quaternion include real and imaginary parts, we can easily express Quaternion with the combination of rotations around the X-axis, Y-axis, and Z-axis, where Beta x, y, z are roll, pitch, yaw respectively. The quaternion for a rotation in 3D space can be represented as the product of individual quaternions for each axis of rotation. Also, the conversion have to follow rotation sequence.
Euler angle to Axis angle
There is currently no direct way to convert Euler angle to Axis angle. We can first convert the Euler angle to DCM according to the rotation sequence, and then convert the DCM to Axis angle.
DCM to Euler angle
According to Figure 3, we know that DCM elements are combined from Euler angles in different rotation sequence. Therefore, we can easily get Euler angles from DCM. For example, if your roll, pitch, yaw refer to the X, Y, Z axis respectively, and follow the XZY rotation sequence, then according to Figure 6, alpha would be roll, beta would be yaw, and gamma would be pitch.
DCM to Quaternion
The scalar and vector values of the quaternion are calculated from the diagonal elements of the DCM. Then, the maximum value is found among these 4 quaternion values. The remaining quaternion element values are calculated according to Figure 7.
DCM to Axis angle
The axis angle consists of the rotation angle and the axis. The rotation angle θ can be found by the trace of the DCM, which is the sum of the diagonal elements of the matrix. The components of the rotation axis come from the off-diagonal elements of the DCM. Figure 8 shows the equation for converting DCM to axis angle.
Quaternion to DCM
Before converting a quaternion to DCM, we must ensure that it is a normalized quaternion. The equation for converting a quaternion to DCM is shown in Figure 9.
Quaternion to Euler angle
A simpler way to convert Quaternion to Euler angle is to do it in two steps, first convert the Quaternion to DCM and then convert to Euler angle.
Quaternion to Axis angle
Since the Axis-angle consists of a rotation angle and an axis, we need to calculate both from the Quaternion. The rotation angle is associated with the scalar portion of the quaternion, while the rotation axis is the vector portion. The norm of the vector portion represents the direction of rotation in 3D space. The factor of 2 comes from the fact that the quaternion represents half of the rotation angle. Therefore, multiplying by 2 gives the correct total rotation angle. After normalizing the rotation axis, multiplying by the rotation angle gives the axis-angle representation.
Axis angle to DCM
According to Rodrigues’ rotation formula, an efficient method for calculating the rotation matrix from the axis and angle is given in Figure 11. [u]× refers to skew-symmetric matrix consisting of Axis angle components, also known as cross product matrix of u, while u ⊗ u refers to outer product. θ is the rotation angle and u is the rotation axis.
Axis angle to Quaternion
The meaning of Axis angle is to rotate a vector by a certain angle (scalar), which is consistent with the physical meaning of quaternion, so the conversion between Axis angle and quaternion is very simple. The reason why θ is halved is because Quaternion represents half a rotation, so the sine and cosine functions are applied to θ/2.
Axis angle to Euler angle
There is currently no direct way to convert Axis angle to Euler angle. We can first convert the Axis angle to Quaternion, and then convert the Quaternion to Euler angle according to the rotation sequence.
Conclusion
In this article, we discussed what Euler angle, Quaternion, DCM, and Axis angle are. Also, we discussed how to convert from one to the other. Each of these models has advantages, and the choice of representation depends on the application. Euler angles are intuitive, Quaternion are efficient for calculation and interpolation, DCM provide detailed accuracy for applications such as aerospace, and Axis angle representation is direct and simple. Everyone is welcome to share your thoughts or suggestions.
Get Teddy Lai’s stories in your inbox
Join Medium for free to get updates from this writer.
Github repository: https://github.com/laitathei/mpu9250_ahrs







