Quaternions and Spatial Rotation - Using Quaternion Rotations

Using Quaternion Rotations

Any rotation in three dimensions can be represented as a combination of an axis vector and an angle of rotation. Quaternions give a simple way to encode this axis-angle representation in four numbers and apply the corresponding rotation to a position vector representing a point relative to the origin in R3.

Quaternions predate the use of vectors in mathematics, so some of the necessary notation continues to be used in the context of vectors. The, vector notation is such a remnant of this time, where a vector such as or can be rewritten as or .

In extension to Euler's formula, a quaternion rotation can be constructed using the formula:

where is the angle of rotation and the vector is a unit vector representing the axis of rotation. The halves enable the encoding of both clockwise and counter-clockwise rotations. To apply the rotations to a point represented by the position vector, one conducts quaternion multiplication by evaluating the Hamilton product:

where is the new position vector of the point after the rotation, and is the quaternion conjugate of :

Two rotation quaternions can be combined into one equivalent quaternion by the relation:

in which corresponds to the rotation followed by the rotation . (Note that quaternion multiplication is not commutative.) Thus, an arbitrary number of rotations can be recursively composed together and then applied as a single rotation.

A quaternion rotation can be algebraically manipulated into a quaternion-derived rotation matrix. By simplifying the quaternion multiplications, they can be rewritten as a rotation matrix given an axis-angle representation:

 \begin{bmatrix}
c(\theta) + a_x^2 \left(1-c(\theta)\right) &
a_x a_y \left(1-c(\theta)\right) - a_z s(\theta) &
a_x a_z \left(1-c(\theta)\right) + a_y s(\theta) \\
a_y a_x \left(1-c(\theta)\right) + a_z s(\theta) &
c(\theta) + a_y^2 \left(1-c(\theta)\right) &
a_y a_z \left(1-c(\theta)\right) - a_x s(\theta) \\
a_z a_x \left(1-c(\theta)\right) - a_y s(\theta) &
a_z a_y \left(1-c(\theta)\right) + a_x s(\theta) &
c(\theta) + a_z^2 \left(1-c(\theta)\right)
\end{bmatrix}

where and is shorthand for and respectively. Although care should be taken (due to degeneracy as the quaternion approaches the identity quaternion or the sine of the angle approaches zero) the axis and angle can be extracted via:

 \begin{align}
\mathbf{q} & = q_r + q_i i + q_j j + q_k k \\
\theta &= 2 \cos^{-1} q_r = 2 \sin^{-1} \sqrt{q_i^2 + q_j^2 + q_k^2} \\
(a_x, a_y, a_z) &= \frac{1}{\sin \tfrac{1}{2} \theta} (q_i, q_j, q_k)
\end{align}

Note that the equality holds only when the square root of the sum of the squared imaginary terms takes the same sign as .

As with other schemes to apply rotations, the centre of rotation must be translated to the origin before the rotation is applied and translated back to its original position afterwards.

Read more about this topic:  Quaternions And Spatial Rotation