« previous | Wednesday, April 23, 2014 | next »
Quaternions and Complex Numbers
how they should be used.
Complex Numbers
Defined by a real and imaginary part:
, where
.
Simple operations:


- Conjugation:
becomes
. What's impressive about this is that
, where 
Relation to Graphics
Given a point
, rotate that point about the origin by
:
Represent
by a complex number:
Rotation is just multiplication by a complex number.
Quaternions
Sir William Rowan Hamilton attempted to extend complex numbers from 2D to 3D, but this is now provably impossible. He discovered a generalization to 4D and wrote it on the side of a bridge in Dublin.
One real part, 3 complex parts:
From this, we get






We can define an algebra on
and
- Multiplication:
- Order matters in quaternion multiplication!
- Conjugation:
, and 
- Inversion:

Relation to Graphics
Claim: unit quaternions represent 3D rotation
Convert from 3D to 4D:
, where
.
, where
.
let
be parallel to the axis of rotation in 3D.
In this case,
. This gives a nonzero real component... uh oh, we now have a 4D number, not a 3D number.
let
be a vector component in the plane normal to
:
represents a positive (ccw) rotation, and
represents a negative (cw) rotation.
Computing
rotates the component of
perpendicular to
by
and leaves the parallel component alone.
Thus the quaternion representing rotation about the unit axis

by

is
, where 
Quaternions vs. Matrices
This seems like magic... This is perhaps the wrong use for quaternions
- Quaternions take less space (4 vs. 9)
- Rotating a vector requires 28 multiplications using quaternions vs. 9 for matrices
- Composing two rotations using quaternions
requires 16 multiplications vs. 27 for matrices
- Quaternions are not hardware-accelerated whereas matrices are.
Quaternions and Interpolation
Unit quaternions represent points on a 4D hypersphere
Interpolation on the sphere gives rotations that bend the least.
Recall we used SLERP to interpolate vectors on the surface of a 3D sphere.
May need to interpolate between
and
.
, where
.
Other Graphics Uses for Quaternions
Skeletal animation: moving bones usually requires a lot of composed rotations.