Quaternions


Dan Slater
(Copyright 1991, All rights reserved)


Introduction
The use of the quaternion in the solution of rigid body rotations as required by computer graphics, flight simulation and inertial guidance systems has proven to be efficient and accurate. Attitude parameterization by the quaternion is more compact than the direction cosine matrix and more computationally efficient than the Euler axis/angle and Euler angle methods. In addition, the Euler angle parameterization has singularities at certain angles which limits the generality of their usage.
 
Definition of the quaternion
The quaternion is a quadruple consisting of a real scalar part (q4) and a hyper-imaginary 3 vector part (q1,q2,q3) defined as follows:

q = q4 + iq1 + jq2 + kq3           (1a)

where:

i2 = j2 = k2 = -1                  (1b)

and:

ij = -ji  = k                     (1c)
jk = -kj  = i                    (1d)
ki = -ik  = j                    (1e)

Additional constraints are often used to support rotational dynamics models; First, the quaternion should have a norm of one. This prevents loss of precision in computers and simplifies the related vector transformations.Second, the quaternion is defined in terms of the Euler Rodriques rotation
parameters (Altmann, 1986) or equivalently Euler symmetric parameters (Wertz, 1978) allowing rotations to be performed as quaternion products:

                                                         q4 =    cos (f/2)                 (2)
                                                         q1 = ex sin (f/2)
                                                         q2 = ey sin (f/2)
                                                         q3 = ez sin (f/2)

where:

e = unit vector along axis of rotation
f = total rotation angle

Note that the norm of this quaternion is unity.

Euler's theorem states "the general displacement of a rigid body with one point fixed is a rotation about some axis". In other words, for any rotation there exists a given axis of rotation in one coordinate system which remains invariant in another reference coordinate system. Any rotation may be expressed as a rotation through some angle about some axis. This parameterization of the attitude is called the Euler axis/angle parameterization.

The literature contains a variety of definitions of the quaternion having different orders and sign conventions. The components of the Rodriques quaternion are often called Euler symmetric parameters.
 
Conversion between Euler angles and a quaternion

The quaternion equivalence to a set of Euler angles with a 321 (yaw, pitch, roll rotation) sequence is (Gainer, 1972):

q4 = cos(yaw/2) cos(pitch/2) cos(roll/2)                      (3)
   + sin(yaw/2) sin(pitch/2) sin(roll/2)

q1 = cos(yaw/2) cos(pitch/2) sin(roll/2)
   - sin(yaw/2) sin(pitch/2) cos(roll/2)

q2 = cos(yaw/2) sin(pitch/2) cos(roll/2)
   + sin(yaw/2) cos(pitch/2) sin(roll/2)

q3 = sin(yaw/2) cos(pitch/2) cos(roll/2)
   - cos(yaw/2) sin(pitch/2) sin(roll/2)

For small angles, the cosine terms in equation 3 can be replaced with a value of one. The quaternion is therefore approximately equal to:

q4 ~ 1                                                        (4)
q1 ~ roll / 2
q2 ~ pitch / 2
q3 ~ yaw / 2

Euler angles can be extracted from a quaternion as:

tan(yaw)   =  2(q1q2+q4q3)/ (q42 + q12 - q22- q32)      (5a)
sin(pitch) = -2(q1q3-q4q2)                                              (5b)
tan(roll)  =  2(q4q1+q2q3)/ (q42 - q12 - q22+ q32)        (5c)

The following are some representative quaternions and the equivalent Euler angles:

yaw   =  0°   q1 = 0.00000
pitch =   0°   q2 = 0.00000
roll  =    0°    q3 = 0.00000
                    q4 = 1.00000

yaw   = 90°    q1 = 0.00000
pitch =   0°     q2 = 0.00000
roll  =     0°     q3 = 0.70711
                       q4 = 0.70711

yaw   =  0°      q1 = 0.00000
pitch = 60°      q2 = 0.50000
roll  =  0°        q3 = 0.00000
                       q4 = 0.86603

yaw   = 10°     q1 = 0.23930
pitch = 20°      q2 = 0.18931
roll  = 30°        q3 = 0.03813
             
q4 = 0.95155
 
Direction of rotation

We may reverse the direction of a rotation simply by taking the complex conjugate of the quaternion:

q* = [ q4 -q1 -q2 -q3]T = [ q4, -q ]T                                                  (6)
 
Quaternion normalization

The length or norm of a quaternion is defined as
                                                
(7)

The norm of the Rodriques quaternion should be 1. If the quaternion is integrated, the quaternion norm will diverge. The quaternion can be renormalized by dividing the quaternion by it's norm.
 
Combined rotations
A quaternion can be rotated into a new reference frame by a multiplication following the laws of quaternion algebra (Brand, 1947, Altmann, 1986). For example, a set of quaternions that rotates A into B and B into C can be combined into a single quaternion that rotates A into C. Note that the quaternion elements in the following vectors are in q1 to q4 order.

qC = qA qB                            (8a)

Using the rules of quaternion algebra, this is:
                                        
(8b)

After forming the vector matrix product:
                               
(8c)
 
Conversion of a latitude & longitude to a quaternion A latitude and longitude position on a planet can be converted to a quaternion by forming the quaternion product of the latitude and longitude
quaternions.

The longitude quaternion is:


where:

f= longitude                                       (9a)

Often a non rotated quaternion should result when the Z axis points downward and the body is at 0 degrees latitude and longitude. For this reason, the quaternion defining the latitude may be defined in terms of the colatitude with an additional 180° rotation:

 

where:

q= p + p /2 - latitude                        (9b)

The combined rotation can be derived by substituting equations 9a
and 9b into 8b.
            
(9c)

After combining terms, this results in:
                                                        
(9d)
 
Transformation of a vector by a quaternion A 3 element vector may be directly rotated by a quaternion in a manner similar to that used to rotate a quaternion. In this case the scalar part
is zero.

That is:

                              v'
= q* v q                                                                  (10a)

This is equivalent to:

              v' = (2q42- 1)v + (2q)(q· v) + 2q4 (qx v)                                       (10b)

where: v' = output vector

v = input vector
q = vector part of the quaternion (q1,q2,q3)
or:
                
          wpe15.jpg (6249 bytes)(10c)

Using the relationship between the Euler axis / angle and quaternion
this can be written alternately as:

                              v' = cos(Ø)v + (1-cos(Ø))(eØ· v)ef-sin(Ø )(eØxv)                          (10d)

where: Ø= rotation angle about efaxis
           eØ = unit vector along axis of rotation
 
Conversion of a quaternion into a direction cosine matrix

A direction cosine matrix can be extracted from a quaternion using the following relationship:
                    
        wpe16.jpg (7724 bytes)(11)
 
In general, if a single vector needs to be transformed, equation 10 is more efficient. If a large number of vectors need to be transformed, it is more efficient to first convert the quaternion into a direction cosine matrix (equation 11) and then use conventional matrix vector products.
 
The inertial rate quaternion in terms of body rates

If Q is the orientation quaternion, then the inertial rate quaternion is:

q' = dQ/dt = 1/2 * quaternion(w ) * Q

The quaternion (w ) converts the angular velocity vector, omega, into a quaternion with a zero scalar part and omega as the vector part. You numerically integrate Q + dQ/dt. Q should be normalized at the end of the numerical integration step.

The inertial rate quaternion (q') is defined in terms of the inertial attitude quaternion and the body rates:
                                                            
                                    wpe17.jpg (5074 bytes)(12)
In a typical vehicle dynamics model, the angular forces on the vehicle are converted into angular accelerations and then integrated in the vehicle reference frame to derive body referenced rotation rates (yaw rate, pitch rate and roll rate). These rates are converted into an inertial rate quaternion
using equation 12. The inertial rate quaternion is integrated forming an inertial attitude quaternion. The inertial attitude quaternion represents the vehicle attitude in inertial space.

These quaternion equations are most commonly implemented in a digital computer. An alternate approach suitable for an analog computer or operation amplifier implementation is described in (Mitchell, 1968).
 
References:
Altmann, S., Rotations, Quaternions and Double Groups, Clarendon Press, Oxford, England (1986). This is an advanced text containing extensive detail. Has an interesting chapter on the history of quaternions.
Anon, Peacekeeper R&D Flight Program Equations, Internal eeport # C83-432/201, Rockwell International, Anaheim, CA (1983). Describes the use of quaternions in the context of a rocket guidance program.
Anon, Strapdown Inertial Systems , Publication # GRB-003-0172A, Lear Siegler Inc., Grand Rapids, MI (1974). Describes the use of quaternions in strap down inertial guidance
systems.
Brand, Vector and Tensor Analysis, John Wiley and Sons, New York, NY (1947). Contains a chapter on quaternion algebra. Farrell, J., Integrated Aircraft Navigation, Academic
Press, New York, NY (1976). Contains a chapter on coordinate transformations including quaternions.
Gainer, Hoffman, Summary of Transformation Equations and Equations of Motion used in Free Flight and Wind Tunnel Data Reduction and Analysis, NASA special publication SP-3070 (1972). Reference document describing transformation equations. 
Minkler, G., J. Minkler, Aerospace Coordinate Systems and Transformations, Magellan Book Company, Baltimore, MD (1990). Reference book describing transformations. Includes a chapter on quaternions.
Mitchell, E., A. Rogers, Quaternion Parameters in the Simulation of a Spinning Rigid Body, in "Simulation" Edited by J. McLeod, McGraw Hill, New York, NY, (1968). Describes an analog computer implementation of quaternion equations.
Regan, F., Re-Entry Vehicle Dynamics, American Institute or Aeronautics and Astronautics, New York, NY (1984). Contains a detailed appendix on quaternions. Stevens, R., Fractal Programming and Ray Tracing with C++, M&T Books, Redwood City, CA (1990). Includes a simple quaternion class that is coded in C++.
Wertz, J., Spacecraft Attitude Determination and Control, D. Reidel Publishing, Hingham, Mass (1978). A classic work with extensive discussions on the subject of attitude
parameterization.