Quaternion rotation demonstration program


qrot demonstrates the problem with using linear interpolation of Euler angles when animating a rotating object in three dimensions, and how great circle interpolation of unit quaternions gives smooth rotation paths.

Basic operation

qrot uses the OpenGL graphics library, which is normally present in Linux and Windows. It may optionally write ASCII text files, but does not otherwise alter its environment.

When the program is started, a three dimensional object and a Cartesian grid are displayed. Click on Move object... menu item to show the 'Object Transformations' dialogue.

Object Transformations

The sliders allow you to rotate the object about the X, Y and Z axes, in that fixed order. The Euler angles are shown in radians. The grid showing parts of the XY and XZ planes may be turned on and off to help with orientation. The size of the grid squares is 100 units.
Rotation axes
Press 'r' or click the box on the 'Object Transformations' dialogue to show the rotation axes, which are represented by a marked ring perpendicular to the axis. Try rotating the X axis (red) with the Y rotn slider until it's coplanar with the Z axis (blue) and notice that you lose a degree of rotational freedom. This is known as 'Gimbal Lock'.
Press 'm' or click the box on the 'Object Transformations' dialogue to show a gimble mount. Note that because of the construction of the gimbal its natural rotation order is XZY, so moving the sliders on the 'Object Transformations' dialogue sometimes has a surprising effect.

When either the rotation axes or the gimbal are enabled the object's translations are suppressed.

Camera adjustment

This dialogue adjusts your viewpoint. The light is positioned at (1000, 1000, -1000) and does not move. It is never visible.

Object animation

You can specify two or more key positions of the object and observe the program generate a smooth path between them.

Try these steps to reveal the use of the buttons:

  1. Click on the Move object... and Animate object... menu items to activate the dialogues.
  2. Click on Animation files and demos... and press Demo 1 to load and run an animation.
  3. Press the Play/Stop/Rewind button. The object will move between the two keys.
  4. Adjust the duration of the animation with the length slider.

Making your own animations

  1. Change the Alpha slider to an appropriate point in the animation.
  2. Rotate the object to a new orientation using the sliders.
  3. Press the Add/Change key button. If alpha is already at a key point, the key will be replaced by the current object position, otherwise a new key will be created.
  4. Repeat 1 - 3 until you have all the key points you want.
  5. Navigate between the keys with the Next key and Previous key buttons.
  6. Delete key removes a key if alpha is actually at a key point, apart from the keys at 0 and 1.

The object's translations are suppressed during animations.

Interpolation type

Euler linear

This is the default method, and linearly interpolates each Euler rotation between the key positions. The intermediate positions are usually not what you want.

Quaternion linear

This option performs a piecewise linear great-circle quaternion interpolation between the keys. The object rotates in the simplest possible way between each key, but the Euler angles often bounce around all over the place.

Quaternion spline

This smooths out the kinks at the key points by splining on the unit quaternion sphere. It is only different from 'Quaternion linear' if there are more than two key-points in the animation.

Animation files

You can save an animation to a file by pressing the Save file button on the Animation files and demos... dialogue box, and load it again later by pressing Load file.


These are pre-recorded animations loaded from the Animation files and demos... dialogue box.

Demo 1 is a rotation about the Z axis only. Linear interpolation of the Euler angles works just as well as great circle interpolation of quaternions in this case.

Demo 2 illustrates why linear interpolation of Euler angles fails. Linear quaternion interpolation produces a smooth simple rotation.

Demo 3 has four key points. Is quaternion splining an improvement over piece-wise linear interpolation in this case?

Demo 4 also has four key points. This time quaternion splining does seem to usefully smooth out the kinks.

Demo 5 demonstrates gimbal flip. It is a very simple move when the rotation order is XYZ, but complex when it is XZY.