# Converting quaternions to Euler angles

There are several different forms for representing orientations, and each has it's benefits and drawbacks that make it appropriate for some situations but not others. We use quaternions to represent orientations for their convenient mathematical properties, but for interpretation Euler angles are often used. Euler angles can be intuitive when the axes of rotation have physical significance, and when there is rotation about only one or at most two axes. In orientations where there is a substantial component in all three angles the interdependence between the rotations can be confusing. This is part of the reason there is no single Euler angle representation, but instead 9 different choices depending on which order of rotations makes the most sense for a particular application.

The process for deriving a conversion between a quaternion and an Euler angle sequence is similar for the different sequences. It is typically done by expressing the rotation matrix separately in terms of the quaternion components and also in terms of the Euler angles, and then selecting favorable elements of that matrix and solving for the Euler angles in terms of the quaternion components. For an example of this, see: http://en.wikipedia.org/wiki/Conversion_between_quaternions_and_Euler_angles

As an example, the quaternions produced by APDM's sensors express the rotation from the sensor frame to the Earth frame in which the XYZ axes are aligned respectively with magnetic North, West, and Up. This is the same body to lab representation as the quaternion in the Wikipedia article (w,x,y,z order). The Euler angles are then given by the following equations:

Φ = atan2(2(q0q1+q2q3),1-2(q12+q22))

θ  = asin(2(q0q2-q3q1))

ψ  = atan2(2(q0q3+q1q2),1-2(q22+q32))