Quaternions are also another convenient rotation representation based on an extension of complex numbers. Unit complex number with can represent 2D rotations because complex multiplication performs rotation:

where the real and imaginary components are respectively the x and y component of a point (p,q) rotated by θ . A long search in the 19th century to find analogues of complex numbers that could perform 3D rotations yielded the quaternion representation.
Quaternions (q0,q1,q2,q3) are composed of 1 real coordinate q0 and three imaginary coordinates q1 , q2 , and q3 that represent a complex number

where i , j , and k are imaginary numbers defined such that




Note that these multiplication rules are non-symmetric. The product of two quaternions is a non-symmetric operation that is defined by applying standard distributive laws and the above rules:

Norms are defined as usual so that defines a unit quaternion. Unit quaternions have the special property that their inverse is simply the negation of their imaginary components:

Given a 3D point p=(x,y,z) and its representation as a quaternion p=(0,x,y,z), there is an operation called the conjugation of p by a unit quaternion q so that the result gives a rotated point

More specifically, the quaternion is related to axis-angle representation using the conversion
Also, the rotation matrix defined by a quaternion is given by:

1. Double cover of 4 sphere

Quaternions are similar to points on a 4-D unit sphere, but they have the property that a quaternion and its negative produce equivalent rotations. This can be easily seen from the conjugation equation:

As a result, the space of rotations could be thought of as a 4-D sphere except warped so that points on the opposite sides of the sphere are mapped to the same rotation. This representation makes certain operations, like interpolation, somewhat more difficult to perform than on a sphere.

2. Composition

Quaternions have slight advantages over rotation matrices when performing rotation composition because quaternion products perform composition. This operation requires 16 multiplications and 12 additions / subtractions in ( 30 ) as compared to 27 multiplications and 18 additions for standard matrix multiplication.

3. Geodesic interpolation

An operation called spherical linear interpolation, or "slerp, " can be used to perform geodesic interpolation of rotations using quaternions. More generally it can be used to interpolate across great circles on spheres of arbitrary dimension.

The process is as follows. Given two quaternions q and p , the operation first needs to figure out which sign of p to assign in order to choose the closer way around the 4-D sphere. Specifically, if the dot product of q and p , q⋅p , is negative, then the sign of each element of p is flipped. (This step is specific to quaternion rotation interpolation, and skipped for general slerp on spheres.)

Next, the angle θ between the two quaternions is computed according to .Finally, the interpolated quaternion is given by
It can be shown that this is a geodesic and interpolates across the great circle at constant velocity.