P

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.

Properties

  1. Addition and subtraction: Quaternions can be added and subtracted component-wise, similar to vectors.
qa±qb=[sa±sb,va±vb]
  1. Multiplication: Quaternion multiplication is not commutative (i.e., qaqb≠qbqa). The multiplication of two quaternions combines their rotations.
    Pasted image 20250929230222.png
qaqb=[sasb−vaTvb,savb+sbva+va×vb]
  1. Conjugate: The conjugate of a quaternion q=[w,v→] is given by q∗=[w,−v→]. This operation is useful for reversing rotations.
q∗q=qq∗=[s2+vTv,0]T
  1. Norm: The norm (or magnitude) of a quaternion is given by ||q||=w2+x2+y2+z2. For unit quaternions, this norm is 1.
  2. Inverse: The inverse of a unit quaternion q is simply its conjugate, i.e., q−1=q∗. Otherwise it's given by:
q−1=q∗||q||2
  1. Rotation of a vector: To rotate a vector p→ in 3D space using a quaternion q, we first represent the vector as a pure quaternion p=[0,p→]. The rotated vector p′ is obtained by:
p′=qpq−1

Pasted image 20250929230627.png

Conversion Between Quaternions and Other Representations

From Quaternion to Rotation Matrix

A unit quaternion q=[w,x,y,z] can be converted to a 3x3 rotation matrix R using the following formula:

R=[1−2(y2+z2)2(xy−wz)2(xz+wy)2(xy+wz)1−2(x2+z2)2(yz−wx)2(xz−wy)2(yz+wx)1−2(x2+y2)]

Advantages of Quaternions

Disadvantages of Quaternions