Quaternions demystified, grand finale

(Read part one and the intermezzo first)

Before getting into quaternion rotations, let’s look at axis-angle rotations.

They are like Euler rotations, but not only around the X-, Y- and Z-axis, but around any axis (think of the picture in part one).

In Blender, you get 4 fields: W (the angle of rotation), X, Y and Z (the vector around which you rotate).

Now try this: choose any vector you want, but set the angle to 179°. Keyframe that value and set the angle at -179 at frame 23 or so and keyframe that value as well. Play the animation and you will see a rotation of -358°. This might be what you want, but imagine that you want a character’s hand to rotate a few degrees and it does something like this…

So we need something ‘better’ to describe  3D rotations. This is where quaternions come in and save the day.

Imagine a ‘copy’ of the 3D space we know and put it perpendicular to our 3D space. Let’s call this an imaginary 3D world. As this is a ‘copy’, we can make a direct ‘connection’ between any point in our world and the imaginary one. We can take Suzanne and put her in the corresponding place and orientation in the imaginary space.

You can think of a quaternion rotation as an axis-angle rotation performed in the imaginary world (twice!).

Under the hood, Blender takes the axis of rotation, divides it by it’s length, puts it in the imaginary world, along with the object that needs to be rotated, rotates it twice (uses a ‘sandwich multiplication’ by the quaternion, similar to the complex multiplication in the intermezzo) the first multiplication creates a real component, meaning we are now in a 4 dimensional world, the second multiplication (by the conjugate of the quaternion) brings it back in the imaginary 3D world and then Blender puts the rotated object back in the real world.

Compared to axis-angle, where the angle is in the W field and the axis vector in the X, Y, Z fields,

a quaternion has the angle represented in all 4 fields.

Mathematically (this is not important for us):

If the vector for the axis of rotation is (x, y, z), then:

W = cos(angle/2)

X = x*sin(angle/2)

Y = y*sin(angle/2)

Z = z*sin(angle/2).

Due to some clever properties of the imaginary components in this 6 dimensional space, we can now easily perform different rotations after one another (it’s just ‘sandwich multiplications’) and smoothly interpolate between rotations.

Usually, you do not want to fiddle with the numbers in the quaternion directly. They are hard to get 'right'.

(A quaternion in Blender for a rotation should be of length 1)

You can fill in the fields in an axis-angle and then switch to quaternion, if you want.

(The term quaternions in the title is short for/should actually be quaternion rotations.)