Quaternion rotation demonstration program Instructions |
Purposeqrot 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 operationqrot 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 TransformationsThe 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 axesPress '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'.GimbalPress '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 adjustmentThis dialogue adjusts your viewpoint. The light is positioned at (1000, 1000, -1000) and does not move. It is never visible.Object animationYou 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:
Making your own animations
The object's translations are suppressed during animations. Interpolation typeEuler linearThis 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 filesYou 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.DemonstrationsThese 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. |
2nd April 2014 |