Conversion between quaternions and Euler angles
From Wikipedia, the free encyclopedia
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 |
[edit] Definition
A unit quaternion can be described as:
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).
[edit] Rotation matrices
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
[edit] Conversion
By comparing the terms in the two matrices, we get
For Euler angles we get:
[edit] Relationship with Tait-Bryan angles
Similarly for Euler angles, we use the Tait-Bryan angles (in terms of flight dynamics):
- Roll - φ: rotation about the X-axis
- Pitch - θ: rotation about the Y-axis
- Yaw - ψ: rotation about the Z-axis
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.
[edit] 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. The common name for this situation is gimbal lock.
Code to handle the singularities is derived on this site: www.euclideanspace.com