This document can be viewed properly only in modern browsers with good support for CSS2 and the full HTML character set.

3-D re-orientation via Quaternions

Prerequisites

To understand this, you will need knowledge of basic linear algebra, such as is often taught in a university second-year algebra course.

Transformation of coordinates

Two orthogonal coordinate systems X and Y are related by a transformation of bases B by

B Y = X B

otherwise expressed as a similarity transformation of Y:

Y = B−1 X B

In three dimensions, with respect to a given basis, each of the above coordinate systems and bases can be represented as a 3 × 3 matrix, and all the calculations can be done directly.

A problem arises when one coordinate system is to be continuously moved to another, as with a jet fighter, a spacecraft, or in a 3-D video game. Instead of B in the above, write B(s) where B is a continuous matrix function of s between 0 and 1, and B(0) is the identity.

There is in fact a path between any two coordinate systems for which the transformation is well behaved... but what is it?

One obvious path would be a linear interpolation between the two coordinate systems. Of course, even if B(0) and B(1) are invertible, there may be a value of s such that B(s) is not invertible.

Another approach is to first map the parameter s to a two-dimensional set of angles, which are then used to calculate the directions of the axes. This avoids the transformation B becoming singular, but the map itself introduces a different problem. It is not possible to continuously map a portion of a 2-D plane onto the whole sphere in a 1-to-1 fashion.

Quaternion-based change of coordinates

The quaternions, however, are a division ring: any non-zero quaternion has an inverse. And multiplication by a unit quaternion corresponds to a change of orientation, which may be viewed as a change of coordinate systems.

The trick is to pack each 3-vector into a quaternion, and convert that to another quaternion by multiplications.

y = q(s)−1 x q(s) .

Such transformation will not present any problem along any path q(s) that avoids the origin. For the simplest kind of path — a linear path — that is very easy to check: the two end points must not be negative real multiples of one another.

(This is the practicality of the question “are there any 3-dimensional division rings”: it would be really nice to handle the problem all in 3-D, but that is in fact impossible.)

With the block matrix forms for left- and right-multiplication given in quaternions as matrices, right multiplication by q = ( t, v ) followed by left multiplication by its conjugate is represented by

t v ·
v t I + v ×
 
t v ·
v t I + v ×
  =  
|( t, v )| I −  
0 0
0 2 t v ×
 .

Since the inverse of a quaternion is its conjugate divided by the square of its norm, the matrix representing the transformation of x to q−1 x q is represented by

T = I   −   2 t |( t, v )|−1  
0 0
0 v ×
 .

The case for a multiplication by a quaternion on the right is the same, except with the “−” replaced by a “+”. Now, the cross product v × acts on another vector to produce a vector perpendicular to the first two, in the direction indicated by the right-hand rule. Thus right multiplication by a quaternion is identified with a change of 3-D coordinates with a twist following the right-hand rule, and multiplication by a quaternion on the left is identified with left-hand twist.

Note that the lower right 3-D block of this transformation is a rotation about a vector ( 0, v ), which is a fixed point of T.

Rotation and skew-symmetry

Some connection from the cross-product in the above expressions and a rotation is provided by a general relation between skew-symmetric transforms and rotations of any vector space.

If S is any skew-symmetric transformation (that is, ST = −S), then there is a rotation R such that

(I + S) = R(IS).

Since the non-zero eigenvalues of S are all pure imaginary, it is possible to solve for R in terms of S.

R = (I + S) (IS)−1.

The right side of this expression was studied by Cayley. It is formally related to the fractional transformation of complex analysis.

A key fact required to perform the manipulations here is that if A is any invertible transformation of the space, then A commutes with (A + I)−1,

Now, the operator v × above, acting on 3-space, is skew-symmetric. So it corresponds directly to a rotation as given by this fractional transformation.

Calculation of transformation between two coordinate systems

The reverse problem is to determine the quaternion q = ( t, v ) from the transformation matrix T.

An effective calculation of v (in the case of coordinate systems of the same handedness) follows from the observation that it is the vector whose representation is the same in both coordinate systems, that is, a 3-vector b for which

b = B b ,

that is to say, an eigenvector corresponding to eigenvalue 1 of the matrix B. That can be calculated easily by various means, such as a QR decomposition. This eigenvector will be well defined, provided B is not the identity matrix.

The vector b will then have the right direction. The value of t is just

T [ 1, 0 ]T .

Finally, to find the multiplier s of b apply T to a vector d that is perpendicular to b

T [ 0, d ] . T .

If the two coordinate systems are of opposite handedness, there is no such vector v; instead there is a vector whose representation in one system is the negative of that in the other, that is, an eigenvector corresponding to the eigenvalue −1.