A unit quaternion is four numbers that represent a 3D rotation without the jumps and gimbal lock of Euler angles. ROS, IMUs and game engines use them for orientation. It is closely related to the axis-angle form in SO(3) & Rotation Vector.

Definition

  • a rotation by angle about a unit axis is
  • for a rotation,
  • and give the same rotation (double cover)
  • ROS messages store the order as , while many maths libraries use , a common source of bugs

Yaw-Only Quaternion

For a ground robot that only turns about by heading :

Composition

  • rotating by then (both in the fixed frame) is the product
  • the product is not commutative, so order matters
  • is the vector part

Rotating A Vector

Yaw From A Quaternion

Zeroing A Heading

To make a sensor's heading start at zero:

  • read the first heading
  • build the yaw-only quaternion for
  • multiply it on the left of every later reading, which rotates in the world frame, so only the heading shifts and roll and pitch stay correct

Why Use Them

  • no gimbal lock, and smooth interpolation (slerp) between orientations
  • only 4 numbers and cheap to compose
  • re-normalise after many multiplications, because rounding slowly breaks the unit length