![]() | ||
Spatial rotations in three dimensions can be parametrized using both Euler angles and unit quaternions. This article explains how to convert between the two representations. Actually this simple use of "quaternions" was first presented by Euler some seventy years earlier than Hamilton to solve the problem of magic squares. For this reason the dynamics community commonly refers to quaternions in this application as "Euler parameters".
Contents
Definition
For the rest of this article, the JPL quaternion convention shall be used. A unit quaternion can be described as:
We can associate a quaternion with a rotation around an axis by the following expression
where α is a simple rotation angle (the value in radians of the angle of rotation) and cos(βx), cos(βy) and cos(βz) are the "direction cosines" locating the axis of rotation (Euler's Theorem).
Tait–Bryan angles
Similarly for Euler angles, we use the Tait Bryan angles (in terms of flight dynamics):
where the X-axis points forward, Y-axis to the right and Z-axis downward with angles defined for clockwise/lefthand rotation. In the conversion example above the rotation occurs in the order yaw, pitch, roll (about body-fixed axes).
Rotation matrices
The orthogonal matrix (post-multiplying a column vector) corresponding to a clockwise/left-handed (looking along positive axis to origin) rotation by the unit quaternion
or equivalently, by the homogeneous expression:
If
The direction cosine matrix (from the rotated Body XYZ coordinates to the original Lab xyz coordinates for a clockwise/lefthand rotation) corresponding to a post-multiply Body 3-2-1 sequence with Euler angles (ψ, θ, φ) is given by:
Euler Angles to Quaternion Conversion
By combining the quaternion representations of the Euler rotations we get for the Body 3-2-1 sequence, where the airplane first does yaw (Body-Z) turn during taxiing onto the runway, then pitches (Body-Y) during take-off, and finally rolls (Body-X) in the air. The resulting orientation of Body 3-2-1 sequence (around the capitalized axis in the illustration of Tait–Bryan angles) is equivalent to that of lab 1-2-3 sequence (around the lower-cased axis), where the airplane is rolled first (lab-x axis), and then nosed up around the horizontal lab-y axis, and finally rotated around the vertical lab-z axis (lB = lab2Body):
Other rotation sequences use different conventions.
Source Code
Below code in C/C++ language illustrates above conversion that also avoids recalculating common expressions:
Quaternion to Euler Angles Conversion
The Euler angles can be obtained from the quaternions via the relations:
Note, however, that the arctan and arcsin functions implemented in computer languages only produce results between −π/2 and π/2, and for three rotations between −π/2 and π/2 one does not obtain all possible orientations. To generate all the orientations one needs to replace the arctan functions in computer code by atan2:
Source Code
Below code in C/C++ language illustrates above conversion that also avoids recalculating common expressions:
Singularities
One must be aware of singularities in the Euler angle parametrization when the pitch approaches ±90° (north/south pole). These cases must be handled specially. The common name for this situation is gimbal lock.
Code to handle the singularities is derived on this site: www.euclideanspace.com
Vector Rotation
Note that the canonical way to rotate a three-dimensional vector
where
where
Proof
The general rule for quaternion multiplication involving scalar and vector parts is given by
Using this relation one finds for
and upon substitution for the triple product
where anti-commutivity of cross product and
one obtains
which upon defining