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".
We can associate a quaternion to 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).
Rotation matrices
Euler angles - The xyz (fixed) system is shown in blue, the XYZ (rotated) system is shown in red. The line of nodes, labelled N, is shown in green.
The orthogonal matrix corresponding to a rotation by the unit quaternion q is given by
The orthogonal matrix corresponding to a rotation with Euler angles , with x-y-z convention, is given by
where the X-axis points forward, Y-axis to the right and Z-axis downward and in the example to follow the rotation occurs in the order yaw, pitch, roll (about body-fixed axes).
Nevertheless, it is not easy to find a matrix expression with Tait-Bryan angles because its final expression depends on how the rotations are applied.
Conversion
By comparing the terms in the two matrices, we get
For Euler angles we get:
Singularities
One must be aware of singularities in the Euler angle parametrization when the pitch approaches (north/south pole). These cases must be handled specially.