ROBOTICS 101Concept explainer

Quaternions and Interpolation (Slerp)

A quaternion stores a rotation as four numbers with no gimbal lock. Its biggest practical win is smooth interpolation. Slerp turns from one orientation to another along the shortest path at a steady rate, which is what you want for a camera or a robot wrist.

Drag the 3D view to look from another angle.

Quaternions

A rotation by angle \(\theta\) about unit axis \(\hat{\mathbf{k}}\) is the unit quaternion

$$q = \left(\cos\tfrac{\theta}{2},\ \hat{\mathbf{k}}\sin\tfrac{\theta}{2}\right) = (w, x, y, z), \qquad w^2 + x^2 + y^2 + z^2 = 1$$

Note that \(q\) and \(-q\) are the same rotation.

Slerp

Spherical linear interpolation moves along the great circle between two quaternions, where \(\Omega\) is the angle between them:

$$\operatorname{slerp}(q_0, q_1; t) = \frac{\sin\big((1 - t)\,\Omega\big)}{\sin\Omega}\,q_0 + \frac{\sin(t\,\Omega)}{\sin\Omega}\,q_1, \qquad \cos\Omega = q_0 \cdot q_1$$

What to notice

The red path of the nose under slerp is a clean arc. The gray path from blending yaw, pitch, and roll separately wanders, takes longer, and the body wobbles along the way. Slerp also picks the shorter of the two ways around by flipping \(q_1\) to \(-q_1\) when needed. ROS 2 and most robotics libraries store orientations as quaternions for these reasons.