Rotation Representations: Quaternions

To overcome the singularity issue of Gimbal Lock found in Euler angles, we can use a different mathematical tool called quaternions.

What is a Quaternion?

At its core, a quaternion is a four-dimensional number. It's an extension of complex numbers, and it's written as:

q=w+xi+yj+zk

where w,x,y,z are real numbers, and i,j,k are the quaternion units.

For 3D rotations, it's more practical to think of a quaternion as having two parts: a scalar part (w) and a 3D vector part (v).

q=[w,v]wherev=[x,y,z]

To represent a rotation, we must use a unit quaternion, which means its magnitude is 1: w2+x2+y2+z2=1.

Quaternions and the Axis-Angle Representation

The real power of quaternions is how elegantly they encode a rotation. A quaternion directly represents a rotation of angle θ around a single, arbitrary unit vector axis u^=[ux,uy,uz].

This problem is really hard using Euler, Rotation-About-An-Axis.

The conversion is given by:

w=cos(θ2)x=uxsin(θ2)y=uysin(θ2)z=uzsin(θ2)

This axis-angle formulation is what allows quaternions to represent any 3D orientation smoothly and without singularities.

Advantages of Quaternions

Disadvantages of Quaternions