# Quaternions (Advanced Methods in Computer Graphics) Part 1

## Overview

In computer graphics applications, quaternions are used to represent threedimensional rotations. They provide some key advantages over the traditional way of defining generic rotational transformations using Euler angles. Quaternions are also extremely useful for interpolating between two orientations in threedimensional space. Keyframe animations requiring orientation interpolation therefore find a very convenient mathematical tool in quaternions.

This topic gives an overview of the algebra of quaternions, the geometrical interpretation of quaternion transformations, and quaternion based linear and spherical interpolation functions. A comparison of rotation interpolation methods using Euler angles, angle-axis representations, and quaternions is presented. The extension of quaternions to eight-dimensional dual quaternions and their usefulness in representing general rigid-body transformations are also discussed.

## Review of Complex Numbers

Quaternions are hyper-complex numbers of rank 4, and therefore it is useful to review some of the basic concepts related to complex number algebra to gain a better insight into quaternion operations. Even though a complex number z is commonly represented in the form a + ib where i =    1,    and a, b are respectively the real and imaginary parts of z, we will use the two-tuple notation (a, b) for z. With this notation, we can write 1 = (1,0), and i = (0, 1). These two-dimensional vectors (1, 0) and (0, 1) form an orthogonal basis for the complex space, where any number z = (a, b) can be expressed as their linear combination a (1,0) + b (0, 1). The operations of addition, subtraction and multiplication in the field of complex numbers are defined as follows: Fig. 5.1 Multiplication by a unit complex number has the effect of rotation of vectors and points about the origin on a two-dimensional plane

where c is a real number. The multiplication rule given in Eq. 5.2 establishes the fact that i2 = (0,1) (0,1) = (—1, 0). The complex conjugate of z = (a, b) is given by z* = (a, —b). The magnitude of z is a positive real number defined as

Using the multiplication rule, we find that

If a complex number z has a unit magnitude, then zz* = 1. This implies that for a unit complex number, z* is the multiplicative inverse of z. All unit complex numbers can be expressed in the general form

Consider any vector (or point)p = (x, y) in a two-dimensional coordinate system. If we treat p as a complex number, and multiply it by the unit complex number z given above, the product zp can be evaluated using Eq. 5.2 as follows:

The transformed vector (or point) p’ has the same magnitude as p, and can be obtained by rotating p about the origin by an angle 1 (Fig. 5.1). The unit complex vector therefore represents a rotation in two-dimensional space.

The geometrical interpretation of unit complex numbers as rotation operators forms the basis for the framework for an extended set of hyper-complex numbers called quaternions. We will see shortly that unit quaternions represent threedimensional rotations. In the following section, we introduce the algebra of quaternion numbers.

## Quaternion Algebra

We have seen above that the field of complex numbers have 1 = (1, 0), i = (0, 1) as the orthogonal basis. The quaternion set has an extended orthogonal basis consisting of four elements 1 = (1, 0, 0, 0), i = (0, 1, 0, 0), j = (0, 0, 1, 0), k = (0, 0, 0, 1). Thus a quaternion Q = (q0, q1, q2, q3) has an equivalent representation q0 + q1i + qzj + q3 k, where the quaternion components q\ are all real values. The term q0 is called the scalar part of Q, and the 3-tuple (q1, q2, q3) the vector part. The operations of addition, subtraction and scalar multiplication are defined as follows:

where c is any real number. Analogous to Eq. 5.2, the quaternion product is given by

From the above definition of a quaternion product, it is obvious that quaternion multiplication is not commutative. That is, for any two quaternions P = (p0, p1, p2, p3), Q = (qo, q1, q2, q3), the product PQ need not necessarily be the same as QP. If we denote the vector part of P by v = (p1, p2, p3) and the vector part of Q by w = (q1, q2, q3), then Eq. 5.10 becomes

where v^w denotes the dot product and vxw the cross product of the two vectors. The right-hand side of Eq. 5.10 when treated as a column vector, can be conveniently expressed as a product of a matrix of elements of P and a vector containing elements of Q as given below.

or, equivalently as

From Eq. 5.10, we can derive the following properties satisfied by the quaternion basis:

Quaternions also form a commutative group under addition, where (0,0,0,0) is the identity element. Quaternion multiplication is associative, and distributes over addition. If P, Q, R are any three quaternions,

The conjugate Q* of the quaternion Q = (q0, q1, q2, q3) is defined as

Thus, if Q = (q0, w), then Q* = (q0, — w). Also, Q + Q* = 2q0. The magnitude (also called the length, or norm) of Q denoted by |Q|, is

By taking the magnitude of the quaternion product in Eq. 5.10 we get

Using Eq. 5.11, it is easy to find that

By dividing the above equation by |Q|2, we get the equation for the quaternion inverse. If we denote the quaternion inverse of Q by Q_1, then

A quaternion Q can be normalized to a unit quaternion by dividing each of its components by the length |Q| given in Eq. 5.17. A unit quaternion satisfies the following equations:

If the real part q0 of a quaternion is zero, it represents a vector (q1, q2, q3) in three-dimensional space. Such a quaternion that has the form (0, q1, q2, q3) = (0, q) is called a pure quaternion. Similarly, quaternions of the type (a, 0, 0, 0) with the vector component zero are called real quaternions. The algebra of real quaternions is the same as that of real numbers. Similarly, quaternions of the type (a, b, 0, 0) behave exactly like complex numbers (a, b).

## Quaternion Transformation

A special type of quaternion product in the form QPQ* plays an important role in three-dimensional transformations. We have just seen that a vector p in the threedimensional space corresponds to a pure quaternion P = (0, p). An interesting fact that leads to the notion of a quaternion transformation is that given any quaternion Q and a pure quaternion P, the product P’ = QPQ* is also a pure quaternion. Thus QPQ* can be viewed as the transformation of a pure quaternion P = (0, p1, p2, p3) using another quaternion Q. We can derive the matrix form of this transformation by using Eq. 5.13 for obtaining the matrix expression for PQ* and then using Eq. 5.12 for getting the final product Q(PQ*).

The following matrix equation immediately follows by multiplying the two matrices together, and setting p0 = 0:

This equation defines the quaternion transformation of a three-dimensional point (or vector)p = (p1, p2, p3) to another three-dimensional point (or vector)p’ = (p10, p2′, p3′). An alternative form of the equation can be derived as follows:

where w = (q1, q2, q3). Using Eq. 5.11 to expand the product term, we get

The above equation proves that the transformation of P is also a pure quaternion. We can therefore write

Further simplification of the right-hand side using vector algebra gives

It should be noted that QPQ* generally is not a scale-preserving transformation because

If we impose the constraint that Q is a unit quaternion (i.e., \Q\ = 1), we get a scale-invariant (or length-preserving) transform. With this additional criterion, we can also write the inverse quaternion transform in a concise form as

We also note that when P is the zero-quaternion (0, 0, 0, 0), so is P’. Therefore the origin is a fixed point of the transformation. A length-preserving transformation with a fixed point is a rotation. In the following sections we will attempt to find a geometric interpretation of the quaternion transformation as a pure rotation in threedimensional space, and express the components of a unit quaternion in terms of the angle and the axis of rotation.