logo back up home forward   further reading more topics »

Maths - Quaternion to Euler - Sample Orientations

Sample Rotations

In order to try to explain things I thought it might help to work out a simple case where rotations are only allowed in mutiples of 90 degrees. This should make it easier to illustrate the orientation with a simple aeroplane figure, we can rotate this either about the x,y or z axis as shown here:

When we combine these rotations about the x,y and z axies in 90 degree multiples there are 24 possible orientations as shown below:

In the following table we will need to know what quadrant the results are in, so I have taken some sample results from Math.atan2 (using java Math library).

atan2(0.0,0.0)=0.0 (although Math.atan2 returns 0 this is abitary and if both x and y is zero we need to find some other way to get to value
atan2(0.0,1.0)=0.0
atan2(1.0,1.0)=0.7853981633974483
atan2(1.0,0.0)=1.5707963267948966
atan2(1.0,-1.0)=2.356194490192345
atan2(0.0,-1.0)=3.141592653589793
atan2(-1.0,-1.0)=-2.356194490192345
atan2(-1.0,0.0)=-1.5707963267948966
atan2(-1.0,1.0)=-0.7853981633974483

heading applied first giving 4 possible orientations:

rightUp

reference orientation:

w = 1
x = 0
y = 0
z = 0

heading = atan2(2*qy*qw-2*qx*qz , 1 - 2*qy2 - 2*qz2)
attitude = asin(2*qx*qy + 2*qz*qw)
bank = atan2(2*qx*qw-2*qy*qz , 1 - 2*qx2 - 2*qz2)

heading = atan2(0, 1)
attitude = asin(0)
bank = atan2(0 , 1)

heading = 0
attitude = 0
bank = 0

backUp

rotate by 90 degrees about y axis:

w = 0.7071
x = 0
y = 0.7071
z = 0

heading = atan2(2*qy*qw-2*qx*qz , 1 - 2*qy2 - 2*qz2)
attitude = asin(2*qx*qy + 2*qz*qw)
bank = atan2(2*qx*qw-2*qy*qz , 1 - 2*qx2 - 2*qz2)

heading = atan2(1 , 0)
attitude = asin(0)
bank = atan2(0 , 1)

heading = 90 degrees
attitude = 0
bank = 0

leftUp

rotate by 180 degrees about y axis:

w = 0
x = 0
y = 1
z = 0

heading = atan2(2*qy*qw-2*qx*qz , 1 - 2*qy2 - 2*qz2)
attitude = asin(2*qx*qy + 2*qz*qw)
bank = atan2(2*qx*qw-2*qy*qz , 1 - 2*qx2 - 2*qz2)

heading = atan2(0 , -1)
attitude = asin(0)
bank = atan2(0 , 1)

heading = 180 degrees
attitude = 0
bank = 0

forwardUp

rotate by 270 degrees about y axis:

w = 0.7071
x = 0
y = -0.7071
z = 0

heading = atan2(2*qy*qw-2*qx*qz , 1 - 2*qy2 - 2*qz2)
attitude = asin(2*qx*qy + 2*qz*qw)
bank = atan2(2*qx*qw-2*qy*qz , 1 - 2*qx2 - 2*qz2)

heading = atan2(-1 , 0)
attitude = asin(0)
bank = atan2(0 , 1)

heading = -90 degrees
attitude = 0
bank = 0

Then apply attitude +90 degrees for each of the above: (note: that if we went on to apply bank to these it would just rotate between these values, the straight up and streight down orientations are known as singularities because they can be fully defined without using the bank value) post multiply above by 0.7071 + k 0.7071 to give:

upLeft

w = 0.7071
x = 0
y = 0
z = 0.7071

heading = atan2(2*qy*qw-2*qx*qz , 1 - 2*qy2 - 2*qz2)
attitude = asin(2*qx*qy + 2*qz*qw)
bank = atan2(2*qx*qw-2*qy*qz , 1 - 2*qx2 - 2*qz2)

heading = atan2(0 , 0)
attitude = asin(1)
bank = atan2(0 , 0)

this is at singularity (straight up) atan2(0,0) is not useful, so instead, use:

heading = 2 * atan2(x,w) =0
bank = 0

heading = 0
attitude = 90 degrees
bank = 0

upForward

w = 0.5
x = 0.5
y = 0.5
z = 0.5

heading = atan2(2*qy*qw-2*qx*qz , 1 - 2*qy2 - 2*qz2)
attitude = asin(2*qx*qy + 2*qz*qw)
bank = atan2(2*qx*qw-2*qy*qz , 1 - 2*qx2 - 2*qz2)

heading = atan2(0 , 0)
attitude = asin(1)
bank = atan2(0 , 0)

this is at singularity (straight up) atan2(0,0) is not useful, so instead, use:

heading = 2 * atan2(x,w)
= 2 * 45=90degrees
bank = 0

heading = 90 degrees
attitude = 90 degrees
bank = 0

upRight

w = 0
x = 0.7071
y = 0.7071
z = 0

heading = atan2(2*qy*qw-2*qx*qz , 1 - 2*qy2 - 2*qz2)
attitude = asin(2*qx*qy + 2*qz*qw)
bank = atan2(2*qx*qw-2*qy*qz , 1 - 2*qx2 - 2*qz2)

heading = atan2(0 , 0)
attitude = asin(1)
bank = atan2(0 , 0)

this is at singularity (straight up) atan2(0,0) is not useful, so instead, use:

heading = 2 * atan2(x,w)
= 2 * atan2(0.7071,0) = 2*90degrees
bank = 0

heading = 180 degrees
attitude = 90 degrees
bank = 0

upBack

w = 0.5
x = -0.5
y = -0.5
z = 0.5

heading = atan2(2*qy*qw-2*qx*qz , 1 - 2*qy2 - 2*qz2)
attitude = asin(2*qx*qy + 2*qz*qw)
bank = atan2(2*qx*qw-2*qy*qz , 1 - 2*qx2 - 2*qz2)

heading = atan2(0 , 0)
attitude = asin(1)
bank = atan2(0 ,0)

this is at singularity (straight up) atan2(0,0) is not useful, so instead, use:

heading = 2 * atan2(x,w)
= 2 * -45degrees
bank = 0

heading = -90 degrees
attitude = 90 degrees
bank = 0

Or instead apply attitude -90 degrees (also a singularity): post multiply top row by 0.7071 - k 0.7071 to give:

downRight

w = 0.7071
x = 0
y = 0
z = -0.7071

heading = atan2(2*qy*qw-2*qx*qz , 1 - 2*qy2 - 2*qz2)
attitude = asin(2*qx*qy + 2*qz*qw)
bank = atan2(2*qx*qw-2*qy*qz , 1 - 2*qx2 - 2*qz2)

heading = atan2(0 ,0)
attitude = asin(-1)
bank = atan2(0 , 0)

heading = 0
attitude = -90 degrees
bank = 0

downBack

w = 0.5
x = -0.5
y = 0.5
z = -0.5

heading = atan2(2*qy*qw-2*qx*qz , 1 - 2*qy2 - 2*qz2)
attitude = asin(2*qx*qy + 2*qz*qw)
bank = atan2(2*qx*qw-2*qy*qz , 1 - 2*qx2 - 2*qz2)

heading = atan2(0 ,0)
attitude = asin(-1)
bank = atan2(0 ,0)

this is at singularity (straight down) atan2(0,0) is not useful, so instead, use:

heading = 2 * atan2(x,w)
= 2 * 45=90degrees
bank = 0

heading = 90 degrees
attitude = -90 degrees
bank = 0

downLeft

w = 0
x = -0.7071
y = 0.7071
z = 0

heading = atan2(2*qy*qw-2*qx*qz , 1 - 2*qy2 - 2*qz2)
attitude = asin(2*qx*qy + 2*qz*qw)
bank = atan2(2*qx*qw-2*qy*qz , 1 - 2*qx2 - 2*qz2)

heading = atan2(0 , 0)
attitude = asin(-1)
bank = atan2(0 , 0)

heading = 180 degrees
attitude = -90 degrees
bank = 0

downForward

w = 0.5
x = 0.5
y = -0.5
z = -0.5

heading = atan2(2*qy*qw-2*qx*qz , 1 - 2*qy2 - 2*qz2)
attitude = asin(2*qx*qy + 2*qz*qw)
bank = atan2(2*qx*qw-2*qy*qz , 1 - 2*qx2 - 2*qz2)

heading = atan2(0 ,0)
attitude = asin(-1)
bank = atan2(0 , 0)

heading = -90 degrees
attitude = -90 degrees
bank = 0

Normally we dont go beond attitude + or - 90 degrees because thes are singularities, instead apply bank +90 degrees: post multiply top row by 0.7071 + i 0.7071 to give:

rightForward

w = 0.7071
x = 0.7071
y = 0
z = 0

heading = atan2(2*qy*qw-2*qx*qz , 1 - 2*qy2 - 2*qz2)
attitude = asin(2*qx*qy + 2*qz*qw)
bank = atan2(2*qx*qw-2*qy*qz , 1 - 2*qx2 - 2*qz2)

heading = atan2(0 , 1)
attitude = asin(0)
bank = atan2(1 , 0)

heading = 0
attitude = 0
bank = 90 degrees

backRight

w = 0.5
x = 0.5
y = 0.5
z = -0.5

heading = atan2(2*qy*qw-2*qx*qz , 1 - 2*qy2 - 2*qz2)
attitude = asin(2*qx*qy + 2*qz*qw)
bank = atan2(2*qx*qw-2*qy*qz , 1 - 2*qx2 - 2*qz2)

heading = atan2(1 , 0)
attitude = asin(0)
bank = atan2(1 , 0)

heading = 90 degrees
attitude = 0
bank = 90 degrees

leftBack

w = 0
x = 0
y = 0.7071
z = -0.7071

heading = atan2(2*qy*qw-2*qx*qz , 1 - 2*qy2 - 2*qz2)
attitude = asin(2*qx*qy + 2*qz*qw)
bank = atan2(2*qx*qw-2*qy*qz , 1 - 2*qx2 - 2*qz2)

heading = atan2(0 , -1)
attitude = asin(0)
bank = atan2(1 , 0)

heading = 180 degrees
attitude = 0
bank = 90 degrees

forwardLeft

w = 0.5
x = 0.5
y = -0.5
z = 0.5

heading = atan2(2*qy*qw-2*qx*qz , 1 - 2*qy2 - 2*qz2)
attitude = asin(2*qx*qy + 2*qz*qw)
bank = atan2(2*qx*qw-2*qy*qz , 1 - 2*qx2 - 2*qz2)

heading = atan2(-1 , 0)
attitude = asin(0)
bank = atan2(1 , 0)

heading = -90 degrees
attitude = 0
bank = 90 degrees

Apply bank +180 degrees: post multiply top row by i to give:

rightDown

w = 0
x = 1
y = 0
z = 0

heading = atan2(2*qy*qw-2*qx*qz , 1 - 2*qy2 - 2*qz2)
attitude = asin(2*qx*qy + 2*qz*qw)
bank = atan2(2*qx*qw-2*qy*qz , 1 - 2*qx2 - 2*qz2)

heading = atan2(0 , 1)
attitude = asin(0)
bank = atan2(0 , -1)

heading = 0
attitude = 0
bank = 180 degrees

backDown

w = 0
x = 0.7071
y = 0
z = -0.7071

heading = atan2(2*qy*qw-2*qx*qz , 1 - 2*qy2 - 2*qz2)
attitude = asin(2*qx*qy + 2*qz*qw)
bank = atan2(2*qx*qw-2*qy*qz , 1 - 2*qx2 - 2*qz2)

heading = atan2(1 , 0)
attitude = asin(0)
bank = atan2(0 , -1)

heading = 90 degrees
attitude = 0
bank = 180 degrees

leftDown

w = 0
x = 0
y = 0
z = 1

heading = atan2(2*qy*qw-2*qx*qz , 1 - 2*qy2 - 2*qz2)
attitude = asin(2*qx*qy + 2*qz*qw)
bank = atan2(2*qx*qw-2*qy*qz , 1 - 2*qx2 - 2*qz2)

heading = atan2(0 , -1)
attitude = asin(0)
bank = atan2(0 , -1)

heading = 180 degrees
attitude = 0
bank = 180 degrees

forwardDown

w = 0
x = 0.7071
y = 0
z = 0.7071

heading = atan2(2*qy*qw-2*qx*qz , 1 - 2*qy2 - 2*qz2)
attitude = asin(2*qx*qy + 2*qz*qw)
bank = atan2(2*qx*qw-2*qy*qz , 1 - 2*qx2 - 2*qz2)

heading = atan2(-1 , 0)
attitude = asin(0)
bank = atan2(0 , -1)

heading = -90 degrees
attitude = 0
bank = 180 degrees

Apply bank -90 degrees: post multiply top row by 0.7071 - i 0.7071 to give:

rightBack

w = 0.7071
x = -0.7071
y = 0
z = 0

heading = atan2(2*qy*qw-2*qx*qz , 1 - 2*qy2 - 2*qz2)
attitude = asin(2*qx*qy + 2*qz*qw)
bank = atan2(2*qx*qw-2*qy*qz , 1 - 2*qx2 - 2*qz2)

heading = atan2(0 , 1)
attitude = asin(0)
bank = atan2(-1 , 0)

heading = 0
attitude = 0
bank = -90 degrees

backLeft

w = 0.5
x = -0.5
y = 0.5
z = 0.5

heading = atan2(2*qy*qw-2*qx*qz , 1 - 2*qy2 - 2*qz2)
attitude = asin(2*qx*qy + 2*qz*qw)
bank = atan2(2*qx*qw-2*qy*qz , 1 - 2*qx2 - 2*qz2)

heading = atan2(1 , 0)
attitude = asin(0)
bank = atan2(-1 , 0)

heading = 90 degrees
attitude = 0
bank = -90 degrees

leftForward

w = 0
x = 0
y = 0.7071
z = 0.7071

heading = atan2(2*qy*qw-2*qx*qz , 1 - 2*qy2 - 2*qz2)
attitude = asin(2*qx*qy + 2*qz*qw)
bank = atan2(2*qx*qw-2*qy*qz , 1 - 2*qx2 - 2*qz2)

heading = atan2(0 , -1)
attitude = asin(0)
bank = atan2(-1 , 0)

heading = 180 degrees
attitude = 0
bank = -90 degrees

 

forwardRight

w = 0.5
x = -0.5
y = -0.5
z = -0.5

heading = atan2(2*qy*qw-2*qx*qz , 1 - 2*qy2 - 2*qz2)
attitude = asin(2*qx*qy + 2*qz*qw)
bank = atan2(2*qx*qw-2*qy*qz , 1 - 2*qx2 - 2*qz2)

heading = atan2(-1 , 0)
attitude = asin(0)
bank = atan2(-1 ,0)

heading = -90 degrees
attitude = 0
bank = -90 degrees


metadata block
see also:

 

Correspondence about this page

Book Shop - Further reading.

Where I can, I have put links to Amazon for books that are relevant to the subject, click on the appropriate country flag to get more details of the book or to buy it from them.

cover us uk de jp fr caVisualizing Quaternions by Andrew J. Hanson

Other Math Books

Commercial Software Shop

Where I can, I have put links to Amazon for commercial software, not directly related to the software project, but related to the subject being discussed, click on the appropriate country flag to get more details of the software or to buy it from them.

cover Dark Basic Professional Edition - It is better to get this professional edition

cover This is a version of basic designed for building games, for example to rotate a cube you might do the following:
make object cube 1,100
for x=1 to 360
rotate object 1,x,x,0
next x

cover Game Programming with Darkbasic - book for above software

 

Can you help?

Please send me any improvements to here. I would appreciate ideas to make the pages more useful including error correction, ideas for new pages, improvements to wording. It helps if you quote the full URL of the page.

 

progam

I am working on a project which uses these principles, if you would like to help me with this you are welcome to join in, here:

http://sourceforge.net/projects/mjbworld/

This site may have errors. Don't use for critical systems.

Copyright (c) 1998-2008 Martin John Baker - All rights reserved.