Quaternions: The Movie, Scene 1

Опубликовано: 16 Июль 2026
на канале: TheWyrdSmythe
208
3

So I've been messing around with quaternions...

This is an initial bit of fun applying them that also tests the Python classes I wrote to implement vectors, quaternions, and some simple (really simple) 3D image generation.

This little effort, Scene 1, stitches 5000 frames of rotation PNGs into an mpeg. In this scene, a fixed quaternion rotates another, which rotates yet another. Each has a different rate of rotation, and the last one rotates the box.

The red, green, and blue vectors show the progressive rotation. (Notice how the blue vector and the blue box match.) The gray one just sums the three individual vectors.

As it turns out, quaternions aren't that hard for rotations (there is way more to them for mathematicians, obviously). I found there were two main tricks:

The whole ijk thing. There's tendency to want to think of them as three different names for good old i. But that's wrong. It's better to think of them like you do x, y, and z, because they're really basis vectors for three orthogonal complex planes.

Quaternion multiplication. Ya just have to work through it. The wiki article has all you need to know. But forget that multiplication table, and just remember the ijk circle. Forward, ij = k, jk = i, ki = j (remember, it wraps around). Going backwards gives you negative values: kj = -i, ji = -k, ik = -j.