**Related Topics:** Euler's Equation, Quaternion to Rotation Matrix

Quaternion is a geometrical operator to represent the relationship (relative length and relative orientation) between two vectors in 3D space. William Hamilton invented Quaternion and completed the calculus of Quaternions to generalize complex numbers in 4 dimension (one real part and 3 imaginary numbers). In this article, we focus on rotations of 3D vectors because Quaternion implementation for 3D rotation is usually simpler, cheaper and better behaved than other methods.

- Background of Quaternion
- Understanding of Quaternion
- Quaternion Algebra
- 3D Rotation with Quaternion
- Quaternion to Matrix
- References

Euler's equation (formula) can be used to represent a 2D point with a length and angle on a complex plane. Multiplication of 2 complex numbers implies a rotation in 2D. One may think instantly it can be extended to 3D rotation by adding additional dimension. William Hamilton initially studied it by adding an additional imaginary number, *j* to generalize complex numbers to 3D.

However, the set of 3 dimensional complex numbers is not closed under multiplication. For example, the multiplication of *i* and *j* cannot be represented as a form of *a+ib+jc*. If multiplication is closed, then there exist *a, b, c* ∈ **R** that satisfies *ij=a+ib+jc*.

The equation *c ^{2}+1=0* gives the contradiction. There is no real number

Later, Hamilton realized 4 dimensional complex numbers are required for multiplication to be closed by adding an additional imaginary part, *k*. And, he denoted this 4D complex number set as Quaternion. *(In mathematics, each algebra has twice the dimension of the previous one. Therefore, the higher number set of complex number is quaternion, and the next number set is octonion.)*

Now, the above example now satisfies as *ij=0+i0+j0+k1*. The condition of 3 imaginary numbers is explained later, in Quadrantal vectors.

Hamilton's motivation was to create a geometrical operator to transform from a vector to the other in 3D space. This operator is the geometric quotient (ratio) between two vectors that changes the length and the orientation, and it is called a Quaternion because the operation is required 4 parameters.

, or,

(Note that this notation is not same as numerical division nor multiplication. Instead, it is translated as
"the quaternion operator *q* on to produce , or the operator *q* to convert into ".)

When is transformed to vector , quaternion operator performs 2 distinct operations:

**Tensor**: scaling the length of , so as to make it of the same length as .**Versor**: rotating , so as to cause it to coincide with in direction.

These 2 opearions can be symbolically represented (tensor of *q*) and (versor of *q*) respectively.

The order of these two operations does not make any difference of the result. The combined tensor and versor operation requires 4 numbers; 1 for scaling, 1 for rotation angle, 2 additional angles to determine the orientation of the rotation plane. For example, a xy-plane is rotated about x and y axis. But, rotation along z axis does not change the orientation of the xy plane.

**Tensor**

Tensor of *q* is the geometric quotient (ratio) between the lengths of 2 parallel vectors. It changes the scale of the vector, but, keeps the orientation of the vector unchanged.

**Versor**

Versor of *q* is the geometric quotient of 2 non-parallel vectors of equal length. It represents the relative orientation of one vector with respect to the other vector, but, it does not change the length of the vector.

To investigate the quaternion operator deeper, let and as unit vectors along and . so that

And, draw BC perpendicular to , and let the unit vector along be . Therefore, becomes and . Since , we substitute and in the above equation, then we have a quaternion, ;

The last term contains the geometric quotient of two unit vectors at right angles (90 degree) to each other. This quotient represents a unit vector perpendicular to the plane of and . (Think of cross product of 2 vectors) This unit vector is indicating the rotation axis of the plane and the direction of rotation. If we define it , the above equation becomes

From this equation, B/A is tensor (scaling) operation of a quaternion, and is versor (rotation) operator of a quaternion. Note that versor of *q* is very similar to Euler's equation. Euler's equation contains an imaginary number *i*, but a quaternion has a vector instead, which is the rotation axis perpendicular to its rotation plane.

Thus, a quaternion is also expressed as the sum of scalar **S**(*q*) and vector **V**(*q*) parts;

Quaternion can be also written as a 2-tuple form, [*s, v*]. A unit quaternion can be represented as , because the tensor of *q* is 1 (B/A = 1 or no scaling).

Let *i, j and k* represent unit vectors orthogonal (perpendicular) each other. We define multiplications and divisions as rotating a unit vector to another at right angle. Note that, this multiplication and division is not numeric algebra. This kind of multiplication and quotient is called geometric. Thus, production or quotient of two unit vectors at right angles to each other produces a unit vector, perpendicular to their plane. And, it reads as *i* operating on *j* (or, rotating from *i* to *j*) produces *k*.

In same manner, we can write other multiplications and divisions;

The square of a unit vector can be defined from above equations;

In same manner,

Also, *ijk* can be defined as -1 using above multiplication table and square of unit vector.

Here, the basic quaternion mathematics is described. These algebraic definitions and properties are specially required for rotation in 3D space, which describe in the next section. You may skip this section and move on the next section. And, come back later if you need to review a specific definition or property.

Note that quaternion multiplication is not commutative, however, multiplication is associative and distributive across addition.

Unlike quaternion multiplication, scalar multiplication is commutative.

Quaternion subtraction can be derived from scalar multiplication and quaternion addition.

Quaternion congugate is defined by negating the vector part of the quaternion.

Note that the multiplication of a quaternion and its conjugate is commutative.

The norm of a quaternion is defined by;

The norm of quaternion is multiplicative meaning that the norm of the multiplication of multiple quaternions equals to the multiplication of the norms of quaternions.

The inverse of a quaternion is defined to be;

The quaternion inverse makes it possible to divide two quaternions.

Note that the inverse of a unit quaternion equals to the conjugate of the unit quaternion.

In 2D, the multiplication of two complex numbers implies 2D rotation. When *z=x+iy* is multiplied by , the length of z' remains same (|z|=|z'|), and the angle of z' is simply added by θ. (See details in Euler's equation.)

However, multiplying a quaternion *p* by another quaternion *q* does not conserve the length (norm) of the vector part of the quaternion *p* even if *q* is a unit quaternion. For example;

Thus, we need a special multiplication for 3D rotations that is length-conserving transformation. For this reason, we multiply the quaternion *q* at the front of *p* and multiplying its inverse *q ^{-1}* at the back of

If a quaternion is *p* = [s, v], then the scalar (s) and the length of v, |v| are unchanged after conjugation by *q*. For the above example;

If *p* = [s, v] and *p'* = *qpq ^{-1}*, then

(The scalar part of

The proof taks 4 steps. First, we show the scalar parts of quaternions, **S**(*p*)=**S**(*p'*) for *p*=[s, 0], and for *p*=[0, v]. Then, both results are used to show **S**(*p*)=**S**(*p'*) for *p*=[s, v]=[s, 0]+[0, v]. Finally, we show the length of *p'* is unchanged (conserved), therefore, the length of the vector part is same, |**V**(*p*)| = |**V**(*p'*)|.

**Step 1**. If *p* has a scalar part only *p* = [s, 0], then

**Step 2**. If *p* has a vector part only *p* = [0, v], then the scalar part of *qpq ^{-1}* can be computed by 2

**Step 3**. If *p* = [s, v] = [s, 0] + [0, v], then **S**(*p*) = **S**(*p'*).

**Step 4**. The norm of *p'* is same as the norm of *p*;

Since the lengths and the scalar parts of *p* and *p'* are same, the lengths of the vector parts are also same;

The rotation with quaternion by can be expressed with matrix from;

If *q* is a unit quaternion, it can be simplified by;

The derivation of matrix conversion is explained here.

- A. S. Hardy (1881). Elements of Quaternions
- E. B. Dam, M. Koch, M. Lillholm (1998). Quaternions, Interpolation and Animation