Is there an existing algorithm for converting a quaternion representation of a rotation to an Euler angle representation? The rotation order for the Euler representation is
I solve it this way:
step 1: Make sure which convention for Euler rotation you want, say, zyx.
step 2: Compute the analytical rotation matrix for the rotation. For example, if you want R(zyx),
**R***zyx* = **R***x*( phi ) * **R***y*( theta ) * **R***z*( psi ), where the elements become
R11 = cos(theta)*cos(psi)
R12 = -cos(theta)*sin(psi)
R13 = sin(theta)
R21 = sin(psi)*cos(phi) + sin(theta)*cos(psi)*sin(phi)
R22 = cos(psi)*cos(phi) - sin(theta)*sin(psi)*sin(phi)
R23 = -cos(theta)*sin(phi)
R31 = sin(psi)*sin(phi) - sin(theta)*cos(psi)*cos(phi)
R32 = cos(psi)sin(phi) + sin(theta)*sin(psi)*cos(phi)
R33 = cos(theta)*cos(phi)
step 3: By inspection, you can find the sin or tan for the three angles using the elements above. In this example,
tan(phi) = -R23/R33
sin(theta) = -R13
tan(psi) = -R12/R11
step 4: Compute the rotation matrix from your quaternion (see wikipedia), for the elements you need to compute the angles as in 3) above.
Other conventions can be computed using the same procedure.
Here is a paper I wrote on converting a quaternion to Euler angles.
Link 1
I have also put a number of documents at this location discussing various aspects of quaternions, Euler angles and rotation matrices (DCM).
Link 2