## Equations

heading = atan2(2*qy*qw-2*qx*qz , 1 - 2*qy^{2} - 2*qz^{2})

attitude = asin(2*qx*qy + 2*qz*qw)

bank = atan2(2*qx*qw-2*qy*qz , 1 - 2*qx^{2} - 2*qz^{2})

except when qx*qy + qz*qw = 0.5 (north pole)

which gives:

heading = 2 * atan2(x,w)

bank = 0

and when qx*qy + qz*qw = -0.5 (south pole)

which gives:

heading = -2 * atan2(x,w)

bank = 0

## Issues

- It is better to use atan2 function than atan function as described here. Note the warning on this page about the order of operands.
- For issues concerning asin and atan see here.
- Most trig functions (except openGL) use radians not degrees.

The trig functions are many to one, therefore the inverse trig functions have
many possible results. We usually assume that:

acos returns the angle between 0 and π radians (equivalent to 0 and 180 degrees)

asin returns the angle between -π/2 and π/2 radians (equivalent to -90 and 90 degrees)

atan returns the angle between -π/2 and π/2 radians (equivalent to -90 and 90 degrees)

atan2 returns the angle between -π and π radians (equivalent to -180 and 180 degrees)

This is what the java Math functions return for instance. I think this makes sense in the context of finding euler angles because we would usually want to rotate the shortest angle to rotate.

If you have a different result from that shown on this page it may be that you are using different standards, I have tried to keep the standards consistent across this site and I have tried to define the standards that I am using here. One of these standards is that the order that the euler rotations are applied is 'NASA standard aeroplane' it uses a slightly different coordinate definition from VRML (z and y axis swapped). Also when working with aeroplanes we often work in terms of the position of external objects relative to the aircraft (i.e. the inverse of its position transform as explained here). therefore to get the expression normally used with NASA aeroplane we invert all inputs (change sign of every term with odd number of sine terms) invert output (conjugate quaternion) swap z and y for inputs (swap z and y columns) swap z and y for outputs (swap z and y rows). In the case of aircraft it can make sense to work in terms of the local frame of reference of the aircraft looking out, I have a version of this page that does that here, but be careful as this will no longer be compatible with the rest of this site.

However if you have checked these things and you still have a discrepancy then I have probably made an error so please let me know here.

If you are working with different Euler Angles see the 'Alternative Euler Angle Sequences' section below.

## Code

Java code to do conversion:

This depends on what conventions are used for the Euler Angles. The following assumes the standards here