Definition of terms:
This depends on what conventions are used for the Euler Angles. The following assumes NASA Standard Airplane.
The components of the quaternion (w,x,y,z) are:
w = c_{1}c_{2}c_{3} + s_{1}s_{2}s_{3 }x = c_{1}c_{2}s_{3}  s_{1}s_{2}c_{3 }y = c_{1}s_{2}c_{3} + s_{1}c_{2}s_{3 }z = s_{1}c_{2}c_{3}  c_{1}s_{2}s_{3}
where:
An alternative form is:
w = Math.sqrt(1.0 + C_{1} * C_{2} + C_{1}*C_{3} + S_{1} * S_{2} * S_{3} + C_{2}*C_{3})
/ 2
x = (C_{2} * S_{3} + C_{1} * S_{3} S_{1} * S_{2} * C_{3}) / (4.0 * w)
y = (S_{1} * S_{3} + C_{1} * S_{2} * C_{3} +S_{2}) /(4.0 * w)
z = (S_{1} * C_{2} + S_{1} * C_{3}  C_{1} * S_{2} * S_{3}) / (4.0 * w)
where:
Thanks to Mark for letting me know that I originally omitted to point out that the angles are divided by 2 in the first case but not the second. So now the second form is shown upper case (C1) to make it clear that the heading is used directly and not divided by 2. Mark has also included some other useful references.
I don't know which of these forms is most stable? However, as William points out the first is better because it requires the same number of trig operations, no square root, no worry about dividing by zero, uses familiar formulae, and is fairly clearly normalised.
William has proved here that the methods are equivalent.
Thanks to Andy for the following:
From the basic definition of a quaternion, we can easily express the quaternion form for rotation along the X, Y, and Z axes, representing bank, attitude, and heading, respectively. Recall that the rotation quaternion (w, x, y, z) for the angle q is encoded as _{ } and (x, y, z) represents a vector of length _{ } along the axis of rotation. Note also that the handedness of the rotation must agree with the handedness of the coordinate system for the quaternion to be valid. Then
_{ }
_{ }
_{ }
To express the rotation of an arbitrary set of Euler angles φ, θ, and ψ we compose the rotations about the three axes by multiplying the quaternions. In the NASA standard aeroplane, the rotations are applied in the order heading, attitude, and bank. However, because each rotation is expressed in the frame of reference of the aircraft, from an outside frame of reference they must be composed in the reverse order. Remember that multiple quaternions are applied right to left:
_{ }
Substituting and multiplying out, we get
_{ }
First method (Euler parameter method)
public final void rotate(double heading, double attitude, double bank) {
// Assuming the angles are in radians.
double c1 = Math.cos(heading/2);
double s1 = Math.sin(heading/2);
double c2 = Math.cos(attitude/2);
double s2 = Math.sin(attitude/2);
double c3 = Math.cos(bank/2);
double s3 = Math.sin(bank/2); double c1c2 = c1*c2;
double s1s2 = s1*s2;
w =c1c2*c3 + s1s2*s3; x =c1c2*s3  s1s2*c3; y =c1*s2*c3 + s1*c2*s3;
z =s1*c2*c3  c1*s2*s3; }
Second method
public final void rotate(double heading, double attitude, double bank) {
// Assuming the angles are in radians.
Double c1 = Math.cos(heading);
double s1 = Math.sin(heading);
double c2 = Math.cos(attitude);
double s2 = Math.sin(attitude);
double c3 = Math.cos(bank);
double s3 = Math.sin(bank); w = Math.sqrt(1.0 + c1 * c2 + c1*c3 + s1 * s2 * s3 + c2*c3) / 2.0;
double w4 = (4.0 * w);
x = (c2 * s3 + c1 * s3 s1 * s2 * c3) / w4 ;
y = (s1 * s3 + c1 * s2 * c3 +s2) / w4 ;
z = (s1 * c2 + s1 * c3  c1 * s2 * s3) / w4 ; }
we take the 90 degree rotation from this:  to this: 
As shown here the axis angle for this rotation is:
heading = 0 degrees
bank = 90 degrees
attitude = 0 degrees
so substituteing this in the above formula gives:
w = c_{1}c_{2}c_{3} + s_{1}s_{2}s_{3 = 0.7071 }x = c_{1}c_{2}s_{3}  s_{1}s_{2}c_{3 = 0.7071 }y = c_{1}s_{2}c_{3} + s_{1}c_{2}s_{3 = 0 }z = s_{1}c_{2}c_{3}  c_{1}s_{2}s_{3 = 0}
which gives the quaternion _{0.7071} + i _{0.7071}
This agrees with the quaternions here.
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. 

This site may have errors. Don't use for critical systems.
Copyright (c) 19982017 Martin John Baker  All rights reserved  privacy policy.