Quaternion Toolbox Overview

Quaternions

Quaternions are four-dimensional hypercomplex numbers (an extension of the complex number concept to higher dimensions). Conventionally, quaternions have four components and can be written in Cartesian form as:

q = w + xi + yj + zk
where the four ‘coefficients’: w, x, y, z are real or complex and the three hypercomplex operators i, j and k are square roots of -1 obeying the following rule: i² = j² = k² = ijk = -1. In what follows, the term ‘quaternion’ means a quaternion with real coefficients w, x, y, z, and the term ‘biquaternion’ is used for the case where the coefficients are complex (strictly if any one of them has a non-zero imaginary part).

Multiplication of quaternions is not commutative, so that, in general, q×p ≠ p×q. Of course, this also applies to biquaternions.

Quaternions have a polar form:

q = |q| exp(μθ)
where
|q|= √(w² + x² + y² + z²)
is the modulus of the quaternion, μ is called the axis (the direction in 3-space of the vector part), and θ is an angle in the range 0 to π.

Biquaternions

The design of the toolbox assumes that the components of a quaternion may be complex. There is no special provision to deal with this. Consequently, the whole toolbox will work for biquaternions. That said, some functions do not yield correct results for biquaternion arrays. Where this is known, the function usually issues a warning if called with a biquaternion argument.

The quaternions are a division algebra, meaning that every non-zero quaternion has a multiplicative inverse. This is not true for the biquaternions, where divisors of zero exist (these have no multiplicative inverse, and zero norm, despite a non-zero value). There are also idempotents in the biquaternions (values that square to give themselves).

Octonions

From version 2 of the toolbox, support is provided for computation with octonion arrays. This is achieved by making maximum use of existing quaternion functions to do as much computation as possible. The internal representation of an octonion is a pair of quaternions (the Cayley-Dickson form). Octonion functionality is very limited because it is not known how to compute many octonion functions yet, or there has not been time to write the missing functions. As with quaternions, the components of an octonion may be complex, but very little is known about complexified octonions, so users who work with them will be entering uncharted territory. There are certainly divisors of zero, so beware.

Toolbox design principles

Quaternions are represented by the toolbox in the Cartesian form with four components named w, x, y and z. These components are accessible using the functions s (for scalar), and x, y, z. Quaternion matrices are constructed by the constructor function quaternion which can combine together numeric matrices to make a full or pure quaternion. It is also possible to make a quaternion value by using the three quaternion ‘operators’, which are provided as parameterless functions qi, qj, qk:

3 .* qi + 4 .* qj
will yield the quaternion value 3i + 4j.

The toolbox has been designed to extend Matlab® in as natural a way as possible. Therefore the user should assume unless there is a reason to do otherwise that the way to carry out an operation is the same as in Matlab®. Where this is not the case, an error should occur. The documentation or the source code for the appropriate function should be consulted to see whether there is a known limitation.

For example, standard Matlab® notation has been overloaded for quaternion arrays, so that the following makes sense to the toolbox if the variables exist as quaternion arrays:

[p q r] * [a b c].'

Even if one of the vectors is replaced by a numeric vector, the result is still computable, since the toolbox can multiply numeric values by quaternions:

>> [1 2 3] * [qi qj qk].'
 
ans = 1 * I + 2 * J + 3 * K

Further, we can replace one element in the left vector by a quaternion, since the toolbox allows quaternion and numeric (non-quaternion) arrays to be concatenated: the numeric array is automatically converted to a quaternion array by putting the numeric values into the scalar part of an otherwise zero quaternion:

>> [1 qj 3] * [qi qj qk].'

ans =
 
     -1 + 1 * I + 0 * J + 3 * K

In most cases where quaternion matrices and vectors are handled it is not necessary to resort to ‘tricks’ to make things work: try the obvious first and if errors occur, work around them by explicit coding, but do not code some clever workaround for a problem that the toolbox can handle for you.

© 2008-2013 Stephen J. Sangwine and Nicolas Le Bihan.

License terms.