# Maths - Conversion Euler to Axis-Angle

## Definition of terms:

Start from quaternion to axis angle as shown here:

angle = 2 * acos(qw)
x = qx / sqrt(1-qw*qw)
y = qy / sqrt(1-qw*qw)
z = qz / sqrt(1-qw*qw)

Substitute from Euler to Quaternion as shown here:

qw = c1c2c3 + s1s2s3
qx = c1c2s3 - s1s2c3
qy = c1s2c3 + s1c2s3
qz = s1c2c3 - c1s2s3

where:

• c1 = cos(heading / 2)
• c2 = cos(attitude / 2)
• c3 = cos(bank / 2)
• s1 = sin(heading / 2)
• s2 = sin(attitude / 2)
• s3 = sin(bank / 2)

So, removing common factors which means that x,y,z is no longer normalised

angle = 2 * acos(c1c2c3 + s1s2s3)
x = c1c2s3 - s1s2c3
y = c1s2c3 + s1c2s3
z = s1c2c3 - c1s2s3

to normalise divide x,y and z by:

x2 + y2 + z2 = (c1c2s3 - s1s2c3)2+(c1s2c3 + s1c2s3)2+(s1c2c3 - c1s2s3)2

## Example

 we take the 90 degree rotation from this: to this: As shown here the axis angle for this rotation is:

bank = 90 degrees
attitude = 0 degrees

• c1 = cos(heading / 2) = 1
• c2 = cos(attitude / 2) = 1
• c3 = cos(bank / 2) = 0.7071
• s1 = sin(heading / 2) = 0
• s2 = sin(attitude / 2) = 0
• s3 = sin(bank / 2) = 0.7071

angle = 2 * acos(c1c2c3 + s1s2s3) = 2 * acos(0.7071) = 90 degrees
x = c1c2s3 - s1s2c3 = 0.7071
y = c1s2c3 + s1c2s3 = 0
z = s1c2c3 - c1s2s3 = 0

So the axis is: (0.7071,0,0)

This can be normalised to: (1,0,0)

So this gives the correct result, see here, but we have to be very careful about the following issues:

• Most maths libraries use radians instead of degrees (apart from OpenGL).