Quaternions, Interp olation and Animation
Erik B. Dam Martin Ko ch Martin Lillholm
[email protected] [email protected] [email protected]
Technical Rep ort DIKU-TR-98/5
Department of Computer Science
University of Cop enhagen
Universitetsparken 1
DK-2100 Kbh
Denmark July 17, 1998
Abstract
The main topics of this technical rep ort are quaternions, their mathematical prop-
erties, and how they can b e used to rotate ob jects. Weintro duce quaternion math-
ematics and discuss why quaternions are a b etter choice for implementing rotation
than the well-known matrix implementations. We then treat di erent metho ds for
interp olation between series of rotations. During this treatment we give complete
pro ofs for the correctness of the imp ortantinterp olation metho ds Slerp and Squad .
Inspired by our treatment of the di erentinterp olation metho ds we develop our own
interp olation metho d called Spring based on a set of ob jective constraints for an
optimal interp olation curve. This results in a set of di erential equations, whose
analytical solution meets these constraints. Unfortunately, the set of di erential
equations cannot be solved analytically. As an alternative we prop ose a numerical
solution for the di erential equations. The di erentinterp olation metho ds are visu-
alized and commented. Finally we provide a thorough comparison of the two most
convincing metho ds Spring and Squad . Thereby, this rep ort provides a comprehen-
sive treatment of quaternions, rotation with quaternions, and interp olation curves
for series of rotations. i
Contents
1 Intro duction 1
2 Geometric transformations 3
2.1 Translation ...... 3
2.2 Rotation ...... 3
3 Two rotational mo dalities 5
3.1 Euler angles ...... 5
3.2 Rotation matrices ...... 6
3.3 Quaternions ...... 7
3.3.1 Historical background ...... 7
3.3.2 Basic quaternion mathematics ...... 8
3.3.3 The algebraic prop erties of quaternions...... 12
3.3.4 Unit quaternions ...... 14
3.3.5 The exp onential and logarithm functions ...... 15
3.3.6 Rotation with quaternions ...... 17
3.3.7 Geometric intuition ...... 22
3.3.8 Quaternions and di erential calculus ...... 23
3.4 An algebraic overview ...... 26 ii
4 A comparison of quaternions, Euler angles and matrices 27
4.1 Euler angles/matrices | Disadvantages ...... 27
4.2 Euler angles/matrices | Advantages ...... 31
4.3 Quaternions | Disadvantages ...... 31
4.4 Quaternions | Advantages ...... 31
4.5 Conclusion ...... 32
4.6 Other mo dalities ...... 33
5 Visualizing interp olation curves 34
5.1 Direct visualization ...... 34
5.2 Visualizing an approximation of angular velo city ...... 34
5.3 Visualizing the smo othness of interp olation curves ...... 35
5.4 Some examples of visualization ...... 36
6 Interp olation of rotation 38
6.1 Interp olation b etween two rotations ...... 38
6.1.1 Linear Euler interp olation: LinE ul er ...... 38
6.1.2 Linear Matrix interp olation: LinM at ...... 39
6.1.3 Linear Quaternion interp olation: Ler p ...... 40
6.1.4 A summary of linear interp olation ...... 41
6.1.5 Spherical Linear Quaternion interp olation: Slerp ...... 42
6.2 Interp olation over a series of rotations:
Heuristic approach ...... 49
6.2.1 Spherical Spline Quaternion interp olation: Squad ...... 51
6.3 Interp olation b etween a series of rotations:
Mathematical approach ...... 56
6.3.1 The interp olation curve ...... 56
6.3.2 De nitions of smo othness ...... 56
6.3.3 The optimal interp olation ...... 57
6.3.4 Curvature in H ...... 58
1
6.3.5 Minimizing curvature in H : Continuous, analytical solution ...... 60
1
6.3.6 Minimizing curvature in H : Continuous, semi-analytical solution . . . . . 63
1
6.3.7 Minimizing curvature in H : Discretized, numerical solution ...... 64
1 iii
7 Squad and Spring 77
7.1 Example: A semi circle ...... 77
7.2 Example: A nice soft curve ...... 78
7.3 Example: Interp olation curve with cusp ...... 79
7.4 Example: A p endulum ...... 80
7.5 Example: A p erturb ed p endulum ...... 81
7.6 Example: Global prop erties ...... 81
7.7 Conclusion ...... 84
8 The Big Picture 85
8.1 Comparison to previous work ...... 85
8.2 Future work ...... 87
A Conventions 89
B Conversions 90
B.1 Euler angles to matrix ...... 90
B.2 Matrix to Euler angles ...... 90
B.3 Quaternion to matrix ...... 91
B.4 Matrix to Quaternion ...... 93
B.5 Between quaternions and Euler angles ...... 93
C Implementation 94
C.1 The basic structure of quat ...... 95 iv
Chapter 1
Intro duction
To animate means to \bring to life." Animation is a visual presentation of change. Traditionally
this has b een used in the entertainment business, for example Donald Duckmoving in a carto on.
More serious applications have later b een develop ed for physics visualization of particle systems
and chemistry displaying molecules.
This pap er treats a small part of the world of animation | animation of rotation. As a back-
ground for the following chapters, we will in this section giveanoverview of how animation was
done traditionally i. e. b efore the computer, and how it is done now. The presentation is based
on [Foley et al., 1990 ] and [Lasseter, 1987 ].
An animation is based on a story|amanuscript. The manuscript is used to makeastoryboard,
in which it is decided how to split the story into individual scenes. For each scene a sketch is
made with some text describing the scene. Based on the storyb oard, a series of key frames is
pro duced showing the characters of the carto on in key p ositions. The frames between the key
frames can then b e made from these key p ositions. Traditionally, the most exp erienced artists
pro duced the key frames and were therefore named key framers , leaving the frames in-b etween
to the less exp erienced artists who b ecame known as in-betweeners . The animators pro duce a
rough draft of the animation, which is presented at a pencil test. Once the draft is satisfactory,
the nal version is pro duced and transferred to celluloid.
This metho d of animation is called key framing and has since b een used in computer animation
systems. Already in 1968 animation of 3D mo dels was known, and the idea of using computers
for key frame animation was used in 1971 [Burtnyk & Wein, 1971 ].
Computers are natural replacements for the in-b etweeners. Given two key frames, the frames
in-b etween can b e generated byinterp olation. Admittedly there are several problems with this
approach: 1
A translation b etween twokey frames can easily b e obtained by simple linear interp olation.
When the movement consists of more key frames it is necessary to use more advanced
curves for example splines to pro duce a smo oth movement across key frames.
Ordinary physics cannot be used to describ e how the eye p erceives moving ob jects in a
carto on. Ob jects will change shap e as they move: A ball will morph into an oval when
b ouncing fast see gure 1.1. This will not happ en automatically if a computer is used
to animate the motion of the ball.
Animation of rotational movement has also b een attempted using key frames and inter-
p olation. Rotation is more complex than translation, however. The problems involved in
interp olating rotations will b e treated in this pap er.
Figure 1.1: The cartoon version of a bouncing bal l.
Computer animation consists of much more than pure motion. Apart from the problems of
interp olation of the movement there are complicated issues concerning light, sound, colors,
camera angles, camera motion, shadows, physical prop erties of the ob jects b eing mo delled etc.
We limit this pap er to treat metho ds for representation and implementation of rotation. The
metho ds are mostly based on quaternions, a kind of four-dimensional complex numb ers. Through
a series of attempts to de ne \nice" rotation, we derive a mathematical description of rotation
through a series of key frames.
We will not discuss the matters mentioned in the rst two bullets ab ove or the other asp ects
mentioned light, sound etc.
The main foundation for this pap er is the articles [Sho emake, 1985 ], [Barr et al., 1992 ], and
[Watt & Watt, 1992 ]. We do not require any knowledge of these articles. It will, however, b e an
advantage for the reader to b e familiar with the common transformation metho ds using matrices
and to have basic knowledge of interp olation curves in the plane in particular splines . Some
basic mathematics knowledge will also be advantageous group theory, di erentional calculus,
calculus of variations and di erential geometry. 2
Chapter 2
Geometric transformations
In this chapter we will brie y discuss selected transformations of ob jects in 3D. The key topic
will b e rotation but since interp olation b etween p ositions o ers useful parallels to interp olation
of rotation, we include translation. Note that these parallels serve only as inspiration for the
rotational case | mainly b ecause the space of translations is Euclidean while the space of
rotations is not. This di erence will b e discussed in depth in the following chapters.
2.1 Translation
Translation is the most obvious kind of transformation: A p oint in space is moved from one
3
p osition to another. Let a p oint P 2 R be denoted by a 3-tuple x; y ; z ; x; y ; z 2 R and
0
the translation by a vector x; y; z . Then the new p osition P is calculated by simple
0
addition: P =x +x; y +y; z +z . The de nition is non-ambiguous i. e. there exists only
0
one translation vector that takes P to P .
2.2 Rotation
Rotation in 3D is not as simple as translation and it can be de ned in many ways. We have
chosen the following de nition:
We will use the de nition given by Euler's 1707 { y 1783 theorem [Euler, 1752 ] | written in
mo dern notation compare with gure 2.1:
Prop osition 1.
0 3 3
Let O , O 2 R be two orientations. Then there exists an axis l 2 R and an angle of rotation
0
2 ] ; ] such that O yields O when rotated about l .
Note that the prop osition states existence and do es not state uniqueness.
3
We will distinguish between orientations and rotations. An orientation of an ob ject in R is
given by a normal vector. A rotation is de ned by an axis and an angle of rotation. 3
0
O O
l
0 3 3
Figure 2.1: Let O , O 2 R be two orientations. Then there exists an axis l 2 R and an angle
0
of rotation 2 ] ; ] such that O yields O when rotated about l . 4
Chapter 3
Two rotational mo dalities
Euler's theorem prop osition 1 gives a simple de nition of rotations. In most of the literature,
Euler angles are used to de ne rotation. From these two fundamental de nitions, rotation can
be discussed mathematically in numerous ways. We will term the combination of a de nition
and a corresp onding mathematical representation a rotational modality. In this rep ort we will
discuss the following two mo dalities:
Rotation de ned by Euler angles represented by general transformation matrices.
Rotation de ned by Euler's theorem represented by quaternions.
The aim is of this chapter is to reach an implementation of a general rotation with each mo dality.
A comparison of how the mo dalities implement a general rotation is given in chapter 4. Conver-
sion b etween representations of rotation is discussed in app endix B. Finally, general conventions
for rotation used in this rep ort can b e found in app endix A.
In sections 3.1 and 3.2, Euler angles and their matrix representation are describ ed. The descrip-
tion is brief | the reader is assumed familiar with these topics.
Section 3.3 gives an in-depth treatment of quaternions starting of with the basics of quaternion
mathematics. After the intro duction, it is established how quaternions can b e used to represent
rotation as de ned by Euler's theorem.
3.1 Euler angles
The space of orientations can be parameterized by Euler angles. When Euler angles are used,
a general orientation is written as a series of rotations ab out three mutually orthogonal axes in
space. Usually the x, y , and z axes in a Cartesian co ordinate system are used. The rotations
are often called x-roll, y -roll and z -roll.
Euler originally develop ed Euler angles as a to ol for solving di erential equations. Later Euler
angles have b ecome the most widely used metho d of parametererizing the space of orientations. 5
As we shall see b elow, this choice gives rise to anumb er of problems. If wecho ose to consider
a rotation as the action p erformed to obtain a given orientation, Euler angles can be used to
parameterize the space of rotations. To describ e a general rotation as describ ed in section 2.2,
three Euler angles ; ; are required, where , , and are the rotation angles ab out
1 2 3 1 2 3
the x, y , and z axes, resp ectively.
The conversion from a general rotation to Euler angles is ambiguous since the same rotation
can be obtained with di erent sets of Euler angles see [Foley et al., 1990 ]. Furthermore, the
resulting rotation dep ends on the order in which the three rolls are p erformed. This gives rise to
further ambiguity but ts well with the fact that rotations in space do not generally commute
see app endix B. Some of the ambiguity in the conversion to Euler angles can be eliminated
by adopting a convention of which order the rolls should be p erformed. In this pap er, we use
the convention describ ed in app endix A. Intro ducing a convention do es not, however, eliminate
the ambiguity altogether see chapter 4.
3.2 Rotation matrices
Rotation matrices are the typical choice for implementing Euler angles. For each typ e of roll,
there is a corresp onding rotation matrix, i. e. an x rotation matrix, a y rotation matrix, and a
z rotation matrix. The matrices rotate by multiplying them to the p osition vector for a p oint
in space, and the result is the p osition vector for the rotated p oint. A rotation matrix is a
3 3 matrix, but usually homogeneous 4 4 matrices are used instead see [Foley et al., 1990 ]
for further detail. A general rotation is obtained bymultiplying the three roll-matrices corre-
sp onding to the three Euler angles. The resulting matrix emb o dies the general rotation and can
b e applied to the p oints that are to b e rotated.
The three standard rotation matrices are given in homogeneous co ordinates in app endix B.
Matrix multiplication is not generally commutative. This ts well with the fact that rotations
in space do not commute.
Finally it should b e noted that using homogeneous transformation matrices gives the only imple-
mentation that e ectively emb o dies all standard transformations: Translation, scaling, shearing,
and various pro jection transformations. 6
3.3 Quaternions
The second rotational mo dality is rotation de ned by Euler's theorem and implemented with
quaternions. Since quaternions are not nearly as well-known as transformation matrices, and
since no go o d overview of the eld exists, we will give a historical overview and then provide a
thorough treatment of quaternion mathematics.
3.3.1 Historical background
Quaternions were invented by Sir William Rowan Hamilton 1809 { y 1865 in 1843. Hamilton's
aim was to generalize complex numb ers to three dimensions, i. e. numb ers of the form a + i b + jc,
2 2
where a; b; c 2 R and i = j = 1. Hamilton never succeeded in making this generalization,
and it has later b een proven that the set of three-dimensional numb ers is not closed under
multiplication. In 1966 Kenneth O. Maygave the following elegant pro of of this:
Prop osition 2.
The set of three-dimensional complex numbers is not closed under multiplication.
Pro of freely adopted from Kenneth O. May 1966:
2
2
Assume that the usual rules of arithmetic for complex numb ers hold, and that i = j = 1.
The pro of is by contradiction, so we assume that a closed multiplication exists. Since multi-
plication is closed, there exist a; b; c 2 R that satisfy ij = a + ib + jc. Multiplying this with
i yields j = b + ia + ijc. Substituting the rst equation in the second equation yields
2