Rotations, Quaternions, and Direction Cosines

 

            Quaternions have bothered me for a long time.  A colleague of mine once handed me copies of some pages from books that talked about “quaternions,” also called “spinors,” “spin matrices,” and a host of other names.  What bothered me was that I was already familiar with Eulerian rotations, and I wondered what quaternions did differently that made them useful.

            Here is my best answer to date.  This paper answers several particular questions about using quaternions and direction cosines for performing rotations.  It also relates quaternions to Eulerian rotations.  The questions include the following.

 

            1.         I want to rotate a vector by a specified angle about an arbitrary axis of rotation.  Where does the vector end up?  Answer:  Use quaternions.

            2.         I want to rotate a vector from Point 0 to Point 1 (these points are assumed to be a unit distance from the origin).  What is the shortest path of rotation?  What is the axis of rotation?  What is the angle of rotation?  Answer:  Use quaternions.

            3.         To find an angle bisector between two vectors, A and B, I want to find the axis of rotation such that a 180 degree rotation of A maps it to B.  How do I do this?  Answer:  Use quaternions.

            4.         How do I rotate from one reference frame to another?  Answer:  Use direction cosines.

            5.         When rotating between one frame and another using direction cosines, where is the axis of rotation, and what is the angle of rotation?

            6.         What is the direction and length of the differential tangential element described by a differential rotation about an arbitrary axis?

 

Background on Quaternions

            To begin, we first must learn a bit about quaternions.  These mathematics were apparently developed by Gauss (but never published by him) and separately by William Hamilton.  One text of mine says that

 

On the evening of October 16, 1843, William Rowan Hamilton was walking with his wife along the Royal Canal in Dublin when the answer leapt to his mind, the fruit of years of reflection [a pun?].  With his knife he then and there carved on a stone on Brougham Bridge the formulas

 

 

which in today’s notation,

 

  

 

take the form

 

 

 (and cyclic permutations)

 

(I have changed the notation slightly to conform with my own standards.)  The author has a footnote that reads

 

In the same city on June 21, 1972 President Eamon de Valera told one of the authors that, while in jail one evening in 1916, scheduled to be shot the next morning, he wrote down the formula of which he was so fond, .

 

Unfortunately I do not have the complete reference, and I know only that it is in Chapter 41, entitled “Spinors,” of some book.

 

            Piecing together bits and pieces from several such references, none complete, some with sloppy notation, I managed to compile the following practical guide.  First, one can discuss a sequence of rotations of the coordinate system about specified axes.  Second, one can pick an arbitrary axis (by means of its direction cosines) and rotate a point about it.

            Let us consider the following sequence of rotations of a coordinate system.  The point, (x,y,z) remains fixed, and we want to know the location of the point in the new coordinate system after the sequence of rotations is complete.  First, we place the point coordinates in a complex matrix, .

 

           

 

            Next, we define a matrix, , that contains the rotations

 

           

 

The angles and their associated axes of rotations are as follows.  The order of rotation is important.

 

            1.   f:  Rotation about the z axis, the x axis moves toward the positive y axis.

            2.   q:  Rotation about the new x axis, the y axis moves toward the positive z axis.

            3.   y:  Rotation about the new z axis, the x axis moves toward the positive y axis.

 

Alternatively, one could consider the coordinate system fixed, and the point being rotated.  In this case, the angles and their associated axes of rotations are as follows.

 

            1.   f:  Rotation about the z axis, f is measured from the x axis toward the negative y axis.

            2.   q:  Rotation about the x axis, q is measured from the y axis toward the negative z axis.

            3.   y:  Rotation about the z axis, y is measured from the x axis toward the negative y axis.

 

To obtain the new coordinates described by the  matrix, one applies the formula

 

           

 

(Actually, the last term should be the conjugate transpose of , but since  is self-adjoint, the conjugate transpose is the inverse.)  The  matrix is given by

 

           

 

            We note that  can be decomposed and written in terms of the Pauli spin matrices  given above.

 

           

 

           

 

where we also have used the unit matrix, .

 

            Now we turn to rotating a point by an angle, , about an arbitrary axis in space.  The axis can be described in terms of the angles it makes with the coordinate axes:

 

            a  Angle with the x axis

            b  Angle with the y axis

            g  Angle with the z axis

 

The cosines of these angles are the direction cosines:

 

           

           

           

 

The rotation occurs in the clockwise direction from the perspective of a person situated at the origin and looking along the positive rotational axis.  To perform the rotation, one uses the  matrix described above and then forms the  matrix as follows.

 

           

 

The new coordinates, described by the  matrix, are obtained through

 

           

 

            We note that the computation of  is easy and is given by

 

           

 

If one prefers, the total transformation can be described by

 

 

This equation is very easy to compute.   can generally be computed as the dot product of two unit vectors,  as the norm of the cross product, and .  Thus, the above equation reduces to the following.

 

 

Question 1:  Rotation about an arbitrary axis

I want to rotate a vector by a specified angle about an arbitrary axis of rotation.  Where does the vector end up?

 

            Begin by defining the axis by its direction cosines , the angle of rotation by  (measured clockwise as viewed from the origin looking in the direction of the positive axis of rotation), and the original vector location by the unprimed coordinates ; then the rotation carries the vector to the primed coordinates (in the same reference frame) given by

 

 

Question 2:  Shortest path of rotation

I want to rotate a vector from Point 0 to Point 1 (these points are assumed to be a unit distance from the origin).  What is the shortest path of rotation?  What is the axis of rotation?  What is the angle of rotation?

 

            We begin with the normalized coordinates describing the two directions:   and .  We know that the shortest arc between these two directions will lie in the plane of these two points and the origin.  The equation of the plane is

 

           

 

where

 

           

           

           

 

When these parameters are normalized, they become the direction cosines of the normal vector to the plane.  This normal vector is also the desired axis of rotation:

 

           

           

           

 

Finally, we know that the angle of rotation will be equivalent to the angle included by Point 0, the origin, and Point 1.  This angle can be calculated by

 

           

 

Question 3:  Angle bisector between two vectors

To find an angle bisector between two vectors, A and B, I want to find the axis of rotation such that a 180 degree rotation of A maps it to B.  How do I do this?

 

            We begin by assuming that we have two unit vectors  and .  Applying the rotation formula,

 

 

we reduce it with the knowledge that .

 

 

            Now, we need to solve for the direction cosines of the rotation axis, .  Multiplying each side of the equation by  and equating terms on an element-by-element basis, one quickly arrives at the three equations (each repeated three times),

 

                 

 

Recognizing that

 

           

 

one has that

 

                   

 

 is easy to obtain because it is half of the angle included by the two vectors.  That is,

 

           

 

           

 

Note that  is always positive since the included angle must be less than 90°.  If the two vectors are diametrically opposed, then the answer is non-unique, and the procedure fails.  For nearly opposed vectors, severe cancellation  in the numerator could affect the numerical accuracy of the result.  If severe cancellation in one direction cosine is detected, it is best to discard the result, compute the other direction cosines, and apply the constraint .  Severe cancellation can also affect two or all three direction cosines.  Perhaps double precision is the best defense here.

            As an alternative formulation of the angle bisector problem, one could consider a rotation about an axis perpendicular to the plane of the two vectors by an amount equal to half of the included angle.  The resulting vector will be the angle bisector of the two original vectors.  In this case, severe cancellation can occur in the computation of the perpendicular to the two original vectors.

 

Question 4:  Rotation between reference frames

How do I rotate from one reference frame to another?

 

            When rotating from one reference frame to another, we define one coordinate system (the unprimed coordinates) with respect to the other (primed) coordinate system.  We do this by finding the direction cosines of each axis of the unprimed coordinate system in terms of the primed system.  For instance, the direction cosines of the x axis are given by .  Placing all of these direction cosines in a matrix gives us the rotation that we desire:

 

           

 

            As an example, we consider the unprimed system situated so that its z axis coincides with the z prime axis, but the frame is rotated so that the x axis coincides with the y prime axis.  The direction cosines are found by

 

                         

                     

                       

 

or

 

           

 

Thus, the point (1,0,0) in the unprimed system maps to (0,1,0) in the primed system.

            One further note is that the inverse of the matrix given above is merely the transpose of the matrix (that is, the matrix is self adjoint).  Hence,

 

           

 

Question 5:  Axis and angle of rotation when using direction cosines

When rotating between one frame and another using direction cosines, where is the axis of rotation, and what is the angle of rotation?

 

            If one completes a rotation as described in Question 5, it is natural to ask if one can determine the angular extent of the rotation and the axis of rotation.  To answer these questions, we compare the quaternion relationship

 

           

 

to the direction cosine relationship

 

           

 

on an element-by-element basis.  Comparison of the diagonal elements yields that

 

                       

 

By adding corresponding elements on opposite sides of the diagonal , and substituting the above expressions, one easily obtains that

 

           

 

           

 

           

 

For our purposes, any of these equations will do.  The sign is chosen so that the cosine calculation and the following direction cosine calculations lie between –1 and 1 (the previous direction cosine calculations must remain real).  By subtracting corresponding elements, one obtains

 

                   

 

These formula for the direction cosines are superior to the previous ones because sign information is retained.  The previous set of direction cosine equations was derived only to facilitate the derivation of the formulas for the cosine of the angle of rotation.

 

Question 6:  Length of a differential tangential element

What is the direction and length of the differential tangential element described by a differential rotation about an arbitrary axis?

 

 

or

 

 

If  be vanishingly small, then we obtain

 

 

or

 

 

where

 

 

Thus,

 

 

describes the tangent to the great circle.  The square of the length of a differential tangential element is

 

 

            For example, consider a rotation about the z axis so that  and .  The direction of the tangent vector is

 

           

 

or  and .  The length of the differential tangent element is

 

           

 

or .  (Note that this is  if the coordinates are converted to cylindrical coordinates.)