<<

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 , their mathematical prop-

erties, and how they can b e used to rotate ob jects. Weintro duce math-

ematics and discuss why quaternions are a b etter choice for implementing

than the well-known implementations. We then treat di erent metho ds for

interp olation between series of . 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 ...... 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 , 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

j = b + ia +a + ib + jcc,i.e.0=ac b+ia + bc+jc + 1. Thus ac b =0; a + bc =0

2 2

and c +1=0. The equation c +1=0gives the contradiction, since c is real by assumption.

2

One of Hamilton's motivations for seeking three-dimensional complex numb ers was to nd a

description of rotation in space corresp onding to the complex numb ers, where a multiplication

corresp onds to a rotation and a scaling in the plane.

While walking by the Royal Canal in Dublin on a Monday in Octob er 1843, Hamilton realized

that four numb ers are needed to describ e a rotation followed by a scaling. One numb er describ es

the size of the scaling, one the number of degrees to be rotated, and the last two numb ers

1

give the plane in which the vector should be rotated. After this insight, Hamilton found a

closed multiplication for four-dimensional complex numb ers of the form ix + jy + kz , where

2 2 2

i = j = k = ijk = 1. Hamilton dubb ed his four-dimensional complex numb ers quaternions.

The parallel to ordinary complex numb ers stems from the imaginary parts.

3

A quaternion is usually written [s; v ];s 2 R ; v 2 R . Here s is called the scalar part, and

v =x; y ; z  is the vector part.

1

The xy plane can b e rotated to any plane in xy z space through the origin by giving the rotation angles ab out

the x and y axes. 7

Historical aside

Hamilton presented quaternion mathematics at a series of lectures at the Royal Irish Academy.

The lectures gave rise to a b o ok [Hamilton, 1853 ], the full title of which with typ ographyasin

the b o ok is:

Lectures on Quaternions: Containing a systematic statement of

A New Mathematical Method

of which the principles were communicated in 1843 to the royal Irish

academy; and which has since formed the subject of successive courses

of lectures, delivered in 1848 and subsequent years in the halls of

trinity college, Dublin: with numerous illustrative diagrams, and with

some geometrical and physical applications.

In the b o ok page 271 Hamilton writes again imitating the b o ok's typ ography:

285. We know then how to interpret in two apparently di erent ways, which are, however,

easily p erceived to have an essential connection with each other, the following symbol of

operation,

1

q q ;

where q may b e called as b efore the operator quaternion while the symb ol supp ose r of

the operand quaternion is conceived to o ccupy the place marked by the parentheses. For

wemay either consider the e ect of the op eration, thus symb olized, to b e as in 282, 283

a conical rotation of the axis of the operand round the axis of the operator, through double

the angle thereof, in such a manner as to transport the vertex of the representative angle

of the op erand to a new position on the unit sphere, without changing the magnitude of

2

that angle, nor the tensor of the quaternion thus op erated on: or else, at pleasure, may

regard by 285 the op eration as causing one extremity of the representative arc of the

same operand r  to slide along the doubled arc of the same operator q , without any

change in the length of the arc so sliding, nor of its inclination to the great circle along

which its extremitythus slides.

The historically interested reader is referred to [Hamilton, 1899 ] and [Hallenb erg et al., 1993 ]

only available in Danish.

3.3.2 Basic quaternion mathematics

In this section we will state the notation used for quaternions and establish quaternion mathe-

matics including addition, multiplication, subtraction, and multiplication with a scalar. Finally

we de ne the conjugate and the inverse of a quaternion.

2

In mo dern usage = norm. 8

Notation

We use to mean equal by de nition. Closed intervals on the real line are denoted by[a; b]

f x j a  x  b; a; b; x 2 R g . A semi-op en interval is, for example, denoted by]a; b] f x j a<

x  b; a; b; x 2 R g. The set of n times di erentiable functions from A to B with continuous

n

derivatives we denote C A; B .

De nition 1.

The set of quaternions is denoted H .

3

Quaternions consist of a scalar part s 2 R andavector part v =x; y ; z  2 R . We will use the

following forms:

De nition 2.

2 2 2

Let i = j = k = ijk = 1; ij = k and ji = k. Then q 2 H can be written:

3

q [s; v ] ; s 2 R ; v 2 R

[s; x; y ; z ] ; s; x; y ; z 2 R

s + ix + jy + kz ; s; x; y ; z 2 R

3

We will identify the set of quaternions f[s; 0] j s 2 R g with R and the set f[0; v ] j v 2 R g with

3

R .

De nition 3.

0 0 0 0 0 0

Let q; q 2 H where q =[s; x; y ; z ] and q =[s ; x ;y ;z ]. The addition operator, +, is de ned

0 0 0 0 0 0 0 0 0 0 0

q + q [s; v ]+[s ; v ] [s; x; y ; z ] + [s ; x ;y ;z ] s + ix + jy + kz +s + ix + jy + kz 

Prop osition 3. Quaternion addition

0 0 0 0 0 0 0

Let q; q 2 H , where q =[s; v ] and q =[s ; v ]. Then q + q =[s + s ; v + v ]

Pro of of prop osition 3

0 0 0

q + q [s; v ]+[s ; v ]

0 0 0 0

s + ix + jy + kz +s + ix + jy + kz 

0 0 0 0

= s + s +ix + x +jy + y +kz + z 

0 0

[s + s ; v + v ]

2

De nition 4.

0 0 0 0 0 0

Let q; q 2 H where q = s + ix + jy + kz and q = s + ix + jy + kz . Multiplication is de ned

0 0 0 0 0 0 0 0 0 0 0

qq [s; v ][s ; v ] [s; x; y ; z ][s ; x ;y ;z ] s + ix + jy + kz s + ix + jy + kz 

Prop osition 4. Multiplication of quaternions

0 0 0 0 0 0 0 0 0 0

Let q; q 2 H , where q =[s; v ] and q =[s ; v ]. Then qq =[ss v  v ; v  v + sv + s v ], where

3

 and  denote the scalar and vector product in R , respectively. 9

Pro of of prop osition 4

From de nition 2 the following identities can be obtained from simple algebra: jk = i; kj =

i; ik = j and ki = j. These identities are used in:

0 0 0

qq [s; v ][s ; v ]

0 0 0 0

s + i x + jy + k z s + ix + jy + kz 

0 0 0 0 0 0 0 0

= ss xx + yy + zz +isx + s x + yz zy +

0 0 0 0 0 0 0 0

jsy + s y + zx xz +ksz + s z + xy yx 

0 0 0 0 0

[ss v  v ; v  v + sv + s v ]

2

Corollary 1. to prop osition 4

Quaternion multiplication is not general ly commutative.

Pro of of prop osition 1

We give a counter-example: ij = k, but ji = k.

2

Below we will give a number of prop ositions without pro of. The pro ofs are all based on the

principle used ab ove: The constituent quaternions are written s + ix + jy + kz . Then, using

simple algebra and collection of terms, the result can b e written as a quaternion using de nition

2.

We state the following prop erties of quaternion multiplication:

Prop osition 5.

0

Let p; q ; q 2 H and r 2 R . Then:

0 0

pq q = pqq  Quaternion multiplication is associative. 

0 0

pq + q  = pq + pq Quaternion multiplication distributes

0 0

q + q p = qp + q p across addition. 

Multiplying quaternions by a scalar is most easily intro duced by identifying r 2 R with the

quaternion [r; 0]:

De nition 5.

Let q 2 H and r 2 R . Multiplication by a scalar is de ned

rq [r; 0]q

Prop osition 6. Multiplication with a scalar

Let q 2 H , where q =[s; v ] and let r 2 R . Then rq = qr =[r; 0][s; v ]=[rs; rv ].

Note that the prop osition gives that multiplication with a scalar is commutative.

q 1

We will use the notation to mean q , where q 2 H and r 2 R .

r r

We can nowintro duce subtraction in the usual manner: 10

De nition 6.

0 0 0

Given q; q 2 H , subtraction is de ned q q q +1q

The de nition gives the exp ected:

Prop osition 7. Quaternion subtraction

0 0 0 0 0 0 0 0

Let q; q 2 H , where q =[s; v ] and q =[s ; v ]. Then q q = q +1q =[s s ; v v ].

Corresp onding to the de nition of the conjugate of a complex numb er, we de ne the conjugate

of a quaternion:

De nition 7.

  

Let q 2 H . Then q is cal led the conjugate of q and is de ned by q [s; v ] [s; v ].

The de nition gives rise to the following prop erties:

Prop osition 8.

Let p; q 2 H . Then:

         

i q  = q ii pq  = q p iii p + q  = p + q iv qq = q q .

The norm of a quaternion is obtained using conjugation:

De nition 8.

p



Let p 2 H and let the mapping kk : H yR be de ned by kq k qq . This mapping is cal led

the norm and kq k is the norm of q .

That this mapping is a norm in the usual sense is shown in the corollary to prop osition 9. The

norm mapping has a number of interesting prop erties that are summarized in:

Prop osition 9.

0

Let q; q 2 H and let kk : H yR be given as is de nition 8. The fol lowing equations hold:

p

p

2 2 2 2 2

s + v  v = s + x + y + z 3.1 kq k =



kq k = kq k 3.2

0 0

kqq k = kq kkq k 3.3

Pro of of prop osition 9

The equations 3.1 and 3.2 can b e seen directly. Equation 3.3 follows from:

p p p p p

0 0

0 0  0 0  0 2   0 2 2 0 2

kqq k = qq qq  = qq q q = q kq k q = qq kq k = kq k kq k = kq kkq k

2

We will later need the inner pro duct of two quaternions. We also want to show that the norm

mapping is indeed a norm in the usual mathematical sense. From equation 3.1 in prop osition 9

it follows that the norm of a quaternion q can b e written as it is usually obtained from the inner

4

pro duct if q 2 H is identi ed with the corresp onding vector in R . This prop erty is formalized

by: 11

De nition 9.

0 0 0 0 0 0 0 0

Let q; q 2 H; q =[s; v ]=[s; x; y ; z ]; q =[s ; v ]=[s ; x ;y ;z ]. The inner product is de ned

0 0 0 0 0 0 0

as : H  H yR where q q = ss + v  v = ss + xx + yy + zz :

 

2 2 2 2

Note that the de nition yields q q = s + x + y + z , which gives rise to:



Corollary 2. to prop osition 9

p

The norm of a quaternion q can be obtained by kq k = q q . Furthermore, kk is a norm in



the usual mathematical sense.

Pro of of corollary 2

That computes the norm squared follows directly from prop osition 9 and de nition 9. Now



4

let q =[s; x; y ; z ] 2 H . If we identify q with s; x; y ; z  2 R , the ab ove metho d of computing

4

the norm is identical to the usual Euclidean norm on R . Thus the quaternion norm is a norm

in the usual sense.

2

We will later need the following generalization of the two- and three-dimensional cases:

Prop osition 10.

0 0

Let q; q 2 H . De ne q; q as the corresponding four-dimensional vectors and let be the angle

0 0

between them. Then q q = kq kkq k cos .



3.3.3 The algebraic prop erties of quaternions.

In this section we prove that the set of quaternions H nf[0; 0; 0; 0]g is a non-Ab elian group

under quaternion multiplication. At the end of the section we give a summary of some other

algebraic prop erties of quaternions.

De nition 10.



The set of quaternions H nf[0; 0; 0; 0]g is written H

We will base the discussion on the de nition of a group:

De nition 11.

Let G bea set with an operator  : G  G y G de ned by a; b ! a  b ab. G is a group if

i abc=abc for al l a; b; c 2 G The operator is associative

ii Exactly one I 2 G exists such that Ia = aI = I is the neutral element

a for al l a 2 G.

1

iii For every a 2 G there exists an element a is the inverse element of a

1 1 1

a 2 G, such that aa = a a = I .

If ab = ba for al l a; b 2 G, G is cal led an Abelian or commutative group.



That there exists a neutral element and inverse elements in H under quaternion multiplication

is shown in the following two lemmas: 12

Lemma 1.



The element I =[1; 0] 2 H is the unique neutral element under quaternion multiplication.

Pro of of lemma 1

Let q 2 H b e given. Prop osition 6 gives qI = Iq =[1s; 1v ]=[s; v ]=q .

Thus I is a neutral element. I is also the only element that meets the requirements. To see

this, assume that J also meets the requirements. Then IJ = I , b ecause J is a neutral element.

Furthermore, IJ = J , since I is a neutral element. This gives us that I = IJ = J , so I = J is



the only neutral elementinH.

2

Lemma 2.



1 1 1 1

Let q 2 H . Then there exists q 2 H such that qq = q q = I . Furthermore q is unique

and given by:



q

1

q =

2

kq k

Pro of of lemma 2



Let q 2 H b e given.

Uniqueness

Let b oth p ;p 2 H be inverse to q . That p and p are equal follows from

1 2 1 2

p = p I = p qp =p q p = Ip = p

1 1 1 2 1 2 2 2

Existence



q

Let p = . Then

2

kq k

  2

q qq kq k

qp = q = = =1 I

2 2 2

kq k kq k kq k

  2 

q q qq kq k q

q = = = =1 I pq =

2 2 2 2

kq k kq k kq k kq k



Thus every quaternion in H has an inverse.

2

p

1 1

for pq . Note that this is generally di erent from q p since quaternion We will write

q

multiplication is not commutative.

We can now state the following:

Prop osition 11.



The set H is a non-Abelian group under quaternion multiplication.

Pro of of prop osition 11

Note that the set of quaternions is closed under multiplication. This follows directly from Ham-

ilton's de nition. The rst requirement from the de nition of a group follows from prop osition

5. The second and third requirements follow from lemmas 1 and 2. The group is not Ab elian,

since quaternion multiplication is not commutative.

2 13

Other algebraic prop erties

The set of quaternions satisfy some other algebraic prop erties that are worth mentioning. These

are given without further ado:

 The set of quaternions is an Ab elian group H; + under quaternion addition.

 The set of quaternions is a non-Ab elian ring H; +; , where + and  are quaternion

addition and multiplication.

3.3.4 Unit quaternions

This section discusses a subset of the quaternion group | the set of unit quaternions.

De nition 12.

Let q 2 H . If kq k =1, then q is cal led a unit quaternion. We wil l use H to denote the set of

1

unit quaternions.

The set of unit quaternions constitutes a unit sphere in four-dimensional space. We shall later

see that the set of unit quaternions play an imp ortant part in relation to general rotations. The

following prop ositions lead to the imp ortant prop osition 21. the following:

Prop osition 12.

0 3 0

Let q =[s; v ] 2 H . Then there exists v 2 R and 2 ] ; ] such that q = [cos ; v sin ].

1

Pro of of prop osition 12

0 3

If q =[1; 0]we let = 0 and v can b e freely chosen amongst unit vectors in R .

1

0 0 0 3

If q 6=[1; 0] we let k = jv j and v = v . Then v = k v where v is a unit vector in R . Since q

k

is a unit quaternion, we get

2 2 2 2 0 0 2 2

1=kq k = s + v  v = s + k v  v = s + k

2 2

The equation s + k = 1 describ es a circle in the plane. Since a circle is also describ ed by

2

2

cos + sin = 1, there exists 2 ] ; ] such that s = cos and k = sin . All in all we get

the desired:

0 0

q =[s; v ]=[s; v k ] = [cos ; v sin ]

2

Two imp ortant results for unit quaternions are given in:

Prop osition 13.

0

Let q; q 2 H . The fol lowing two equations hold:

1

0 1 

i kqq k =1 ii q = q

Pro of of prop osition 13

0 0 0

i kqq k = kq kkq k = 1, since kq k = kq k =1. by equation 3.3 in prop osition 9

1  2 

ii q q =kq k = q , since kq k =1.

2 14



The set of unit quaternions H is obviously a subset of H , but de nition 13 and prop osition 14

1



give that H constitute a subgroup of H .

1

De nition 13.

Let G bea group and F 6= ? be a subset of G. F is a subgroup of G if

i For al l a; b 2 F : ab 2 F F is closed

1

ii For al l a 2 F : a 2 F

Prop osition 14.



The set H of unit quaternions is a subgroup of the group H .

1

Pro of of prop osition 14

0 0 0

Let q; q 2 H . Prop osition 13 gives that kqq k = 1, i. e. that qq 2 H , and thus the rst

1 1

subgroup requirement is satis ed. Equation 3.2 in prop osition 9 and prop osition 13 give that

1 

kq k = kq k = kq k =1

1

and thereby the second subgroup requirement q 2 H .

1

2

3.3.5 The exp onential and logarithm functions

We will later need quaternion versions of the real exp onential and logarithm functions. The

de nitions and a few consequences of them are given here see [Pervin & Webb, 1992 ] for further

detail.

De nition 14.

Let q 2 H , where q = [cos ; sin v ] as in proposition 12. The logarithm function log is de ned

1

log q [0; v ]

Note that log [1; 0; 0; 0] = [0; 0; 0; 0] as in the real case. Note also that log q is not in general

a unit quaternion.

The exp onential function is intro duced by

De nition 15.

3

For a quaternion of the form q =[0; v ]; 2 R ; v 2 R ; jv j =1, the exponential function exp

is de ned by

exp q [cos ; sin v ]

Note that the exp onential and logarithm functions are mutually inverse, and that exp maps into

H .

1

From the ab ove de nitions we can de ne exp onentiation for q 2 H ;t 2 R :

1 15

De nition 16.

t

Let q 2 H ;t 2 R . Exponentiation q is de ned by

1

t

q expt log q 

This gives rise to the following:

Prop osition 15.

t

Let q 2 H ;t 2 R . Then log q =t log q .

1

Pro of of prop osition 15

t

log q  = log exp t log q  = t log q

2

The following rule from R also holds for unit quaternions:

Prop osition 16.

Let q 2 H ;q = [cos ; sin v ] and a; b 2 R . Then

1

a b a+b

q q = q

Pro of of prop osition 16

a b

q q = expa log q  expb log q 

= expa[0; v ] exp b[0; v ]

= [cos a ; v sin a ][cos b ; v sin b ]

= [cos a cos b sin a sin b v  v ; v cos a sin b + v cos b sin a +v  v  sin a sin b ]

= [cos a cos b sin a sin b ; v cos a sin b + cos b sin a ]

= [cos a + b ; sina + b v ]

= exp[0; a + b v ]

= expa + b log q 

a+b

= q

2

a b ab

Another rule from the real numb ers is p  = p . This rule also holds for unit quaternions:

Prop osition 17.

a b ab

Let p 2 H and a; b 2 R . Then p  = p

1

Pro of of prop osition 17

a b b ab

p  = expa log p = expb log exp a log p = expba log p=p

2 16

One must be very careful when using exp and log as the corresp onding real versions. For

example, consider the following incorrect derivation, where p and q are unit quaternions.

pq = explog pq  = explog p + log q  = explog q  + log p = explog q  exp log p = qp

This is inconsistent with the fact that quaternion multiplication is not commutative. The error

lies in the second step where the rule log pq = log p + log q  is used | this rule do es not hold

for quaternions.

3.3.6 Rotation with quaternions

Hamilton sought to describ e rotations in space, just as complex numb ers describ e rotations in

the plane. That quaternions do, in fact, p erform rotation, is shown in the following prop ositions

prop osition 21 in particular.

Prop osition 18.



1 1

Let p 2 H , p =[s; x; y ; z ] = [s; v ] and let q 2 H . If r 2 R nf0g then rqprq = qpq .

Pro of of prop osition 18

1 1

Let r 2 R nf0g. The inverse of rq is q r . Since scalar multiplication is commutative we

1 1 1 1 1 1 1

can write: rqprq = rqpq r = qpq rr = qpq . Thus qpq is unchanged if q is

multiplied byany non-zero scalar. 2

In the prop ositions b elow, we will only consider unit quaternions, since results shown for H

1



generalize to all of H by prop osition 18.

Prop osition 19.

1 0 0 0 0

Let q 2 H ; p =[s; v ] 2 H . Then qpq = p , where p =[s; v ] with jv j = jv j.

1

Pro of of prop osition 19

Belowwe write S q  for the scalar part of q .

0

The pro of consists of three steps. We rst show S p =S p for p 2f[s; 0] j s 2 R g and then

3

for p 2f[0; v ] j v 2 R g. Finally these results are used to show the prop osition for p 2 H .

0

If p is a scalar represented as a quaternion, S p  = S p follows from simple algebra. Let

p =[s; 0], then:

1 1 1

qpq = q [s; 0]q =[s; 0]qq =[s; 0]

Wehave used that multiplication with a scalar commutes prop osition 6.

Corresp ondingly, we will now show that the same result holds for a vector v represented as a

quaternion [0; v ].



The scalar part S q  of a quaternion q can be computed by 2S q  = q + q . We show the

prop osition for a quaternion with 0 in the scalar part p =[0; v ]: 17

1 1 1 

2S qpq  = qpq +qpq 

  

= qpq +qpq 

  

= qpq + qp q Prop ositions 5 and 8

 

= q p + p q Prop osition 5



= q 2S pq

= 2S p The ab ove result

= 0 Since p =[0; v ]

Now let p 2 H , p =[s; v ]=[s; 0]+[0; v ].

1 1

qpq = q [s; 0]+[0; v ]q

1 1

= q [s; 0]q + q [0; v ]q Prop osition 5 

0

= [s; 0]+[0; v ] The twoabove results

0

= [s; v ]

0 0 0 1

All in all S p  = S p. Since q 2 H , prop osition 9, equation 3.3 gives kp k = kqp q k =

1

1 0

kq kkpkkq k = kpk. Since s is unchanged, it must b e the case that jv j = jv j.

2

Corollary 3. to prop osition 19

3  0 

Let q 2 H ; p =[a; bv ] 2 H where a; b 2 R and v 2 R . If q [a; v ]q =[a; v ], then q [a; bv ]q =

1

0

[a; bv ].

Pro of of prop osition 3

 

qpq = q [a; bv ]q

a



= qb[ ; v ]q

b

a

0

= b[ ; v ] Prop osition 19

b

0

= [a; bv ]

2

We will later need the following useful rule:

Prop osition 20.

t   t

Let q; p 2 H ;p = [cos ; sin v ];t 2 R . Then qp q =qpq  .

1

Pro of of prop osition 20

0 3  0

By corollary 3 there exists v 2 R such that q [cos ; sin v ]q = [cos ; sin v ]. We get

t  

qp q = q expt log pq



= q expt[0; v ]q De nition 14



= q exp[0;t v ]q



= q [cos t ; sin t v ]q De nition 15

0

= [cos t ; sin t v ] Corollary 3

0

= expt[0; v ]

0

= expt log [cos ; sin v ]



= expt log qpq 

 t

= qpq 

2 18

We are now ready to show the main theorem of this section inspired by[Watt &Watt, 1992 ].

Prop osition 21.

3 0 1

Let q 2 H ; q = [cos ; sin n]: Let r =x; y ; z  2 R and p =[0; r] 2 H . Then p = qpq is p

1

rotated 2 about the axis n.

Pro of of prop osition 21

We rst show how a vector r is rotated degrees ab out n, using sine, cosine, and the scalar

and vector pro ducts. We then show that the same result is obtained through rotation with

quaternions.

Assume therefore that r is to b e rotated to R r ab out an axis given by the unit vector n see

gure 3.1.

R r r

n

Figure 3.1: The vector r is rotated to R r about an axis given by the unit vector n.

The vector r can b e written as a sum of two comp onents, r and r , where r is the pro jection

?

k k

of r on n, and r is orthogonal to n see gure 3.2. We get

?

r = r  nn, and

k

r = r r = r r  nn

?

k

To see how the rotation a ects r, we place a two-dimensional co ordinate system in the plane

that is orthogonal to n and contains the p oints designated by r and R r. To do this, we need a

vector v that is orthogonal to r and n:

?

~

v = n  r = n  r r  nn=n  r n  r  nn = n  r 0 = n  r

? 19

R r

r

v

r

?

r

k

n

Figure 3.2: In the two-dimensional coordinate system orthogonal to n, R r can be written

?

R r = r cos + v sin .

? ?

From gure 3.2 we see that R r's comp onent orthogonal to n,R r ,isgiven by

?

R r = r cos + v sin :

? ?

Wenow get:

R r = R r +R r

?

k

= r + r cos + v sin

?

k

= r  nn +r r  nn cos + v sin

= r  nn r  nn cos + r cos + v sin

= 1 cos r  nn + r cos +n  r sin 3.4

We will now examine the e ect of applying a quaternion to a vector, and see that we get the

same result as in equation 3.4.

1

We now lo ok at R p = qpq and remind the reader that p = [0; r] and that q is a unit

q

quaternion [s; v ]: 20

1

R p = [s; v ][0; r][s; v ]

q

= [s; v ][0; r][s; v ]

= [s; v ][v  r;sr r  v ]

= [sv  r v  sr r  v ;ssr r  v +v  rv + v  sr r  v ]

2

= [0;s r sr  v +v  rv + v  sr v  r  v ]

2

= [0;s r +v  rv v  r  v  2sr  v ]

2

= [0;s r +v  rv v  v r +v  rv +2sv  r] 

2

= [0; s v  v r +2v  rv +2sv  r]

 Here we use the identity v  v  v =v  v v v  v v

1 2 3 1 3 2 1 2 3

Since q is a unit quaternion, we can write q = [cos ; sin n], where jnj =1 by prop osition 12

on page 14.

Substituting this into R p, we get:

q

2

2

R p = [0; cos sin n  nr + 2sin n  rsin n

q

+2 cos sin n  r]

2 2

2

= [0; cos sin r +2n sin n  r

+2 cos sin n  r]

= [0; r cos 2 +1 cos 2 n  rn +n  r sin 2 ]

From the ab ove derivation, we see that the result is the same vector as in equation 3.4 except

that the ab ove equation has 2 instead of . Thus, given a unit vector n and a rotation angle ,

the unit quaternion [cos ; sin n] rotates r through the angle 2 ab out n. 2

As a consequence of this prop osition, we get the following imp ortant corollary:

Corollary 4. to prop osition 21

Any general three-dimensional rotation about n, jnj =1 can be obtained by a unit quaternion.

Pro of of corollary 4

In the ab ove prop osition cho ose q such that q = [cos ; sin n]. Thus the desired rotation is

2 2

obtained.

2

Comp osition of rotation is achieved by multiplying the corresp onding quaternions. This is

formalized in:

Prop osition 22.

Let q ;q 2 H . Rotation by q fol lowed by rotation by q is equivalent to rotation by q q .

1 2 1 1 2 2 1 21

Pro of of prop osition 22

Given p 2 H , the result follows directly from

1 1 1 1

q q pq q = q q pq q 

2 1 2 1

1 2 1 2

 

= q q pq q  prop osition 13 

2 1

1 2



= q q pq q  prop osition 8 

2 1 2 1

1

= q q pq q  prop osition 13 

2 1 2 1

2

3.3.7 Geometric intuition

We will make some observations that can aid the intuitive understanding of rotation with quater-

nions.

1

The quaternions q and q

Let q =[s; v ] 2 H . Then

1

1

1 

[s; v ] = q = q =[s; v ]

1

It can b e useful to consider the geometric interpretation of this: The inverse of q , q , rotates

the same numb er of degrees as q , but the axis p oints in the opp osite direction:

1

q q

1

By inverting the axis, the direction of rotation is reversed; a subsequent rotation by q cancels

out the e ect of the rotation q .

The quaternions q and q

The quaternion q represents exactly the same rotation as q this follows from prop osition

6. This may seem surprising, but should b e exp ected: A rotation through the angle ab out

the axis n can also be expressed as a rotation through the angle ab out the axis n. It is

therefore aesthetically pleasing that we nd b oth rotations on the unit quaternion sphere. The

same duality is also found in Euler's theorem. 22

q q

Non-unit quaternions

It follows from prop osition 18 that all quaternions on the line rq; r 2 R ; r 6=0 represent the

same rotation.

3.3.8 Quaternions and di erential calculus

In this section we show a number of common results from di erential calculus for functions

that map into H . The results will later be used to show that certain interp olation curves are

di erentiable.

Prop osition 23.

Let q = [cos ; sin v ] 2 H ;t 2 R . Then

1

d

t t

q = q log q 

dt

Pro of of prop osition 23

The equation is shown through simple calculation of the two sides of the equation.

The left-hand side:

d d d d

t

q expt log q  = expt[0; v ] = [cos t ; sint v ]= [ sint ; cos t v ] =

dt dt dt dt

The right-hand side:

t

q log q  = expt log q  log q  = [cos t ; sint v ][0; v ]

= [ sint v  v ; cos t v + sint v  v ]

= [ sint ; cos t v ]= [ sint ; cos t v ]

2 23

We also want to show the chain rule and the pro duct rule for quaternions. We will rst show

the pro duct rule. The purp ose of this derivation is to ensure that the order of the quaternions

in the di erentiated expression is correct; it is imp ortanttomake sure that this is the case since

quaternion multiplication is not commutative.

Prop osition 24. The pro duct rule

1

Let f; g 2 C R ;H . Then

d d d

f tg t =  f tg t+f t g t

dt dt dt

Pro of of prop osition 24

f x +  g x +   f xg x d

f tg t = lim

 !0

dt 

f x +  g x +   f x +  g x+f x +  g x f xg x

= lim

 !0



f x +   f x g x +   g x

= lim + g x f x +  

 !0

 

0 0

= f xg x+f xg x

2

Prop osition 25. The chain rule

d

1 1 0 0

Let f 2 C H; H ; g 2 C R ;H . Then f g x = f g xg x

dt

Pro of of prop osition 25

We compute the derivative at an arbitrary p oint c 2 R :

f g x f g c d

f g c = lim

x!c

dt x c

1

f g x f g cg x g c g x g c

= lim

x!c

x c

f g x f g c g x g c

= lim

x!c

g x g c x c

0 0

= f g cg c

2

Finally we state the following result, that has no obvious counterpart in the real numb ers:

Prop osition 26.

1 1

Let q 2 C R ;H ;r 2 C R ; R . Since q maps into H , q t can be written [cos t; v t sin t],

1 1

and we have

h

d

r t

0 0

q t = sin r t t r t t+r t t ;

dt

i

0 0 0

cos r t t r t t+r t t v t + sin r t t v t 24

Pro of of prop osition 26

d d

r t

q t = expr t log q t

dt dt

d

= expr t[0; v t t]

dt

d

= exp[0;rtv t t]

dt

d

[cos r t t; sinr t tv t] =

dt

h

0 0

= sin r t t r t t+r t t ;

i

0 0 0

cos r t t r t t+r t t v t + sin r t t v t

2

1

Compare this equation to the derivativeoftwo real-valued functions u; v 2 C R ; R :

d d d

v v 1 v

u = vu u + u log u v:

dt dt dt

This equation is di erent from the equation in prop osition 26, and it is unlikely that it holds in

general for quaternions. 25

3.4 An algebraic overview

This section contains a short resume of the algebraic prop erties of the rotational mo dalities.

The mathematical concepts are assumed to be known by the reader, and they are therefore

not describ ed in detail. This section elab orates on the algebra previously discussed and is only

intended for the interested reader.

The space of three-dimensional rotations is not a simple vector-space but a closed three-dimensional

manifold and also a non-Ab elian group see section 3.3.3 known in the literature as SO3

[Sho emake, 1994b ]. Here S is for \sp ecial" and the O 3 stems from the de nition: O n =

t

fn  n matr ices j O O = I g | the set of orthonormal n  n matrices.

The set of unit quaternions constitutes a subgroup of the quaternion group see section 3.3.4. In

3

the literature, H is also called S [Sho emake, 1985 ]. This subgroup constitutes ahyp ersphere

1

3

in quaternion space. The spherical metric for S is equivalenttothe angular metric for SO3

[Sho emake, 1985 ].

Furthermore the rotation group can b e pro jected onto the four-dimensional unit sphere of unit

quaternions. This pro jection is two-to-one see section 3.3.7: For each rotation there are

two corresp onding unit quaternions | q that is obtained directly and q , the antip o dal unit

quaternion see [Sho emake, 1994b ], [Foley et al., 1990 ] and app endix B. This is b ecause SO3

3

has the same top ology as the three-dimensional pro jection space called R P , while the set

3 3

of unit quaternions constitutes a hyp ersphere S  that is top ologically di erent from R P

[Sho emake, 1994b ].

Bearing these similarities and the small discrepancy in mind, we can see that by developing a

smo oth interp olation b etween unit quaternions, we get a smo oth interp olation b etween general

rotations. The problem is not trivial, in particular b ecause H constitutes a non-Euclidean

1

space, which excludes the usual interp olation metho ds such as splines. Our task is to nd an

equivalentinterp olation curve on the surface of the four-dimensional unit sphere. 26

Chapter 4

A comparison of quaternions, Euler

angles and matrices

In the previous chapter weintro duced two rotational mo dalities:

 Rotation de ned by Euler angles represented by general transformation matrices.

 Rotation de ned by Euler's theorem represented by quaternions.

In this chapter we will describ e advantages and disadvantages of the di erent mo dalities.

4.1 Euler angles/matrices | Disadvantages

Traditionally homogeneous matrices have b een used to represent Euler angles b ecause the basic

rotation matrices for rotation ab out the x-, y -, and z -axes are simple and well-known. This

historically based choice has some disadvantages, though. We will discuss the disadvantages

b elow.

Lack of intuition

Describing a general rotation as rotations ab out the three basis axes is not natural for an

animator. If, for instance, the animator wants to rotate an ob ject 30 degrees ab out a rotation

axis given by the vector 1; 1; 1, it is quite tedious to derive the corresp onding Euler angles

ab out the three basis axes. 27

The order of rotation axes is imp ortant

The user of a graphical system must express rotations in resp ect to a certain convention that

de nes in which order the three basis rotations are applied. Di erent conventions yield di erent

 

; ; 0 yields di erent orientations dep ending on which results. For example, a rotation of 

2 4

convention of x; y ; z and y ; x; z is b eing used.

As an example, we examine an ob ject in a co ordinate system see gure 4.1. By rotating the

 

ob ject in gure 4.1.i the angle ab out x and then ab out y the result is 4.1.ii. If the convention

2 4

 

y ; x; z is used instead, the rotation is done by ab out y and then ab out x yielding 4.1.iii.

4 2

i ii iii

Figure 4.1: In the coordinate system the x-axis points to the right, the y -axis points up and

the z -axis point to the left. Figures ii and iii show the result of applying di erent rotation

conventions to the object in gure i.

Gimbal lo ck

Getting an intuitive understanding of how rotation matrices work is quite dicult. In partic-

ular, it is dicult to predict how successive rotations ab out the basis axes a ect each other.

Considering that the matrix representation of Euler angles has an innate singularity in the pa-

rameterization makes this even more dicult. It is p ossible to create series of rotations, where

one degree of freedom in the rotation is lost. This situation is called lock.

Gimbal lo ck is a concept originating from the air and space industry, where gyroscop es are

used [Sho emake, 1985 ] [Watt &Watt, 1992 ] [Verplaetse, 1995 ]. A gyroscop e basically consists

of three concentric rings. See gure 4.2 for an illustration of this the example is inspired by

[McCo ol, 1995 ].

In 4.2.i the inner ring represents the x-axis, the center ring the y -axis and the outer ring

represents the z -axis. A rotation ab out the x-axis can for example result in 4.2.ii, where the

ob ject is rotated approximately 45 degrees ab out the x-axis. If we then rotate 90 degrees ab out

the y -axis, we get the situation shown in gure 4.3.

In this situation, the x and the z -rotation acts ab out the same axis. This is an example of

gimbal lo ck. 28

i ii

Figure 4.2: In the coordinate system the x-axis points up, the y -axis points to the left and the

z -axis points to the right. The inner ring represents the x-axis, the center ring the y -axis and the

outer ring represents the z -axis. From the starting point i the x-axis is rotated approximately

45 degrees in ii.

Figure 4.3: In the coordinate system the x-axis points up, the y -axis points to the left and the

z -axis points to the right. In this situation the x and the z -rotation act about the same axis.

This phenomenon is cal led gimbal lock.

Mathematically gimbal lo ck corresp onds to lo osing a degree of freedom in the general rotation

matrix see app endix B:

9 8

cos cos cos sin sin cos sin cos cos sin + sin sin 0

> >

> >

> >

> >

cos sin cos cos + sin sin sin cos sin sin cos sin 0

> >

> >

R  ; ;  =

> >

> >

sin cos sin cos cos 0

> >

> >

; :

0 0 0 1



If we let = , then a rotation with will have the same e ect as applying the same rotation

2

with . This can be seen from the following derivation using the addition formulas for cos

and sin: 29

8 9

0 cos sin cos sin cos cos + sin sin 0

> >

> >

> >

> >

0 cos cos + sin sin cos sin cos sin 0

> >



> >

R  ; ;  =

> >

2 > >

1 0 0 0

> >

> >

: ;

0 0 0 1

8 9

0 sin  cos   0

> >

> >

> >

> >

0 cos   sin  0

> >

> >

=

> >

> >

1 0 0 0

> >

> >

: ;

0 0 0 1

This expression shows that the rotation only dep ends on the di erence and therefore it



changes of and result in rotations has only one degree of freedom instead of two. For =

2

ab out the same axis.

Implementing interp olation is dicult

Normally the co ordinates of each basis axis are interp olated indep endently. Thereby the inter-

dep endencies between the axes are ignored. As an example, this results in unexp ected e ects

when applying simple linear interp olation. See section 6.1.1 for a treatment of this.

Ambiguous corresp ondence to rotations

Given a rotation matrix it is dicult to solve the inverse problem: What are the original

rotations ab out the basis axes? In general, there is no unambiguous solution to this problem.

See app endix A or [Sho emake & Du , 1994 ] for more detail.

In addition to this, a rotation can b e represented by many di erent rotation matrices. All in all

the mapping b etween rotations and rotation matrices is neither injective nor surjective.

The result of comp osition is not apparent

According to Euler's theorem two successive rotations can b e expressed as one. The two rotation

matrices must b e comp osed and multiplied followed by extraction of the resulting rotation. To

determine this rotation is tedious and in general not p ossible as mentioned ab ove see page 90

or [Sho emake & Du , 1994 ] for further detail.

The representation is redundant

Homogeneous matrices contain exp endable information. If the matrices are to b e used exclusively

for rotation, the matrices will have zero es for indices 4;i and i; 4;i 2f1; 2; 3g. In addition

to this, the matrix uses 9 places for the 4 degrees of freedom that are necessary to describ e a

rotation according to Euler's theorem.

On top of this numerical inaccuracies will be problematic. Since rotation matrices must be

orthonormal there are 6 constraints each rowmust b e a unit vector and the columns must b e

mutually orthogonal that must b e maintained during the computations. 30

4.2 Euler angles/matrices | Advantages

An advantage of matrix implementations is that the mathematics is well-known and that matrix

applications are relatively easy to implement using standard packages. These advantages are

more historically than rationally determined though.

The main advantage of the matrix representation is the ability of the homogeneous matrix to

represent all the other basic transformations, for example translation, scaling, pro jection, and

shearing.

4.3 Quaternions | Disadvantages

Quaternions only represent rotation

It is p ossible to implement translation using quaternions quaternion addition can be used as

a translation transformation interpreting the vector part of the quaternion as the translation

vector. In [Maillot, 1990 ] a kind of homogeneous quaternions are de ned with a multiplication

making b oth translation and rotation multiplicative.

Even though it is p ossible to de ne a homogeneous quaternion and thereby including the trans-

lation comp osition, this extension is not as elegant as the homogeneous matrices. The homo-

geneous extension app ears to be ignored in the literature. Quaternions are used for rotation

exclusively, matrices are used for all other transformations.

Quaternion mathematics app ears complicated

Quaternions are not included in standard curriculum of mo dern mathematics. Some might study

the quaternion group in algebra, but knowledge of quaternions is, in general, not widespread.

Therefore quaternions require a bit of work in the b eginning. However, quaternions should p ose

no problem for someone able to understand matrix algebra.

4.4 Quaternions | Advantages

Obvious geometrical interpretation

Quaternions express rotation as a rotation angle ab out a rotation axis. This is a more natural

way to p erceive rotation than Euler angles.

The obvious corresp ondence b etween Euler's theorem and rotations represented by quaternions

gives a nice intuitive understanding of quaternions. The mapping b etween rotations and quater-

nions is therefore unambiguous with the exception that every rotation can b e represented bytwo

quaternions. This app ears to be a weakness in the quaternion representation. That q and q

corresp ond to the same rotation is on the other hand mathematically pleasing. This is b ecause

rotations themselves come in pairs. Given a rotation, the same rotation is obtained by rotating

in the opp osite direction ab out the opp osite axis. see 3.3.7 on page 22. 31

Co ordinate system indep endency

Quaternion rotation in not in uenced by the choice of co ordinate system. The user of an

animation system do es not need to worry ab out a certain convention of the order of rotation

ab out explicit axes.

Simple interp olation metho ds

Quaternions allow elegant formulations of a range of interp olation metho ds. Achieving a smo oth

interp olation is therefore simpler using quaternions than Euler angles. We will give a compre-

hensive treatment of this in chapter 6.

Compact representation

The representation of rotation using quaternions is compact in the sense that it is four di-

mensional and thereby only contains the four degrees of freedom required according to Euler's

theorem.

In theory all non-zero quaternions can be used for rotation by prop osition 18. In practical

applications only unit quaternions will b e used. Thus, only one constraint on the representation

must b e upheld during computation compared to the six constraints on rotation matrices.

No gimbal lo ck

Since gimbal lo ck is innate to the matrix representation of Euler angles, this problem do es not

app ear in the quaternion representation.

Simple comp osition

Rotations are easily comp osed when using quaternions. The comp osition corresp onds to multi-

plication of the involved quaternions. Rotation with q followed by rotation with q is achieved

1 2

by rotating with the quaternion q q .

2 1

4.5 Conclusion

Wehave stated a series of advantages and disadvantages for the two rotation mo dalities. Using

Euler angles represented by matrices leads to several problems. Rotation must be expressed

as the angles ab out three explicit axes, with the order b eing imp ortant. It is p ossible to en-

counter gimbal lo ck and nally it is troublesome to uphold the mathematical constraints on the

representation during calculations. 32

The quaternion representation is compact with a more natural geometrical interpretation and a

parameterization of rotation that is not dep endent on the co ordinate system.

The only real advantage of matrices is the p ossibilityof representing all the other transforma-

tions.

All in all, quaternions o er the b est choice for representation of rotations.

4.6 Other mo dalities

In the previous sections we have argued that rotations should be represented by quaternions

based on Euler's theorem. However, wehave only compared to one other mo dality | rotation

matrices based on Euler angles.

Obviously, other mo dalities are p ossible. For example the two mo dalities can b e combined. It

is p ossible to de ne rotation matrices based on Euler's theorem an example can be found in

[Foley et al., 1990 ] exercise 5.15. Thereby the problems connected to Euler angles are avoided

yielding a b etter corresp ondence between rotation matrices and the set of rotations. There

are still problems with this mo dality though. For instance, the inverse mapping from rotation

matrices to rotations is still ambiguous. Further, the matrix representation is not well-suited for

interp olation algorithms. For example the matrices still need to ful ll the constraints imp osed

by b eing orthonormal matrices.

We will limit ourselves from discussing other mo dalities. This is simply b ecause the two we

have mentioned are by far the most imp ortant. Euler angles and matrices are the most com-

mon mo dality in b oth the literature and in applications. We claim that quaternions are more

appropriate. 33

Chapter 5

Visualizing interp olation curves

In chapter 6 we discuss a series of interp olation metho ds that can interp olate between two or

more quaternions. Wewould like to compare these metho ds from a theoretical p ersp ective. At

the same time it is natural to compare the results of the metho ds in practice, to see if practice

re ects our theoretical considerations.

This section contains a short description of the visualization metho ds used and the motivation

for eachtyp e of visualization.

5.1 Direct visualization

The most obvious visualization metho d is to apply the interp olated rotations to the ob ject. This

is most easily achieved by de ning an ob ject using a three-dimensional visualization to ol, and

then rotating it with the interp olated rotations. We let this visualization metho d pro duce an

animated sequence that shows how the ob ject is rotated. The metho d gives an intuitive feel

for how the interp olation curve b ehaves, but it is dicult to say anything concrete ab out the

smo othness of the interp olation curves or the variation in angular velo city. We therefore need

other metho ds of visualization that can provide us with this information.

5.2 Visualizing an approximation of angular velo city

We want to visualize the angular velo city of the interp olation curve. For example it will be

interesting to see if some of the interp olation curves have constant angular velo city.

In the following, q denotes the i'th frame, i. e. the i'th quaternion in a discrete quaternion

i

interp olation curve.

To pro duce a graph of the angular velo city,wemust de ne a function that gives an approximation

of the angular velo city. Then all that remains is to plot this function against the interp olation

parameter. Anumb er of di erent approximations to the angular velo city can b e de ned based 34

in either physics or mathematics. We will base our de nition in mathematics, and use that

we have de ned a norm on quaternions. We can de ne the distance between two quaternions

0

q ;q to be dq ;q =kq q k. Then the angular velo city V in the i th quaternion q can b e

1 2 1 2 1 2 i

approximated by the centered average:

dq ;q +dq ;q  kq q k + kq q k

i i1 i i+1 i i1 i i+1

V q = = 5.1

i

2 2

Plotting V as a function of the interp olation parameter yields a graph of an approximation to

the angular velo city.

We will omit the rst and last key frames from the angular velo city graph, since no obvious

angular velo city can be assigned to them. Thereby the leftmost p oint on the angular velo city

graph is the angular velo city in the rst interp olated frame. The remaining key frames we will

mark with an asterisk in the velo city graph.

5.3 Visualizing the smo othness of interp olation curves

We would also like to visualize the interp olation curves to see, for example, how smo oth they

app ear.

Since quaternion space is four-dimensional, we cannot visualise the interp olated curves directly.

We will always interp olate between unit quaternions, and the interp olated quaternions will

always with a few exceptions in chapter 6 on page 38 and 69 be unit quaternions. This

means that we only need three dimensions to visualize the interp olation curves, b ecause they

lie on the surface of the unit sphere. In practice it can be dicult to visualise this space

e ectively since it must b e presented via a two-dimensional media pap er or monitor. We can

remove another dimension byinterp olating b etween quaternions in the same three-dimensional

hyp erplane. This can b e achieved by xing one of the quaternion co ordinates in all key frames.

Thus the interp olated curves should stay inside a two-dimensional space that can b e shown in

the plane. To keep the asso ciation to the four-dimensional unit sphere, we elect to show the

curves on the surface of the three-dimensional unit sphere a two-dimensional sub manifold of

3

R . In chapter 6 we will argue that the ideal interp olation curve will lie on the surface of the

quaternion unit sphere. Our choice of visualization ensures that we can visually determine if

the visualization curve stays on the surface of the unit sphere. See gure 5.3 for an example of

this.

The actual visualizations are pro duced using a ray tracer [POV, 1997 ]. Here we generate a large

sphere that represents the three-dimensional unit sphere. The rst key frame is shown as a

medium-sized sphere, other key frames are shown using a bit smaller spheres, and interp olated

p oints are shown using small spheres. See gures 5.1 through 5.3 b elow. 35

5.4 Some examples of visualization

In this section we show some examples of the visualization of the angular velo city graphs and

the interp olation curves. The interp olation metho ds are describ ed in section 6; we only describ e

prop erties of the resulting visualizations here.

The interp olation is p erformed on the frames given in table 5.1. The key frames are given by

a general rotation. As noted ab ove, we cho ose the rotation angle and axis such that all the

rotations lie in the same three-dimensional hyp erplane.

In gures 5.1 through 5.3 we discuss di erent prop erties of the visualizations. Note that there

is no obvious connection b etween the rotations in gure 5.1 and the p oints on the surface of the

sphere. This is b ecause the table contains general rotations, while the visualizations show the

corresp onding quaternions. Since we are only interested in the geometric shap e of the curves,

the absolute p ositioning of the key frames on the sphere is irrelevant.

3

Rotation angle 2 ] ; ] Rotation axis v 2 R

1 1,3,0

1.9 -1,0,0

0 -2,1,0

-2 3,4,0

-1 -1,4,0

1 1,3,0

Table 5.1: Key frames

1.2 'Angular Velocity.' 'Key Frames.'

1

0.8

0.6

0.4

0.2

0 0 100 200 300 400 500 600 700 800

Frame nr.

Figure 5.1: The interpolation curve stays on the surface of the sphere, but it is not di erentiable

in any key frames; the curve \breaks" when it passes through the key frames. The angular velocity

graph is piecewise continuous and shows that the angular velocity is constant between keys. This

method of interpolation is cal led Slerp and is described in section 6.1.5. 36 1.2 'Angular Velocity.' 'Key Frames.'

1

0.8

0.6

0.4

0.2

0 0 100 200 300 400 500 600 700 800

Frame nr.

Figure 5.2: The interpolation curve is now di erentiable through al l key frames. Compare, for

example, the key frame in the midd le of the gure with the corresponding key frame in gure

5.1. The angular velocity graph is continuous and assumes local minima at the key frames. This

interpolation curve is cal led Squad, and it is described in section 6.2.1.

1.2 'Angular Velocity.' 'Key Frames.'

1

0.8

0.6

0.4

0.2

0 0 100 200 300 400 500 600 700 800

Frame nr.

Figure 5.3: This interpolation curve dips below the surface of the three-dimensional unit sphere.

This means that the interpolated points are not unit quaternions, and thus the points do not lie

on the surface of the sphere. The angular velocity graph is piecewise linear. This interpolation

curve is cal led LinE ul er , and is described in section 6.1.1

In general we will illustrate the interp olation metho ds with the last two visualization metho ds:

Sphere and graph. Wehave included the animated sequences for the sake of completeness, since

it is in this context that the interp olation serves its practical purp ose.

A few examples of these animated sequences can b e seen at http://kantine.diku.dk/~myth/gif/ 37

Chapter 6

Interp olation of rotation

In the previous chapters we presented and discussed two rotational mo dalities. In this chapter

we will investigate howwell-suited the mo dalities are for interp olation metho ds.

Gradually we will move from simple, intuitive metho ds to more advanced, theoretically well-

founded interp olation metho ds. Parallel to the derivation of metho ds we will discuss what we

p erceive as criteria de ning the optimal interp olation metho d. Our mo dest aim is to de ne and

implement this optimal metho d.

6.1 Interp olation between two rotations

Initially we will limit ourselves to lo oking at interp olation b etween two rotations. We will use

the rotation representations as inspiration for treating a series of simple metho ds.

Each of the metho ds results in an interp olation curve de ned as follows. Given an arbitrary

set M we interp olate between x 2 M and x 2 M parameterised by h 2 [0; 1]. The resulting

0 1

interp olation curve : M  M  [0; 1] y M must satisfy the constraints:

x ;x ; 0 = x

0 1 0

x ;x ; 1 = x

0 1 1

6.1.1 Linear Euler interp olation: LinE ul er

The most obvious metho d is simply linear interp olation between two tuples of Euler angles.

3

Calling this interp olation curve LinE ul er ,interp olation b etween v =x ;y ;z  2 R and v =

0 0 0 0 1

3

x ;y ;z  2 R can b e stated algorithmically using h 2 [0; 1] as the interp olation parameter:

1 1 1

LinE ul er v ;v ;h = v 1 h+v h 6.1

0 1 0 1 38 1.2 Angular Velocity Key Frames

1

0.8

0.6

0.4

0.2

0 0 50 100 150 200 250 300

Frame nr.

Figure 6.1: Interpolation curve and velocity graph for Linear Euler interpolation | LinE ul er .

Between the two key frames are 300 interpolated frames.

Figure 6.1 is not a very good illustration of the interp olation curve. The curve \lives" in the

set of Euler angles while the illustration shows the corresp onding quaternions. As describ ed in

chapter 5, the illustration is designed to show unit quaternions with the z co ordinate equal to

zero. The quaternions corresp onding to the key frames meet these criteria but the rest of the

interp olation curve do es not. The curve consists of unit quaternions but their z co ordinate is

not generally equal to zero. Therefore the curve disapp ears from the surface of the sphere in

the illustration.

1

This b ehaviour is neither optimal nor intuitively correct.

The velo city graph shows that the animation corresp onding to the interp olation will gradually

slowdown. Again, this b ehaviour is neither optimal nor intuitively correct.

6.1.2 Linear Matrix interp olation: LinM at

An alternative simple attempt is linear interp olation between rotation matrices | meaning

linear interp olation of every single matrix element indep endently of the others.

This can be stated simply algorithmically. With parameter h 2 [0; 1], the interp olation curve

4 4 4 4

between the rotation matrices M 2 R  R and M 2 R  R the curve is de ned by

0 1

LinM atM ;M ;h = M 1 h+M h 6.2

0 1 0 1

As with linear Euler interp olation, the curve for linear matrix interp olation do es not in general

lie on the unit sphere, since linear interp olation b etween orthonormal matrices will not in gen-

eral pro duce orthonormal matrices. Thus, the interp olated matrices are general homogeneous

1

We p erceive \optimal" informally so far. Later we will state a strict de nition of the optimal interp olation

curve. 39 1.2 Angular Velocity Key Frames

1

0.8

0.6

0.4

0.2

0 0 50 100 150 200 250 300

Frame nr.

Figure 6.2: Interpolation curve and velocity graph for linear matrix interpolation | LinM at.

Between the two key frames are 300 interpolated frames.

transformation matrices containing translation, scaling, pro jection and other transformation el-

ements. Thereby the interp olation can b ecome arbitrarily wrong. For example, it is p ossible to

collapse the entire ob ject into a single p oint [Sho emake & Du , 1994 ].

Our visualization metho ds cannot show other transformations than rotation. Therefore we are

not able to illustrate that the interp olated matrices are not pure rotation matrices. By converting

matrices to quaternions we preserve only the rotational part.

In gure 6.2 wehave pro jected the interp olation curve on to the unit quaternion sphere to show

the pure rotational part of the interp olation curve. Finally, after these detours, we arrive at a

quite nice interp olation curve.

As explained, the nice illustration do es not imply that the interp olation metho d is usable |

only a comp onent of the full interp olation curve is shown. The metho d is only discussed for

completeness.

6.1.3 Linear Quaternion interp olation: Ler p

Finally, another obvious attempt is linear interp olation between rotation quaternions called

Ler p for linear interpolation. For q ;q 2 H and h 2 [0; 1] this interp olation curve can be

0 1

stated:

Ler pq ;q ;h = q 1 h+q h 6.3

0 1 0 1

The interp olation curve for linear interp olation between quaternions gives a straight line in

quaternion space. The curve therefore dips b elow the surface of the unit sphere. Since all

2

quaternions on a line through the origin give the same rotation , the curve can b e pro jected on

2

Except the origin itself. This follows from prop osition 18. 40 1.2 Angular Velocity Key Frames

1

0.8

0.6

0.4

0.2

0 0 50 100 150 200 250 300

Frame nr.

Figure 6.3: Interpolation curve and velocity graph for linear quaternion interpolation | Ler p.

Between the two key frames are 300 interpolated frames.

to the unit sphere without changing the corresp onding rotations. Therefore the interp olation

curve is normalized  gure 6.3.

The illustration shows that Ler p is the rst of the interp olation metho ds discussed so far to yield

a satisfying result. Even though the interp olation curve for Ler p resembles the curve for LinM at

see gures 6.2 and 6.3 wemust emphasize that this do es not mean that the interp olations are

alike. The illustration for LinM at is the result of a series of transformations and not a true

image of the interp olation curve.

Even though the interp olation curve for Ler p is nice, the velo city graph is not intuitively satis-

fying. The sp eedup in the middle is due to the fact that the interp olation curve takes a \short

cut" b elow the surface of the unit sphere. This is not a desired prop erty. The intuitively correct

velo city graph for linear interp olation is a constant function.

6.1.4 A summary of linear interp olation

We have attempted simple linear interp olation with the purp ose of revealing which rotation

representation is most suitable for de ning interp olation curves.

The disadvantages of LinE ul er and LinM at are evident. As previously describ ed, Euler angles

are not the b est de nition for rotation and matrices are not an obvious representation. Therefore

it is not to b e exp ected that simple linear interp olation b etween pairs of Euler angles or rotation

matrices will result in nice interp olation curves.

In contrast the interp olation curve for Ler p is quite nice. The only problem is the varying

velo city graph. A constant velo city is not necessarily a requirement for a curve. However, in

this case the varying velo city is a problem since it is the result of a aw in the metho d. The

problem is that the interp olated quaternions are not unit quaternions in general. 41

For Euler angles and rotation matrices the linear interp olation can result in unacceptable in-

terp olation curves. It do es not necessarily follow from this that it is imp ossible to de ne a

satisfying interp olation curve using these representations. It do es, however, imply that it is not

p ossible to de ne simple algorithms yielding satisfying curves. This is a direct consequence of

the disadvantages in the Euler angle and rotation matrix representation as discussed in chapter

4.

On the other hand, the very simple Ler p is close to b eing optimal. At this stage we p erceive

the optimal interp olation curve between two key frames to b e the great arc on the quaternion

unit sphere b etween the two corresp onding quaternions.

Due to the previous considerations we will refrain from further attempts at deriving interp olation

curves based on Euler angles and rotation matrices.

6.1.5 Spherical Linear Quaternion interp olation: Slerp

3

As proven in prop osition 18, all quaternions on a line through the origin p erform the same

rotation. However, we only want to use unit quaternions for rotation since they p ossess a range

4

of desirable prop erties .

Simple linear quaternion interp olation yields a secant between the two quaternions. Therefore

the interp olation function has larger velo city in the middle of the curve see gure 6.3 and

gure 6.4. Apart from this Ler p is optimal. An obvious idea is to de ne an interp olation

metho d yielding the same interp olation curve but where the interp olated quaternions are unit

quaternions. Instead of doing simple linear interp olation the curve should follow a great arc on

the quaternion unit sphere from one key frame to the other. This is called great arc interpolation

or spherical linear interpolation - Slerp .

V

a b c

Figure 6.4: An il lustration in the plane of the di erence between Ler p and S l er p. a The

interpolation covers the angle v in three steps. b Ler p | The secant across is split in four

equal pieces. The corresponding angles are shown. c S l er p | The angle is split in four equal

angles.

This interp olation can b e stated algorithmically as follows [Sho emake, 1985 ], [Sho emake, 1987 ]

and [Sho emake, 1997 ]. Given q ;q 2 H and h 2 [0; 1] the following four functions are equiva-

0 1 1

lent expressions for spherical linear interp olation:

3

Except the origin itself.

4

The unit quaternion sphere is, as mentioned in chapter 3.4, equivalent to the space of general rotations. 42

 h

S l er pp; q ; h = p p q  6.4

 1h

S l er pp; q ; h = pq  q 6.5

 h

S l er pp; q ; h = q p  p 6.6

 1h

S l er pp; q ; h = q q p 6.7

Notice the pairwise symmetry yielding the intuitively correct:

Slerp p; q ; h=Slerp q; p; 1 h

The equivalence of the four expressions for Slerp is proven in the following prop osition inspired by

[Sho emake, 1997 ]. No pro of of the equivalence has previously b een published this is con rmed

by Ken Sho emake.

Prop osition 27.

For p; q 2 H ;h 2 R the fol lowing four expressions are equivalent:

1

 h

1 p p q 

 1h

2 p q  q

 h

3 q p  p

 1h

4 q q p

Pro of

First we show 1 = 3. Prop osition 20 is used page 18.

 h  h 

pp q  = pp q  p p

 h 

= pp q  p p

  h

= pp qp  p Prop osition 20

 h

= qp  p

Nowwe show 4 = 2:

 1h  1h 

q q p = q q p q q 

 1h 

= q q p q q

  1h

= q q pq  q Prop osition 20

 1h

= pq  q

Finally we show 2 = 1 using prop osition 16 from page 16 and prop osition 17:

 1h   h

pq  q = pq pq  q Prop osition 16

  1 h

= pq pq   q Prop osition 17

   h

= pq pq   q

  h

= pq qp  q

  h

= pq qp q  Prop osition 20

  h

= pq qp q 

 h

= pp q 

2 43

5

We have thus proved the equivalence of the four expressions for Slerp . From now on we will

 h

use Slerp p; q ; h=pp q  equation 6.4.

That Slerp do es, in fact, p erform great arc interp olation on the four-dimensional quaternion

sphere is not obvious. Often in the literature it is stated that this follows directly from the

Lie group structure of the unit quaternions. We provide a thorough pro of in prop osition 28

requiring only basic di erential geometry.

There are several di erent ways of proving prop osition 28. One approach is to lo ok at the

curvature of Slerp . It is fairly easy to prove that the curvature equals one throughout the entire

interp olation curve. Only great arcs have curvature equal one on a unit sphere. Here we use

another approach. The key p oint in this pro of is observing that the curve is a great arc if the

second derivative vector is parallel and with opp osite direction to the p osition vector of the

2

d

curve, i. e. Slerp p; q ; h = c Slerp p; q ; h; c  0. This corresp onds to the forces acting on

2

dh

an ob ject describing a plane circular motion with constant angular velo city.

Before the pro of we need a lemma:

Lemma 3.

Let p =[s; v ];q =[s ; x ;y ;z ] = [s ; v ];q =[s ; x ;y ;z ] = [s ; v ] 2 H:

1 1 1 1 1 1 1 2 2 2 2 2 2 2

2

q  Then pq  pq =kpk q

2 1 2 1

 

Pro of of lemma 3

pq  pq  = [ss v  v ;sv + s v + v  v ] [ss v  v ;sv + s v + v  v ]

1 2 1 1 1 1 1 2 2 2 2 2

 

2

= s s s ss v  v ss v  v +v  v v  v +

1 2 1 2 2 1 1 2

2

s v  v + ss v  v + sv  v  v +

1 2 2 1 1 2

ss v  v + s s v  v + s v  v  v +

1 2 1 2 1 2

sv  v   v + s v  v   v +v  v   v  v 

1 2 2 1 1 2

2

= s s s +v  v v  v +

1 2 1 2

2

s v  v + sv  v  v +s s v  v +

1 2 1 2 1 2

sv  v   v +v  v   v  v 

1 2 1 2

We simplify using v  v   v  v =v  v v  v  v  v v  v :

1 2 1 2 2 1

2

pq  pq  = s s s +v  v v  v +

1 2 1 2 1 2



2

s v  v + sv  v  v +s s v  v +

1 2 1 2 1 2

sv  v   v +v  v v  v  v  v v  v 

1 2 1 2 2 1

2 2

= s + v  v s s +s + v  v v  v +

1 2 1 2

sv  v  v +sv  v   v

1 2 1 2

2

= kpk q q +sv  v  v +sv  v  v 

1 2 1 2 2 1



Finally,we use the identity

x y z

= xy z + x yz + x y z xy z x yz x y z x y z v  v  v =

1 2 2 1 1 2 2 1 1 2 2 1 1 1 1 1 2

x y z

2 2 2

5 1h h

Another comp elling expression for Slerp is Slerpp; q ; h= p q . This is intuitively analogous to ordinary

 h

linear interp olation p 1 h+q h. The equivalence with equation 6.4 can be shown as follows: pp q  =

1 h h h 1h h

pp q  = pp q = p q . This is very nice | and yet another example of how easy it is to make erroneous

h h h

pro ofs with quaternions. For q; p 2 H and h 2 R the equation qp = q p do es not hold in general. This would

require commutativity. 44

Wenow get:

2

q +sv  v  v +sv  v  v  pq  pq  = kpk q

2 1 2 2 1 1 2 1

 

2

q + = kpk q

2 1



sx yz + x y z + xy z x y z xy z x yz +

1 2 2 1 2 1 1 2 1 2 2 1

sx yz + x y z + xy z x y z xy z x yz 

2 1 1 2 1 2 2 1 2 1 1 2

2

q  = kpk q

2 1



2

Prop osition 28.

The curve Slerp p; q ; h : H  H  [0; 1] y H is a great arc on the unit quaternion sphere

1 1 1

between p and q . The position vector function of Slerp has constant angular velocity.

Pro of of prop osition 28

To show prop osition 28 wemust prove that the following four conditions are met:

Slerp p; q ; 0 = p 6.8

Slerp p; q ; 1 = q 6.9

kSlerp p; q ; hk = 1; h 2 [0::1] 6.10

2

d

Slerp p; q ; h = c Slerpp; q ; h; c  0 2 R 6.11

2

dh

Conditions 6.8 and 6.9 are shown directly using the de nitions for exp and log .

 0

Slerp p; q ; 0 = p p q  = p exp[0; 0] = p[1; 0] = p

 1 

Slerp p; q ; 1 = p p q  = p explog p q 

 1

= pp q = pp q = q

Condition 6.10 is met since exp maps into H de nition 15 and since the norm of a pro duct is

1

the pro duct of the norms prop osition 9, equation 3.3:

 h 

kSlerp p; q ; hk = kpkkp q  k =1 k exph log p q k =1

To show condition 6.11, we need the second derivativeofSlerp . Using prop osition 23 we nd:

d d

 h

Slerp p; q ; h = pp q 

dt dt

 h 

= pp q  log p q 



= Slerp p; q ; h log p q  6.12

2

d

 h  2

Slerp p; q ; h = p p q  log p q 

2

dh

 2

= Slerp p; q ; h log p q 

 2  

Condition 6.11 holds if log p q  is a non-p ositive real numb er. Since p ;q 2 H , then p q 2 H .

1 1

3 

By prop osition 12 there exists 2 R and v 2 R ; jv j = 1 such that p q = [cos ; sin v ]. Then: 45

 2 2

log p q  = [0; v ]

2 2

= [ v  v ; v  v ]

2

= [ ; 0]

2

d

2

Slerp p; q ; h=c Slerp p; q ; h where c =  0. Thus

2

dh

2

Having shown that Slerp p; q ; h;h 2 [0; 1] spans a great arc b etween p and q , there are still two

p ossible curves dep ending on which direction around the unit sphere Slerp takes. The following

prop osition states that Slerp b ehaves as desired.

Prop osition 29.

Let p; q 2 H . Then Slerp p; q ; h; h 2 [0; 1], spans the shortest great arc between p and q on

1

the unit quaternion sphere.

Pro of of prop osition 29

1

Let q = Slerp p; q ; . Slerp yields the shortest  and let denote the angle between p and q

1 1

2

2 2

 

arc if and only if 2 ] ; ]. This is equivalent to cos   2 [0; 1]. We therefore examine the

2 2

sign of cos .

Let p; q 2 H , where p =[s; v ].

1

cos   = p q Prop osition 10

1



2

= p Slerp  p; q ; 1=2



1



2

 = p p p q 



  3

Since p ;q 2 H it follows that p q 2 H . By prop osition 12 there exists w 2 R , jw j =1 and

1 1



 2 ] ; ] such that p q = [cos  ; sin  w ]. Using lemma 3 we get:

1=2

cos = p p [cos  ; sin w ]



= p  p exp1=2  log [cos  ; sin w ]



= p  p exp[0; =2w ]



= p  p [cos =2 ; sin  =2 w ]



= p [1; 0] p [cos =2 ; sin =2 w ]



2

= kpk [1; 0] [cos =2 ; sin  =2 w ] Lemma 3



2

= kpk cos =2

= cos =2

Now  2 ] ; ] yields cos=2  0 and therefore cos    0. Thus Slerp spans the shortest

great arc b etween p and q .

2 46

We have now proven the equivalence of the four expressions for Slerp from prop osition 27

and then proven that Slerp actually pro duces the desired great arc. This could conclude our

treatment of Slerp . However, the literature has traditionally avoided the use of exp onentiation

6

in the expression for Slerp . We have encountered no problems using the expressions from

prop osition 27. However, for the sake of completeness, we will include the following expression

for Slerp without exp onentiation:

q cos   = q

1 0



q sin1 h  + q sinh 

0 1

6.13 S l er pq ;q ;h =

0 1

sin 

Notice that this expression is not de ned for q = q . The obvious patchisSlerp q; q; h q .

0 1

The correctness of the expression ab ove equation 6.13 can b e shown in the plane. The inter-

p olation b etween p and p as illustrated in gure 6.5 can b e written:

0 1

cosv + ht

q h =

sinv + ht

The expression from equation 6.13 can | through applying the addition formulas for sin and

cos successively | b e written as:

p sin1 ht+p sinht

0 1

S l er pp ;p ;h =

0 1

sint

! 

cosv  sin1ht+cos v +t sinht

sint

=

sinv  sin1ht+sin v +t sinht

sint

 !

cosv sin t cos htcos t sinht+cos v  costsin v  sint sinht

sint

=

sinv sin t cos htcos t sinht+sin v  cost+cos v  sint sinht

sint

cos v  cos ht sinv  sinht

=

sinv  cos ht + cosv  sinht

cos v + ht

=

sinv + ht

= q h

Thus, the correctness of the expression has b een proven in the plane. This result can b e gener-

alized directly to four dimensions thereby proving equation 6.13.

Slerp summarized

The interp olation curve for Slerp  gure 6.6 forms a great arc on the quaternion unit sphere

as proven in prop osition 28. In di erential geometry terms, the great arc is a geodesic |

corresp onding to a straight line. Not only do es Slerp follow a great arc as proven in prop osition

29 it follows the shortest great arc. Thus Slerp yields the shortest p ossible interp olation path

7

between the two quaternions on the unit sphere . Furthermore Slerp has constant angular

velo city. All in all Slerp is the optimal interp olation curvebetween two rotations.

6 h

Since q = exph log q  exp onentiation automatically implies the use of the logarithm and exp onential func-

tions. These functions are only de ned on a limited set of quaternions and they can therefore cause problems in

conjunction with numerical inaccuracies.

7

It should b e noted that even though Slerp p erforms the shortest p ossible arc b etween p and q this is not nec- 47 p' p' q

t p ht p

v

a b

0

Figure 6.5: Slerp in the plane. a The interpolation goes from p to p across the angle t. b A

0

step in the interpolation, where h 2 [0; 1], q moves from p to p .

1.2 Angular Velocity Key Frames

1

0.8

0.6

0.4

0.2

0 0 50 100 150 200 250 300

Frame nr.

Figure 6.6: Interpolation curve and velocity graph for spherical linear quaternion interpolation

{ Slerp. Between the two key frames there are 300 interpolated frames.

essarily optimal. Since p and p p erform the same rotation according to equation 18 page 17, the interp olation

between p and q could p ossibly yield a shorter interp olation path. This can b e established simply by comparing

the distance b etween p and q , kp q k, with the distance b etween p and q , kp + q k. 48

6.2 Interp olation over a series of rotations:

Heuristic approach

When interp olating b etween two rotations Slerp is optimal. In the set of unit quaternions the

interp olation curveofSlerp is equivalent to a straight line the great arc. When interp olating

between a series of rotations problems emerge: a The curve is not smo oth at the control p oints,

b The angular velo city is not constant and c The angular velo city is not continuous at the

controls p oints.

1.2 Angular Velocity Key Frames

1

0.8

0.6

0.4

0.2

0 0 100 200 300 400 500 600 700 800

Frame nr.

Figure 6.7: Interpolation curve and angular velocity graph for Slerp. Between the six key frames,

750 interpolated frames have been generated.

A reparameterization can easily ensure continuity across the entire interp olation. Actually the

interp olation parameter is transformed into a numb er of discrete frames b etween each pair of key

frames. Thus a reparameterization corresp onds to assigning each interval a number of frames

relative to the size of the interval. The size of an interval can b e measured as the angle between

a pair of key frames q and q , given by cos = q q .

i i+1 i i+1



Since the number of frames in each subinterval necessarily has to be an integer the angular

velo city is, due to rounding, only approximately constant. Compare gure 6.7 and gure 6.8.

It is not equally simple to x the lack of smo othness. Analogously it is simple to interp olate

between two p oints in the plane with a straight line, but even in the simple Euclidean space it

is relatively complicated to create a smo oth interp olation b etween a series of p oints see gure

6.9.

When interp olating b etween a series of control p oints in the plane di erent kinds of cubic curves

are typically used. For example this can b e done with B ezier curves, which can b e constructed

quite simply. 49 1.2 Angular Velocity Key Frames

1

0.8

0.6

0.4

0.2

0 0 100 200 300 400 500 600

Frame nr.

Figure 6.8: Interpolation curve and angular velocity graph for Slerp. Between the six key frames,

550 interpolated frames have been generated. The frames in the subintervals are distributed

according to length of the interval.

a b c

Figure 6.9: a In the plane simple interpolation between two points is obtained by a straight

line. b Linear interpolation between a series of points is not di erentiable in the control points.

c To ensure di erentiability one can use cubic curves, for example splines.

B1

A2

P1 P2

P3 P0 B2

A1

Figure 6.10: Interpolation between the points P 1 and P 2 with a B ezier curve. The curve is

de ned as a third-order curve, where the tangent in the control points is de ned by auxiliary

points. For example the tangent in P 1 is de ned by the auxiliary points A1 and B1 the tangent

is B1-P1 or P1-A1. The di erentiability is automatical ly assured since the curve is a third

order curve. 50

The B ezier curve from gure 6.10 with auxiliary p oints B and A  that interp olates b etween

1 2

the control p oints P and P can b e expressed algorithmically based on [Watt & Watt, 1992 ]

1 2

as three steps of linear interp olation:

linx ;x ;h = x 1 h+x h

0 1 0 1

B ez ier P ;P ;B ;A ;h = linlinP ;P ;h;linB ;A ;h; 2h1 h

1 2 1 2 1 2 1 2

The auxiliary p oints can b e moved arbitrarily, which yields a change in the shap e of the curve.

The interp olation curvebetween P1 and P2 is solely determined from the p ositions of auxiliary

p oints B1, A2 relativetocontrol p oints P1 and P2. The tangent at P1 is de ned by the vector

B1-P1 and the tangent at P2 is de ned by the vector A2-P2.

When interp olating b etween a series of control p oints, it is often desirable to ensure di erentia-

bility in the control p oints. This constraint can b e met by making the tangents coincide in the

control p oints, i.e. ensuring that B1-P1 = P1-A1.

6.2.1 Spherical Spline Quaternion interp olation: Squad

The ab ove construction can serve as an inspiration for formulating the spherical cubic equivalent

ofaB ezier curve. This interp olation curve is called Squad spher ical and quadr ang l e and was

presented by Sho emake in [Sho emake, 1987 ].

Sho emake de nes Squad as with h 2 [0; 1]:

De nition 17.

Squad q ;q ;s ;s ;h = Slerp Slerp q ;q ;h; Slerp s ;s ;h; 2h1 h 6.14

i i+1 i i+1 i i+1 i i+1

1 1

q  q  + log q log q

i1 i+1

i i

s = q exp 6.15

i i

4

The resulting expression for Squad is analogous to the B ezier curve, but involves spherical linear

interp olation instead of simple linear interp olation. B1 and A2 are written s and s . The

i i+1

expression for s equation 6.15 will b e derived b elow.

i

Correctness of Squad

The de nition of Squad is complex and therefore neither the continuity nor the di erentiability

of the resulting interp olation curveisobvious.

Squad was originally presented in [Sho emake, 1987 ] which has served as general reference for a

8

pro of of the di erentiabilityof Squad . [Sho emake, 1987 ] is no longer available , and furthermore

8

[Sho emake, 1987 ] is a set of course notes from SIGGRAPH 1987, and these notes are no longer available from

University libraries or ACM. 51

9

the original pro of of di erentiabilitywas awed . In [Kim et al., 1996 ] a new pro of was presented.

However, the di erentiabilityof Squad is a consequence of a more general result in this pap er

and therefore the pro of is not very thorough. In addition, the constants s from prop osition 17

i

were not derived. After corresp onding with Ken Sho emake [Sho emake, 1997 ] wehave therefore

derived a complete pro of of the di erentiabilityof Squad .

Prop osition 30.

1

Squad 2 C

Pro of

That Squad is continuously di erentiable is obvious except at the control p oints, since all the

sub expressions are continuously di erentiable in a given sub-interval and therefore Squad is

continuously di erentiable inside eachinterval.

We must now show continuous di erentiability for Squad at a given control p oint q . First

i

we must show that the neighb oring segments have the control p oints as their value at the end

p oints, i. e. that S q uadq ;q ;s ;s ; 1 = S q uadq ;q ;s ;s ; 0:

i1 i i1 i i i+1 i i+1

Squadq ;q ;s ;s ; 1 = Slerp Slerp q ;q ; 1; Slerp s ;s ; 1; 0

i1 i i1 i i1 i i1 i

= Slerp q ;s ; 0

i i

= q

i

Squadq ;q ;s ;s ; 0 = Slerp Slerp q ;q ; 0; Slerp s ;s ; 0; 0

i i+1 i i+1 i i+1 i i+1

= Slerp q ;s ; 0

i i

= q

i

Thus Squad is continuous and has the correct value at the control p oints.

Wenow show that Squad is continuously di erentiable at a given control p oint. We do this by

deriving the derivativeofSquad in a given interval. Likeabove, wemust then show that

d d

Squad q ;q ;s ;s ; 1 = Squad q ;q ;s ;s ; 0

i1 i i1 i i i+1 i i+1

dt dt

To nd the derivative of Squad , we need the derivative of Slerp , which we get from equation

6.12.

Weintro duce the abbreviation



g h=Slerp q ;q ;h Slerp s ;s ;h

i i i+1 i i+1

Nowwe will nd the derivativeofS q uadq ;q ;s ;s ;h and decide how s and s must b e

i i+1 i i+1 i i+1

de ned to ensure di erentiability at the control p oints.

d d

Squad q ;q ;s ;s ;h = Slerp Slerp q ;q ;h; Slerp s ;s ;h; 2h1 h

i i+1 i i+1 i i+1 i i+1

dt dt

d

2h1h

= Slerp q ;q ;h g h

i i+1 i

dt

9

According to Ken Sho emake. 52

The pro duct rule for di erentiation prop osition 24 yields:

d d

2h1h

Squad q ;q ;s ;s ;h = Slerp q ;q ;hg h

i i+1 i i+1 i i+1 i

dt dt

d

2h1h

Slerp q ;q ;h g h + =

i i+1 i

dt

d

2h1h

Slerpq ;q ;h g h 

i i+1 i

dt

 2h1h

= Slerpq ;q ;h log q q g h +

i i+1 i+1 i

i

d

2h1h

g h Slerpq ;q ;h

i i i+1

dt

Since g h is a pro duct of unit quaternions, the function values are on the unit sphere. Therefore,

i

g hmay b e written:

i

g h = [cos  ; sin v ]

i

g h g h g h

i i i

2h1h

Here v is a unit vector. We can now use prop osition 26 to nd the derivativeof g h :

i

g h

i



d d d

2h1h

g h = sin 2h1 h 2h1 h +2h1 h   ;

i

g h g h g h

i i i

dt dt dt

d d

cos 2h1 h 2h1 h +2h1 h   v +

g h g h g h g h

i i i i

dt dt



d

sin 2h1 h v 

g h g h

i i

dt

h

0

= sin 2h1 h 2 4h +2h1 h ;

g h g h g h

i i

i

0

cos 2h1 h 2 4h +2h1 h v +

g h g h g h

g h

i i i

i

i

0

sin 2h1 h v

g h

g h

i

i

Having expanded all the sub expressions of the derivativeofSquad ,we will now determine s so

i

that the derivativeof Squad is continuous across each control p oint, i. e.

d d

Squad q ;q ;s ;s ; 1 = Squad q ;q ;s ;s ; 0

i1 i i1 i i i+1 i i+1

dt dt



d

2h1h 2h1h

Belowwe write g h 1 for the derivative of the expression g h applied

i1 i1

dt

to the value 1. Using algebra and rearranging, we get:

d



Squad q ;q ;s ;s ; 1 = Slerpq ;q ; 1 log q q +

i1 i i1 i i1 i i

i1

dt

d

2h1h

g h 1 Slerpq ;q ; 1

i1 i1 i

dt



= q log q q +q [0; 2 1v 1]

i i i g g

i1

i1 i1





= q log q q  2 log [cos  1; sin  1v 1]

i i g g g

i1

i1 i1 i1



= q log q q  2 log g 1

i i i1

i1

 

= q log q q  2 log q s 

i i i

i1 i 53

d



Squad q ;q ;s ;s ; 0 = Slerp q ;q ; 0 log q q +

i i+1 i i+1 i i+1 i+1

i

dt

d

2h1h

Slerp q ;q ; 0 g h 0

i i+1 i

dt



= q log q q +q [0; 2 0v 0]

i i+1 i g g

i

i i



= q log q q  + 2 log [cos  0; sin  0v 0] 

i i+1 g g g

i

i i i



= q log q q  + 2 log g 0

i i+1 i

i

 

= q log q q  + 2 log q s 

i i+1 i

i i

Thus, s must satisfy

i

   

q log q q  + 2 log q s  = q log q q  2 log q s :

i i+1 i i i i

i i i1 i

1



Using q = q since q 2 H we get:

i 1

i

i

  

4 log q s  = log q q  log q q 

i i i+1

i i1 i

 

log q q  log q q 

i i+1

i1 i



q s = exp

i

i

4

 

log q q  log q q 

i i+1

i1 i

s = q exp

i i

4

  

To rewrite the expression for s , we use the identity q q  = q q . Since the constituent

i 1 2

2 1

 1 

quaternions are unit quaternions, the identities q = q , and log q  = log q  also hold.

Finally wehave:

 

log q q  + log q q 

i1 i+1

i i

s = q exp

i i

4

1 1

q  q  + log q log q

i+1 i1

i i

= q exp 6.16

i

4

Thus Squad is continuously di erentiable at the control p oints with s de ned as ab ove. All in

i

all we have shown that Squad is continuous and continuouly di erentiable across all segments.

Further observe that the derived equation 6.16 for s is the same as equation 6.15.

i

2

The interp olation curve generated by Squad

The algorithmic expression for Squad yields an interp olation curve for a series of quaternions

q ;::: ;q . The expression is not de ned in the rst and last interval since q app ears in

0 N 1

the expression for s and q app ears in the expression for s . Therefore it is necessary to

0 n+1 n

de ne sound values for s and s . The simplest solution is to de ne s q and s q |

0 n 0 0 N N

alternatively q and q can be de ned. The choice of s and q have little impact on the

1 n+1 0 0

resulting interp olation curve and we will consider the choice an implementation detail.

As for the interp olation curveofSlerp  gure 6.8 it is, for implementation purp oses, necessary

to pro duce a discrete version of the interp olation parameter and thereby selecting the number

of interp olated frames b etween each key frame. For Slerp this pro cess was simple since the arc

length of the interp olation curve corresp onds to the angle b etween the twoinvolved quaternions. 54

Since the interp olation curve for Squad is rounded, it is not simple to calculate the arc length

between each pair of key frames and thus it is not trivial to determine the number of frames

between each pair of key frames. We cho ose to determine the number of frames between each

pair of key frames relative to the distance between the the two key frames. This is not the

optimal choice, but a simple and e ective heuristic.

1.2 Angular Velocity Key Frames

1

0.8

0.6

0.4

0.2

0 0 100 200 300 400 500 600

Frame nr.

Figure 6.11: Interpolation curve and angular velocity graph for Squad. Between the six key

frames we have interpolated 550 frames. The frames have been distributed according to interval

length.

From gure 6.11 it is clear that Squad gives a \nice" interp olation curve. The term \nice" can

b e read as continuous and di erentiable | but even this clari cation is qualitatively vague: A

continuous and di erentiable curve can haveanynumb er of more or less wild twists and turns.

From the formulation of Squad it is far from trivial to determine qualitative prop erties of the

curve. Therefore wewant a more ob jective measure from whichwe can de ne an interp olation

curve. In this context it is no longer adequate to use quali ed guesses to derive new metho ds

of interp olation. However, the previously stated metho ds provide a good foundation for the

development of a more general metho d.

In the next sections we will seek the formulation of a more general metho d from a more mathe-

matical and physical p oint of view. 55

6.3 Interp olation between a series of rotations:

Mathematical approach

So far the interp olation metho ds have b een fairly simple and based on the rotation represen-

tations. In principle, the interp olation is indep endent of which rotational mo dality is used to

implement the metho d. Instead, the optimal interp olation curve should be de ned from the

desired prop erties in the space of rotations. This optimal curve can, of course, be written

algorithmically for any sensible representation of rotation.

The ab ove p oint can b e exempli ed for interp olation b etween two rotations. The optimal inter-

p olation curve is the equivalent of a straight line in the space of rotations. This curve can be

written algorithmically using Euler angles, but the advantage of using quaternions is that the

curve can b e stated simply | using Slerp . This is due to the previously describ ed equivalence

between the space of rotations and the unit quaternion sphere.

Therefore, we will base our discussion b elow on the space of rotations. We will give mathemat-

ically based demands for the optimal interp olation curve. The goal is to give an algorithmic

description of the optimal interp olation curve.

6.3.1 The interp olation curve

Interp olation b etween rotations is de ned in the space of rotations SO3. As mentioned earlier,

however, SO3 and the set, H , of unit quaternions are top ologically equivalent. We therefore

1

cho ose to de ne the general interp olation in the space of unit quaternions.

De nition 18.

Given k control points q 2 H and I = [t ;t ], the interpolation curve t : I y H , is

i 1 1 1

k

constrained by t  q for t 2 I. We require that t  t ;::: ;t  t .

i i i 1 2

k 1 k

6.3.2 De nitions of smo othness

A natural requirement is that the interp olation curve is \nice." This vague term usually means

smo oth in di erential geometry. However, several di erent de nitions of smo oth exist. We

mention the following:

De nition 19.

n n

Let t be the parameterization of a curve in C I; R . Smo oth can then be de ned in the

fol lowing ways:

1 0

[Madsen, 1991 ]: The curve t is smo oth if: t 2 C and 8t 2 I : t 6=0.

2

[Schwarz, 1989 ]: The curve t is smo oth if: t 2 C .

1

[Jakobsen, 1993 ]: The curve t is smo oth if: t 2 C .

The di erent de nitions express that it is not immediately obvious what \nice" is. We must

therefore examine more closely which prop erties wewant the interp olation curvetohave. 56

a b c d

Figure 6.12: Interpolation between three control points in the plane. a Discontinuous interpo-

1 2

lation curve. b Continuous curve. c C -curve. d C -curve.

The curvemust obviously b e continuous. The curvemust also b e di erentiable. We do not want

either \holes" or \breaks" in an animation. Thus we demand that the interp olation curvemust

1 2 1

be C . However, it is not as obvious whether the curve should b e C or, for that matter, C .

Figure 6.12 illustrates the di erent classes of curves in the plane.

Since the control p oints are symmetric, it is natural to exp ect that the interp olation curve

2 1

is symmetric. The illustrations in the plane clearly show that we must demand C over C .

However, illustrations in the plane are not adequate ground to base this choice on, and we

therefore p ostp one this decision see section 6.3.7.

0

In the rst de nition we nd the requirement t 6=0. Thus, the interp olation function is not

allowed to contain singularities, i. e. the interp olation must not \stop." O hand, this seems

to be a sensible demand. However, it is p ossible to make sensible but contradictory demands

to the sp eed of the interp olation curve. Consider, for example, animating a p endulum. The

control p oints that de ne the angle that the p endulum oscillates through will lie on a straight

line in the space of rotations. At the outer p ositions, it is to be exp ected that the p endulum

has no velo city, corresp onding to a singularity in the interp olation function. We therefore also

p ostp one this decision until section 6.3.7.

This discussion of smo othness do es not bring us much further. The de nitions ab ove will not

2

even allow us to di erentiate b etween LinE ul er , Ler p and Slerp . These curves are all C except

0

at the control p oints, where they are C . Thus, it is not sucient just to describ e which class

of functions the interp olation curve should b elong to.

6.3.3 The optimal interp olation

Smo othness considerations do not give adequate requirements to the de nition of the interp ola-

tion curve. We need an ob jective measure of how \nice" our curve is in rotation space.

We will again seek inspiration in the plane see gure 6.13. As mentioned earlier, cubic curves

are usually used to interp olate b etween a series of p oints. There are many kinds of cubic curves;

the B ezier curve describ ed in section 6.2 is an example. The most common class of curves is

splines. 57

a b

Figure 6.13: Interpolating with a spline in the plane. a Simple linear interpolation. b Inter-

polation with a spline.

Discussing splines we must, as any serious pro ject dealing with splines, write a bit ab out ship

builders. Traditionally, when ship builders wanted to decide how to shap e the curved parts of a

ship, a exible piece of metal was used. The piece of metal was xed b etween a series of rivets.

The metal piece then adapted itself to the rivets, making a nice soft curve. The ship builders

10

called this to ol a spline .

Viewed physically, the ab ove description of a spline corresp onds to the piece of metal achieving

a minimum of inner tension forces sub ject to the constraints the rivets. Mathematically, the

metal piece minimizes curvature.

2

In the plane, the curve can b e describ ed as follows. Given the control p oints x ;y  2 R , de ne

i i

2 2 11

t 2 C I; R , where t is the natural parameter , such that t passes through the control

R

00 2

p oints and at the same time minimizes the expression k tk dt. Thus the square of the

I

curvature is minimized.

This simple formulation gives a non-ambiguous de nition of the interp olation curve from a

general concept in di erential geometry. We therefore cho ose to view the curve that minimizes

the square of the curvature as the optimal interp olation curve. As we shall see b elow, it is not

as simple to compute this curveinH as it is in the plane.

1

6.3.4 Curvature in H

1

The interp olation curve lies on H , whichis a hyp ersphere in quaternion space. Normally the

1

00

curvature for a curve t is de ned as k tk, assuming that t is the natural parameter.

The interp olation curve Slerp yields a great arc on the quaternion unit sphere. A great arc in

H is equivalent to a straight line in the plane. Thus it is to exp ected b e that a great arc do es

1

00

not haveany curvature. If the curvature is computed by k tk, the curvature will not b e zero,

but one: The curvature of the unit sphere. We therefore want to compute the curvature relative

to the quaternion unit sphere, and not relative to quaternion space. We will call this curvature

the local curvature.

The de nition of lo cal curvature for a curve that lies on a surface is based in di erential geometry.

The lo cal curvature in a p oint is de ned as follows. Given the p oint on the surface, a co ordinate

system a map is placed in the tangent plane. The lo cal curvature of the curve is now the

curvature of the curve pro jected onto the tangent plane. This is also called tangential curvature.

10

The ambitious pro ject will obviously also note that mo dern-day architects use a re ned version of the ships-

builder's spline to draw curves. According to an architect, however, this is a myth.

11

i. e. the parameter de ned from the curve length. 58

In di erential geometry a great arc the \straight line" is called a geo desic. Pro jected onto the

tangent plane, the geo desic b ecomes a straight line. Thus we see, as exp ected, that a great arc

do es not haveany lo cal curvature.

0 00

t t t

t

00

t

o

a b

00

Figure 6.14: The division of t | an analogy in the plane. a The position vector for the

curve t lies on the surface of the quaternion unit sphere. The tangential plane is orthogonal

00 00

to the position vector. b t can be split in a component t in the tangential plane and

t

00

a component t paral lel with the position vector.

o

00

t into two parts see gure 6.14: a If a curve t lies on the surface of H , we can split

1

00 00

comp onent, t, in the tangential plane , and a comp onent, t, orthogonal to the tangential

t o

00

plane. The desired part of the curvature is t. Thus, the lo cal curvature  of the curve can

t

b e obtained:

00 00 00

 ; t=k tk = k t tk

t o

00

Since t lies on the surface of the unit sphere, t will b e parallel to t. Thus we can nd

o

00 00

tby pro jecting tonto t. Thus:

o

00 00 00

t = t t

t o

t t

00 00

= t t



k tk k tk

00 00

= t  t t t



De nition 20.

2

Given t 2 C I;H , the local curvature  ; t is de ned:

1

00 00

 ; t=k t  t t tk



Note that t is not necessarily the natural parameter. Thus the ab ove de nition is not correct

12

in a strict di erential geometric sense . However, we are not only interested in the shap e

curvature of the interp olation curve. We also want a \nice" angular velo city function, i. e. one

that minimizes angular acceleration corresp onding, from a physical viewp oint, to minimizing

the energy. In the ab ove expression the angular acceleration is automatically included, exactly

b ecause we do not reparameterize to the natural parameter.

12 00

The curvature for a curve parameterised on the natural parameter can b e written  ; t=k tk. In general

for a smo oth curve, the correct expression from di erential geometry is:

0 00 0

00

t t t

t



 ; t=

0 2 0 4

k tk k tk 59

6.3.5 Minimizing curvature in H : Continuous, analytical solution

1

We de ned the optimal interp olation curve in H as the curve that minimizes the square of

1

the curvature, but with the restriction that it must pass through the control p oints. We then

de ned the relevant expression for curvature in H . We thus get the following formulation of

1

the problem:

k

Given the control p oints q ;::: ;q 2 H we seek t 2 C I;H  such that there exist

1 N 1 1

t ;::: ;t 2  I  that satisfy t =q , and such that this expression is minimized:

1 N i i

Z

t

N

2

K  = k ; hk dh 6.17

t

1

The problem of minimizing an integral of a function is called a calculus of variations problem.

Below, we will outline the basic metho d used for solving problems in the calculus of variations.

0

A necessary condition for K   to attain a minimum is that K   = 0. For  2 R and

k

 2 C I;H we lo ok at the \derivative":

1

K  +  K  

lim =0 6.18

 !0



In the ab ove expression,  is called the variation of , and the function +  is called the

k

comparison function. A function h 2 C I;H  that satis es the b oundary conditions i. e.

1

t =q for i =1;::: ;N is called an admissible function.

i i

We will now derive the requirements a solution to the variation problem must meet. We therefore

assume that b oth the solution and the comparison function +  are admissible, and that

K   is minimal.

For the comparison function +  to b e admissible, it must b e the case that

 t = t =::: =  t =0 6.19

1 2 N

2

Furthermore, since and +  lie on the surface of the unit sphere, we have that k k =1

2 13

and k + k =1. Thus wehave :

2

1 = k + k

2 2 2

= k k +  k k +2   



2

= 1+  k k +2  



m



2

 = k k 6.20



2

13

In the derivations b elow, it is p ossible to ignore the fact that the constituent expressions contain quaternion

functions. This is due to the fact that quaternion multiplication is not used only the scalar pro duct, , is used.



Therefore, there are no problems with commutativity. 60

Wewant to use our knowledge of the \derivative" and examine K  +  K  :

K  +  K  

Z

t

N

2 2

k + ; hk k ; hk dh =

t

1

Z

t

N

00 00 2 00 00 2

= k +   +   +  + k k   k dh

 

t

1

Z

t

N

2 00 2 00 00 00 00 00

  + k  +   +   +  k +   =

   

t

1

2 00 00

 k dh k 



Z

t

N

00 00 00 00 00 00 2 3 2

= k[   ]+ [        ]+ [:::]+ [:::]k

   

t

1

2 00 00

 k dh k 



In the ab ove expression, we have collected terms according to the exp onent of  . The goal of

the ab ove derivations is to nd the \derivative." In the expression for K  +  K   terms

2 3

multiplied by  and  can b e removed b ecause they disapp ear when examining the limit, after

b eing divided by  . Thus the expression can b e written:

Z

t

N

2 2

K  +  K   = kA + B k kAk dh

t

1

Z

t

N

2 2

=  kB k +2A B dh



t

1

00 00 00 00 00 00

Here A =   and B =         . Again wemay omit

   

2

terms multiplied by  , and we can rewrite the expression:

Z

t

N

00 00 00 00 00 00

2 [   ] [         ] dh K  +  K   =

    

t

1

Z

t

N

00 00 00 00 00 00 00 00

             = 2

      

t

1

00 00 00 00 00 00

   +    +    

       

00 00

+     dh

  

2

We can now use the fact that = k k =1, since lies on the surface of the unit sphere.





2

Furthermore, equation 6.20 is used to rewrite  = k k . We then get:

2



Z

t

N



00 00 00 00 00 00 2 2

    +  +   K  +  K   = 2 k k  dh

    

2

t

1

Z

t

N

00 00 00 00 00

= 2     +   dh

   

t

1 61

2

Wehaveyet again ignored terms multiplied by  .

After numerous rewritings, we have isolated  as a single factor. This factor will disapp ear in

the expression for the derivative when divided by  . We therefore now want to isolate terms

containing  . This is attempted using partial integration. The expression is rewritten as follows:

N 1

X

L K  +  K   = 2

i

i=1

Z

t

i+1

00 00 00 00 00

L =

    +   dh

i

   

t

i

Z

t

i+1

00 00 00 00 00

  dh        =

   

t

i

t

i+1

0 00 00

   ] = [ 

t

 

i

Z

t

i+1

d

00 00 0 00 00

 f   g      dh

   

dh

t

i

d

t t

i+1 i+1

00 00 00 00 0

f   g  ] = [     ] [

t t

  i   i

dh

Z

t

2

i+1

d

00 00 00 00

f   g      dh + 

   

2

dh

t

i

Note that the ab ove expression requires that is four time s di erentiable. Nowwe can use that

 is zero in all the control p oints equation 6.19 to see that the second term is zero:

Z

t

2

i+1

d

t

i+1

0 00 00 00 00 00 00

 +    ] L = [    dh   g   f 

i

t

     

i

2

dh

t

i

We again consider the whole expression:

N 1

X

K  +  K   = 2 L

i

i=1

N 1

X

t

i+1

00 00 0

= 2 [     ]

t

 

i

i=1

Z

N 1

t

2

i+1

X

d

00 00 00 00

f   g      dh +2 

   

2

dh

t

i

i=1

t

00 00 0

n

    ] = 2 [

t

  1

Z

N 1

t

2

i+1

X

d

00 00 00 00

 +2 f   g    dh

  

2

dh

t

i

i=1

The last rewriting uses continuity in the control p oints. We can nd the \derivative"

K  +  K  

t

00 00 0

N

lim = 2[     ]

t

  1

 !0



Z

N 1

t

2

i+1

X

d

00 00 00 00

+2  f   g    dh

  

2

dh

t

i

i=1 62

Since the derivativemust b e zero equation 6.18 for any  , we get the following requirements

to the solution:

4

2 C  I ;H 

1

00 00

0 = t   t  t  t 

1 1 1 1



00 00

0 = t   t  t  t 

N N N N



2

d

00 00 00 00

 g f   = 

 

2

dh

0000 00 00 00 0 0 00 00

=   2   

  

The second and third requirements are equivalent with the lo cal curvature b eing zero at the

end-p oints. The last requirement can b e rewritten using = k k =1:



00 00 00 0 0

0 = 1 =  =2 +2 6.21

  

Now we can state the set of di erential equations, that must be solved to nd an analytical

solution to the desired optimal interp olation curve:

Prop osition 31.

4

Given the control points q ;::: ;q 2 H the interpolation curve 2 C I;H , where t =q

1 N 1 1 i i

R

t

N

2

for t 2 I, wil l minimize khk dh if the fol lowing requirements are met:

i

t

1

1. t =0

1

2. t =0

N

3. For each interval t

i i+1

0000 0 0 00 0 0 0 0 0 0 00

+  +2  +2  =0

  

Now \all" that remains is to solve the ab ove fourth-order di erential equation with the given

b oundary values. This, unfortunately, is not p ossible with the existing mathematical knowledge.

14 15

This is con rmed by Jrgen Sand and Gerd Grubb .

6.3.6 Minimizing curvature in H : Continuous, semi-analytical solution

1

The strict mathematical derivation of the desired optimal interp olation curve stranded on an

unsolvable di erential equation.

We can, however, again seek inspiration in the plane. The corresp onding di erential equation

0000

is here =0, i. e. that the fourth derivative of the curve must be zero between the control

p oints. This corresp onds to a third-order curve a spline. If the solution is constrained to b e a

third-order curve, the equations can b e solved more easily.

14

Asso ciate Professor at the Institute of Computer Science, University of Cop enhagen, sp ecializing in the

solution of systems of equations.

15

Professor at the Institute of Mathematics, University of Cop enhagen, sp ecializing in di erential equations. 63

We could therefore restrict which family of functions we would like the interp olation curve to

b elong to. This could, for example, b e a kind of cubic splines. With this restriction on the set

of p ossible solutions, the optimization problem could b e solved.

Dep ending on the choice of de nition of the family of curves, this strategy for nding a solution

will give a result corresp onding to the basis for the construction of Squad .

Tokeep this rep ort at a manageable size, we will not pursue this line of thoughtany further.

6.3.7 Minimizing curvature in H : Discretized, numerical solution

1

Unfortunately, we cannot give an analytical expression for the optimal interp olation curve.

Therefore we will try to solve a discrete version of the problem using a numerical metho d.

We rewrite the problem in an equivalent discrete version. We then solve the new version of the

problem.

Discretization

k

Given the control p oints Q ;::: ;Q 2 H we sought an analytical solution t 2 C I;H 

1 1 1

k

such that there existed t ;::: ;t 2 I , that t =Q , and such that the following expression

1 i i

k

was minimized:

Z

t

k

2

K  = k ; tk dt 6.22

t

1

In the discrete version we will therefore attempt to solve the following problem. Given control

p oints Q ;::: ;Q 2 H we seek q ;::: ;q 2 H such that q = Q for t = 1;::: ;k and such

1 1 1 N 1 i t

k

t

that the following expression is minimized:

N

X

2

l q  k~ q k 6.23 E =

i i

i=1

The integral has b een replaced by a sum. The \parameter width" of the interval we integrate

over is termed l q . It can be expressed as a centered average of the parameter width in the

i

intervals immediately b efore and after the i'th quaternion:

kq q k + kq q k

i i1 i i+1

l q  = 6.24

i

2

Another measure of the parameter distance b etween q and q in the approximation for l q 

i i1 i

could b e , where cos = q q , instead of kq q k.

i i i i+1 i i1



In equation 6.23 ~ is the discrete version of the lo cal curvature:

00

q q

i

i

00



q 6.25 ~ q  = q

i i

i

q q

i i

 64

q is not omitted as in the de nition of lo cal curvature page 59. Note that the denominator q

i i



This is b ecause the interp olated quaternions cannot b e exp ected to b e unit quaternions this is

explained b elow. Therefore, the denominator is not in general equal to 1; thus it cannot be

omitted.

In equation 6.25 the second derivative of the discrete approximation of the interp olation curve

is used. A good centered approximation of the second derivative is [Kincaid & Cheney, 1991 ],

[Barr et al., 1992 ]:

q 2q + q

i1 i i+1

00

q = 6.26

i

2

l q 

i

Gradient descent

The ab ove equation equation 6.23 can b e minimized using gradient descent. In general terms,

gradient descent can be describ ed as follows. Consider the function that is to be minimized

commonly termed the energy function  as a hilly landscap e, where the function value is the

height of a hill at each set of co ordinates. The gradient of the function in that p oint p oints

in the steep est p ossible up-hill direction. Gradient descent is based on an initial guess at the

solution. From the initial guess the gradient is computed, and a small step is taken in the

opp osite direction of the gradient i. e. down-hill, resulting in a new p oint. This pro cess is

rep eated with the new p ointuntil the function value do es not b ecome smaller by taking a step.

In this fashion, the gradient descent metho d yields an approximate lo cal minimum. It is outside

the scop e of this rep ort to describ e the theory of gradient descent any further, but we will

describ e the metho d in enough detail so that readers without prerequisites in the eld will still

b e able to follow the derivations.

When using numerical approximation metho ds such as gradient descent, it is often dicult to

maintain restrictions on the solution space. Instead a term is added that makes the solution

16

more \exp ensive" if the solution lies outside the desired solution space. Thus, we seek a

function that can determine if the discrete version of the interp olation curve lives in H , and

1

thus consists of unit quaternions. This can b e done by:

g q =q q 1 6.27



Note that H = fq 2 H j g q =0g. This measure for determining if the quaternions are unit

1

quaternions can b e combined with the energy function E as follows:

N

X

2 2

l q  k~ q k + cgq  6.28 F =

i i i

i=1

Assuming c 2 R suitably large, the energy function F will have a minimum approximately where

E has a minimum, and where all q are approximately unit quaternions.

i

16

We here assume \the cheap er, the b etter", which is not always the case in real life. Sometimes you haveto

pay extra for quality. Red wine is a go o d example of this, although there are, of course, exceptions in this case,

to o. 65

Wewant to nd a minimum for F in equation 6.28 using gradient descent. We therefore haveto

nd the gradient. Below, we will write q for the x'th co ordinate regarding a quaternion as a

i;x

four-dimensional vector in the i'th quaternion in the discrete interp olation curve. The gradient

is 4n-dimensional. Each co ordinate can b e written:

0 1

N

X

@F @

2 2

@ A

= l q  k~ q k + cgq 

j j j

@q @q

i;x i;x

j =1

In equations 6.24, 6.25, and 6.26, q is a term in the discrete versions of l q , l q , l q ,

i i1 i i+1

~ q , ~ q  and ~ q . The corresp onding terms must app ear in the partial derivative:

i1 i i+1



@ @F

2 2 2 2

= l q  k~ q k + l q  k~ q k + l q  k~ q k + cgq 

i1 i1 i i i+1 i+1 i

@q @q

i;x i;x



@

2

= l q  ~ q  ~ q +l q  ~ q  ~ q +l q  ~ q  ~ q +cgq 

i1 i1 i1 i i i i+1 i+1 i+1 i

  

@q

i;x

@lq  @lq  @lq 

i1 i i+1

= ~ q  ~ q + ~ q  ~ q + ~ q  ~ q +

i1 i1 i i i+1 i+1

  

@q @q @q

i;x i;x i;x

@ ~ q  @ ~ q  @ ~ q 

i i+1 i1

+2l q ~ q  +2l q ~ q  + 2l q ~ q 

i i i+1 i+1 i1 i1

  

@q @q @q

i;x i;x i;x

@ g q 

i

6.29 2cgq 

i

@q

i;x

Belowwe will derive the partial derivatives for the sub-expressions of the ab ove expression.

Weintro duce the notation 1 to b e the vector with 1 in the x'th co ordinate, and 0 in the other

x

co ordinates. We can now lo ok forward to deriving the partial derivatives of g q , l q , l q ,

i i1 i

00 00 00

l q , q , q , q , ~ q , ~ q  and ~ q :

i+1 i i1 i+1

i1 i i+1

@ g q  @

i

= q q 1

i i



@q @q

i;x i;x

@ q

i

= 2 q

i



@q

i;x

= 2 q 6.30

i;x

@ l q  kq q k + kq q k @

i1 i1 i2 i1 i

=

@q @q 2

i;x i;x

q q

1 @

= q q  q q + q q  q q 

i1 i2 i1 i2 i1 i i1 i

 

2 @q

i;x

0 1

1 q q 

1

x i1 i



@ A

q

=

2

q q  q q 

i1 i i1 i



1 q q 

x i i1



= 6.31

2 kq q k

i1 i 66

@ kq q k + kq q k @ l q 

i i1 i i+1 i

=

@q @q 2

i;x i;x

q q

1 @

q q  q q + q q  q q  =

i i1 i i1 i i+1 i i+1

 

2 @q

i;x

0 1

q q  1 q q  1

1

i i1 x i i+1 x

 

@ A

q q

= +

2

q q  q q  q q  q q 

i i1 i i1 i i+1 i i+1

 

q q  1 q q  1

i i+1 x i i1 x

 

+ 6.32 =

2 kq q k 2 kq q k

i i1 i+1 i

@ @ l q  kq q k + kq q k

i+1 i+1 i i+1 i+2

=

@q @q 2

i;x i;x

q q

1 @

= q q  q q + q q  q q 

i+1 i i+1 i i+1 i+2 i+1 i+2

 

2 @q

i;x

0 1

q q  1

1

i+1 i x



@ A

q

=

2

q q  q q 

i+1 i i+1 i



1 q q 

x i i+1



= 6.33

2 kq q k

i+1 i

00

@ q

@ q 2q + q

i2 i1 i

i1

=

2

@q @q l q 

i;x i;x i1

@ @

2 2

q 2q + q  q 2q + q  l q  l q 

i2 i1 i i2 i1 i i1 i1

@q @q

i;x i;x

=

4

l q 

i1

@ @

2

l q  q q 2q + q 2l q  l q 

i1 i i2 i1 i i1 i1

@q @q

i;x i;x

=

4

l q 

i1

@

2

l q  1 2q 2q + q l q  l q 

i1 x i2 i1 i i1 i1

@q

i;x

= 6.34

4

l q 

i1

00

@ q @ q 2q + q

i1 i i+1

i

=

2

@q @q l q 

i;x i;x i

@ @

2 2

q 2q + q  q 2q + q  l q  l q 

i1 i i+1 i1 i i+1 i i

@q @q

i;x i;x

=

4

l q 

i

@ @

2

2q  q 2q + q 2l q  l q  l q 

i i1 i i+1 i i i

@q @q

i;x i;x

=

4

l q 

i

@

2

2l q  1 +2q 2q + q l q  l q 

i x i1 i i+1 i i

@q

i;x

= 6.35

4

l q 

i 67

00

@ q

@ q 2q + q

i i+1 i+2

i+1

=

2

@q @q l q 

i;x i;x i+1

@ @

2 2

l q  q 2q + q  q 2q + q  l q 

i+1 i i+1 i+2 i i+1 i+2 i+1

@q @q

i;x i;x

=

4

l q 

i+1

@ @

2

q q 2q + q 2l q  l q  l q 

i i i+1 i+2 i+1 i+1 i+1

@q @q

i;x i;x

=

4

l q 

i+1

@

2

l q  l q  1 2q 2q + q l q 

i+1 i+1 x i i+1 i+2 i+1

@q

i;x

= 6.36

4

l q 

i+1

00

q q

@ @ ~ q 

i1

i1

i1

00



q = q

i1

i1

q @q @q q

i1 i;x i;x i1



00

@q

i1

00

q

i1

@ q

@q



i;x

i1

= q 6.37

i1

q @q q

i1 i;x i1



00

q q

@ ~ q  @

i

i

i

00



= q q

i

i

@q @q q q

i;x i;x i i



00 00

00

q q q q

@ @ q @ q

i i

i

i i

  i

q =

i

@q q @q @q q q q

i;x i i;x i;x i i i

 

00 00

00

q q q q

@ @ q

i i

i i

i

 

q 1 =

i x

@q q @q q q q

i;x i i;x i i i

 

0 1

00

@q q @q q

i i i

i

00

 

00

00

q q q q

i i i

q q

@ q i

@q @q

i

 

B C

i;x i;x

i

 i

1 q =

@ A

x i

2

q q  @q q q

i i i;x i i

 

0 1

00

@q

@q @q

00 00

i i

i

00

00 q + q q q 2 q q q

i i i i i

i q q i

@q @q @q

@ q     

i

i;x i;x i;x

i

i



@ A

= 1 q

x i

2

@q q q q q 

i;x i i i i

 

0 1



00

@ q

00 00

i

00

q q 1 q 2 q q 1 q + q 00

i x i i i x i

i i

q q

@q

     @ q

i

i;x

i

i



@ A

1 q 6.38 =

x i

2

q q  @q q q

i i i;x i i

 

00

q q

@ ~ q  @

i+1

i+1

i+1

00



q = q

i+1

i+1

q @q @q q

i+1 i;x i;x i+1



00

@q

i+1

00

q

i+1

@ q

@q



i;x

i+1

= q 6.39

i+1

q @q q

i+1 i;x i+1



We now have simple but long expressions for all the terms in the gradient. We return to

the gradient equation equation 6.29. All the constituent terms have b een derived, and the

gradient can be explicitly computed by substituting the derived terms for ~ q , ~ q , and

i1 i

@ ~ q  @ ~ q 

@ ~ q 

i1 i+1

i

~ q  equation 6.25 and the partial derivatives , and equations 6.37,

i+1

@q @q @q

i;x i;x i;x

6.38, and 6.39 into the equation of the gradient equation 6.29. 68

The algorithm

Wehavenow derived an explicit discrete expression for the gradient, and we can p erform gradient

descent according to the following algorithm:

Initialization

0

Give a go o d initial guess q =q ;::: ;q . An obvious way of doing this is by using one

1 N

of the metho ds describ ed earlier Slerp or Squad . The b etter the initial guess, the faster

the metho d converges.

Iteration

Write out the gradient using equation 6.29:

@F @F @F @F @F @F @F @F

rF = ; ; ; ; :::;  ; ; ; 

@q @q @q @q @q @q @q @q

1;1 1;2 1;3 1;4 N;1 N;2 N;3 N;4

We set the gradient to zero in all key frames.

i+1 i

Perform the iteration on the solution guess: q = q erF , where e de nes the step

length

rF

i+1 i

. This Alternatively: Perform the iteration on the solution guess: q = q e

krF k

metho d can provide greater numerical stability.

Termination condition

Rep eat the second step until a suitable termination condition has b een reached. The

termination condition can b e dep endent on the numb er of iterations, the total energy, F ,

the energy F in relation to the numb er of control p oints, the size of the gradient, or more

advanced strategies.

Alternative metho ds for computing the norm of the interp olation curve

As noted ab ove, wewant the interp olation curve to lie in the space, H , of unit quaternions. This

1

is ensured by using the p enalty function g from equation 6.28. It can b e dicult to determine

when the weighting factor, c 2 R , of the p enalty function equation 6.28 is \suitably large." In

theory, c must b e in nite to ensure that q 2 H . Several metho ds exist to handle this problem:

i 1

Pro jection

There is a simple and well-de ned connection b etween p oints inside and outside the solu-

tion space. As describ ed previously, all quaternions on a line through the origin p erform

the same rotation. Thus the solution guess can simply be pro jected into the solution

space by normalizing the generated quaternions. This can be done in each iteration or,

alternatively, after the last iteration.

Lagrange Multipliers

The p enalty function g q  can also be intro duced with a Lagrange Multiplier  in the

i i

following manner:

N

X

 g q  F = E +

i i

i=1 69

A solution to equation 6.22 is a singularity for F . However, the singularity will not be a

minimum, but instead a saddle p oint. Thus gradient descent is still an applicable metho d

for the constituent quaternions, but gradient ascent must be p erformed on the auxiliary

variables  .

i

By including the p enalty function b oth in equation 6.28 and a Lagrange Multiplier, the

metho d b ecome more numerically robust and converges faster. The details of this metho d

can b e found in [Platt & Barr, 1988 ] and in [Barr et al., 1992 ].

Polar co ordinates

In the ab ove metho d of solving the problem, wehave reformulated the problem such that

the restrictions on the solution space are integrated into the energy function that is to

be minimized. However, we can restate the restriction on the solution space such that

the complexity of the expression to be minimized do es not increase. This can be done

be representing the quaternions using p olar co ordinates. Thus a quaternion is written

q = [r; ; ; ], where r is the radius and , , and  are the three necessary rotation

angles.

Using this representation, it is very easy to maintain the restriction on the solution space.

This can b e done by not p erforming gradient descent on the radius co ordinate, that is kept

at a constantvalue of 1. Thus the restriction on the solution space is maintained.

Amongst the ab ove representations, p olar co ordinates will ensure that the interp olation curve

stays in the space, H , of unit quaternions. The use of Lagrange Multipliers would ensure a

1

more robust and faster converging algorithm. We will not pursue either p ossibility, since wewant

the algorithm to b e as simple as p ossible. We regard normalizing the generated quaternions as

\cheating" seen from a theoretical viewp oint. We will therefore not discuss any of the three

alternative metho ds any further.

Extensions to the algorithm

Generally, gradient descent is a metho d that is fairly easily expanded. The desired prop erty

of the interp olation curve must simply be describ ed as a zero-crossing for some function. For

example we mightwant to ensure constant angular velo city across the entire interp olation curve.

This can b e obtained using yet another p enalty function:

w q =kq q kkq q k 6.40

i i1 i i i+1

Thus the p enalty function increases with the di erence b etween the previous and the following

step length. This p enalty can simply b e intro duced into the algorithm byintro ducing it in the

original energy function equation 6.28:

N

X

2 2 2

F = l q  k~ q k + c g q  + c w q  6.41

i i g i w i

i=1

An extra term must be added to the gradient. This is easily derived since w q  =2l q  and

i i

the derivative can thus b e obtained using equation 6.32:

1 q q  1 q q 

@ w q 

x i i1 x i i+1

i

 

= + 6.42

@q kq q k kq q k

i;x i i1 i+1 i 70

Adding the ab ove p enalty do es not ensure constant sp eed in the interp olation curve. This is due

to the fact that the gradient contains other terms that a ect the distance b etween the individual

key frames. As stated earlier, lo cal curvature is de ned such that b oth the geometric curvature

and the size of the angular acceleration of the interp olation curve are included. In practice, this

means that the angular velo city of the interp olation curve will b e smaller around the key frames,

17

where the curvature of the interp olation curve is maximal .

When the gradient contains terms that act in opp osite directions, the algorithm b ecomes less

robust. Thus setting c \suitably large" will not necessarily ensure approximately the same

w

distance between the interp olated frames. Instead this could lead to the metho d b ecoming

numerically unstable, pro ducing unwanted results.

The implementation

The ab ove description of the algorithm is purely theoretical. Since we did not want to analyze

the convergence and stability prop erties of the algorithm theoretically, there is no guarantee

that the metho d works in practice. We will therefore presenta numb er of considerations to take

into account when implementing the algorithm.

Multi-step minimization

In practice, the algorithm b ehaves badly when given many frames. Each frame is only a ected

by its neighb ors, and only key frames are p ositioned correctly initially. Thus the adaption to

the key frames must propagate through all the frames between the keys and a given frame.

The more frames that lie in-b etween, the more iterations are necessary for the system to attain

an energy minimum. This give a practical upp er b ound on the acceptable number of frames

between eachkey frame.

An ecient way of solving this problem is by minimizing in several steps. In the rst step

relatively few frames are used, and the system attains an energy minimum after few steps. The

frames computed in the rst step are used as key frames in the second step. In the second step

more in-b etween frames are added, and an energy minimum is again attained after a few steps.

This pro cess may b e rep eated an arbitrary numb er of times, until the desired numb er of frames

has b een reached.

In gure 6.15 the result of the algorithm is seen with all frames placed during the rst step. This

gives a bad approximation curveeven after many iterations. The result b ears great resemblance

to Slerp , whichwas used to generate the initial guess passed to the optimization algorithm.

If the multi-step algorithm is used, a much nicer interp olation curve is pro duced after fewer

iterations. In gure 6.16 the intermediate result with few frames can be seen. This is used as

the initial con guration for the second step, and the nal interp olation curve can be seen in

gure 6.17. The angular velo city graph is also nicer when the multi-step algorithm is used. If

the one-step metho d is used see gure 6.15, the velo city curve resembles an electro cardiogram,

while the velo city curve for the multi-step algorithm 6.17 is somewhat nicer, but still somewhat

17

This is natural seen from a physical p ersp ective. It is also necessary to drive slower through a sharp b end in

the road than it is on a straight section. 71 1.2 Angular Velocity Key Frames

1

0.8

0.6

0.4

0.2

0 0 50 100 150 200 250 300 350

Frame nr.

Figure 6.15: One-step iteration. The interpolation curve contains 350 frames, and is shown

after 500 iterations.

uneven. This is a weakness in our implementation, but we exp ect that a more robust algorithm

with b etter convergence prop erties will yield nicer velo city graphs.

All in all, 450 iterations are used for the multi-step metho d versus 500 in the original version.

The result is obviously nicer when the multi-step metho d is used.

1.2 Angular Velocity Key Frames

1

0.8

0.6

0.4

0.2

0 0 5 10 15 20 25

Frame nr.

Figure 6.16: The multi-step algorithm, rst step. In the rst step only 22 frames and 200

iterations are used.

Simplifying the parameter width { l q 

i

In equation 6.24 a numerical approximation to the \parameter width" for the parameter of the

interp olation curve is given. In practice it turns out that this expression has no in uence on

the shap e of the interp olation curve. The algorithm b ecomes less numerically stable with the

expression, however. We therefore use the simpler expression:

l q  = 1 6.43

i 72 1.2 Angular Velocity Key Frames

1

0.8

0.6

0.4

0.2

0 0 100 200 300 400 500 600

Frame nr.

Figure 6.17: The multi-step algorithm, nal result. In the second step, 110 frames are in-

terpolated using 150 iterations. In the third and nal step, 550 frames and 100 iterations are

used.

@ l q  @ l q 

i i1

=

@q @q

i;x i;x

@ l q 

i+1

=

@q

i;x

= 0 6.44

The expression for the gradient equation 6.29 is simpli ed corresp ondingly:

@F @ ~ q  @ ~ q  @ ~ q 

i1 i i+1

= 2~ q  +2~ q  +2~ q 

i1 i i+1

  

@q @q @q @q

i;x i;x i;x i;x

@ g q 

i

+2cgq  6.45

i

@q

i;x

Weighting the curvature at the key frames

The analytical version of the minimization of curvature ensures that the curvature is minimized

by de nition. The discrete numerical approach only gives an approximation of the solution

with minimized curvature. The validity of the approximation to the solution dep ends on the

approximations to the constituent mathematical expressions. For example the second derivative

of the interp olation curve is approximated with:

q 2q + q

i1 i i+1

00

q =

i

2

l q 

i

It is this approximation that is at the core of the approximation of the lo cal curvature of

the interp olation curve. O hand, it is dicult to predict if this approximation intro duces

\weaknesses" to the numerical solution when interp olating between key frames with certain

prop erties. 73 1.2 Angular Velocity Key Frames

1

0.8

0.6

0.4

0.2

0 0 20 40 60 80 100 120 140 160 180 200

Frame nr.

Figure 6.18: The multi-step algorithm used on a set of key frames with a sharp curve. 200

frames are interpolated.

In practice the numerical metho d is somewhat sensitive to sharp curves. For example the curve

in gure 6.18 is to o \sharp" in the middle key frame.

The approximation to the curvature do es not adequately propagate across key frames. Let us

reexamine the gradient the simpli ed version, equation 6.45:

@F @ ~ q  @ ~ q  @ ~ q  @ g q 

i1 i i+1 i

= 2~ q  +2~ q  +2~ q  +2cgq 

i1 i i+1 i

  

@q @q @q @q @q

i;x i;x i;x i;x i;x

The last term makes sure that the quaternions remain unit quaternions. This can be ignored.

This leaves three considerations when determining the gradient, and thus the movement of the

individual frame during the iteration. These are the changes in curvature in the quaternion

itself, and in b oth its neighb ors.

It is tempting to think that it is enough to consider curvature in the quaternion itself. However,

if the neighb ors are not taken into consideration, the result will b e trivial, namely Slerp . Here

every frame except the key frames has zero curvature. Therefore no comp ensation will b e made

for the large curvature in the key frames.

Thus minimizing curvature at the key frames dep ends only on that the immediate neighb ors of

each key frame must \take note of " the curvature of their neighb ors. This is ensured by the

@ ~ q  @ ~ q 

i1 i+1

terms 2 ~ q  and 2 ~ q  . As shown by the example in gure 6.18, this

i1 i+1

@q @q

 

i;x i;x

is not quite sucient.

The approximation of the second derivative of the interp olation curve is therefore not a good

approximation in this particular case. The approximation is to o lo cal, and should have a wider

domain. Since this is not a rep ort on numerical calculation metho ds, wehave not attempted to

nd an optimal approximation expression.

The problem wehave describ ed can b e eliminated simply, though. Each key frame can simply

\ask" its neighb ors to b e more \considerate." This means that we add a weighting function to 74

each expression in the gradient. The weight is dep endent on whether or not a given frame is a

@ ~ q  @ ~ q 

i1 i1

neighborofakey frame. For example, 2 ~ q  will b e replaced by c 2~ q  ,

i1 i1

k

@q @q

 

i;x i;x

if q is a key frame. In practice, a go o d value for c is ab out 1.2. The e ect of the weighting

i1

k function can b e seen in gure 6.19.

1.2 Angular Velocity Key Frames

1

0.8

0.6

0.4

0.2

0 0 20 40 60 80 100 120 140 160 180 200

Frame nr.

Figure 6.19: The multi-step algorithm with a set of key frames with a sharp curve. 200 frames

are interpolated, and the curvature around the key frames are weighted with a factor 1.2

Adding a constant to the algorithm \by eye" is at o dds with our stated purp ose of deriving

an interp olation curve from ob jective criteria. The alternative is to analyze the prop erties of

di erent numerical approximations. This, like the prop erties of convergence and stability, is

outside the scop e of this pro ject.

Remaining details

Wehave not describ ed the termination requirements for the algorithm describ ed ab ove. In the

implementation wehavechosen the simplest p ossible: The numb er of iterations.

Corresp ondingly,wehave not de ned the initial guess that the algorithm uses. Wehave elected

to use Slerp between each pair of key frames. This starting p oint is clearly not optimal. Quicker

convergence might be achieved using Squad . Since the purp ose was to derive a interp olation

curve that is sup erior to Squad , it seemed to be more fair to use Slerp as the basis for the

iteration.

The remaining constants in the algorithm the step size, e, in the iteration, and the p enalty fac-

tor, c can all b e calculated from robustness and convergence criteria. As previously mentioned,

we will not describ e these prop erties any further, and regard the constants as implementation

details see the intro duction to the program in app endix C.

The interp olation curve summarized

The mo dest purp ose of this chapter was to develop the optimal interp olation from ob jective,

general criteria to the interp olation curve. 75

We rst studied the more or less heuristic interp olation curves that are to be found in the

literature. These included the naive LinM at, LinE ul er , Ler p, the simple Slerp , and nally the

convincing Squad .

Using these simple interp olation curves as a basis we tried to de ne which class of functions the

interp olation curve should b elong to page 56. Wewere not able to determine which de nition

of smo othness was suitable to de ne the class of desired functions.

We then attempted to de ne an interp olation curve that minimized the integral of the lo cal

curvature de ned in equation 6.17 of the interp olation curve. These derivations required

that the interp olation curve is four times di erentiable with continuous derivatives i. e. t 2

4

C I;H . This is noted on page 62 in section 6.3.5. Unfortunately, this derivation gave rise

1

to a fourth-order di erential equation that we were unable to solve. Thus it is irrelevant to

consider the op en questions from section 6.3.2: How many times di erentiable should the curve

b e and are singularities allowed?

Thus we settled for a discrete, numerical solution. We have presented a metho d based on

gradient descent. We examined and re ned the metho d. The nal result were some very pleasing

interp olation curves.

As our nal interp olation algorithm we will cho ose the basic algorithm from section 6.3.7 with

the relative distribution of frames in the sub-intervals see section 6.2.1 on page 55 and with

the weighting of the curvature around the key frames. This interp olation curve we will name

Spring for Spherical Interp olation using Numerical Gradient descent. In gure 6.20, the

e ect of using Spring can be seen. The result is only marginally b etter than the version that

do es not include sp ecial treatment of curvature at the key frames. In the next chapter we will

see examples where Spring much more clearly demonstrates its value.

1.2 Angular Velocity Key Frames

1

0.8

0.6

0.4

0.2

0 0 100 200 300 400 500 600

Frame nr.

Figure 6.20: The e ect of Spring. 550 frames have been interpolated and curvature is weighted

with a factor 1.3 76

Chapter 7

Squad and Spring

In chapter 6 we treated a series of interp olation algorithms. The most convincing among the

known algorithms was Squad . In this chapter we will compare Squad with our own algorithm

Spring .

The comparison will b e based on a numb er of illustrative examples.

7.1 Example: A semi circle

First we check if Squad and Spring can pro duce nice rounded curves. We have placed the key

frames as corners in a spherical square. Around the center key frames the interp olation curve

should approximately be a semi circle. Figure 7.1 and 7.2 show that b oth curves meet this

requirement nicely.

1.2 Angular Velocity Key Frames

1

0.8

0.6

0.4

0.2

0 0 100 200 300 400 500 600

Frame nr.

Figure 7.1: A simple curve with soft rounded corners interpolated with Squad. A total of 550

frames have been used in the interpolation. 77 1.2 Angular Velocity Key Frames

1

0.8

0.6

0.4

0.2

0 0 50 100 150 200 250 300 350 400 450

Frame nr.

Figure 7.2: A simple curve with soft rounded corners interpolated with Spring. A total of 430

frames and 700 iterations in the steps have been used. No extra weight on the curvature at the

key frames has been added see section 6.3.7 page 73.

7.2 Example: A nice soft curve

This next example should be no real challenge for either of the algorithms. The exp ected

interp olation curve is simply a nice rounded curve with no sharp corners. The intersection in

the curve should p ose no problem.

1.2 Angular Velocity Key Frames

1

0.8

0.6

0.4

0.2

0 0 100 200 300 400 500 600

Frame nr.

Figure 7.3: Interpolation with Squad of a soft curve with an intersection. A total of 550 frames

have been used in the interpolation.

Both interp olation curves on gure 7.3 and gure 7.4 are nice. However, the curve has more

rounded corners for Spring than for Squad even though no extra weight has b een added to the

curvature at the key frames { see section 6.3.7 page 73. This means that the curve for Spring

has smaller curvature. Furthermore the velo city graph for Spring is more constant than for

Squad . This implies that Spring b ehaves as desired. 78 1.2 Angular Velocity Key Frames

1

0.8

0.6

0.4

0.2

0 0 100 200 300 400 500 600

Frame nr.

Figure 7.4: Interpolation with Spring of a soft curve with an intersection. A total of 550

frames and 700 iterations distributed over the interpolation steps. No extra weight is added to

the curvature around the key frames see section 6.3.7 page 73

7.3 Example: Interp olation curve with cusp

Squad can pro duce interp olation curves with quite p ointy corners at the key frames.

1.2 Angular Velocity Key Frames

1

0.8

0.6

0.4

0.2

0 0 20 40 60 80 100 120 140 160 180 200

Frame nr.

Figure 7.5: A curve with a cusp interpolated with Squad. 200 frames have been used.

The interp olation curve for Squad  gure 7.5 reveals a nasty p ointy curve. However, Spring is

able to pro duce a nice smo oth rounded interp olation curve  gure 7.6.

That the interp olation curve for Squad has a sharp corner do es not contradict the proven fact

that Squad is di erentiable section 6.2.1 page 51. At the key frame with the sharp corner the

velo city of the curve is zero. Thereby the function Squad remains di erentiable although the

geometric app earance of the curve is not intuitively di erentiable. 79 1.2 Angular Velocity Key Frames

1

0.8

0.6

0.4

0.2

0 0 20 40 60 80 100 120 140 160 180 200

Frame nr.

Figure 7.6: A curve with a cusp interpolated with Spring. A total of 200 frames and 700

iterations distributed over three steps. The relative weight of the curvaturearound the key frames

is 1.3 see section 6.3.7 page 73.

7.4 Example: A p endulum

We continue to investigate curves with large curvature. In this example we use a curve with

in nite curvature - a p endulum motion. This is achieved with three key frames where the rst and last are equal.

1.2 Angular Velocity Key Frames

1

0.8

0.6

0.4

0.2

0 0 50 100 150 200 250

Frame nr.

Figure 7.7: Squad displaying pendulum motion over 250 frames.

The desired b ehaviour of the interp olation curve is not intuitively obvious. Since all key frames

are on a arc one would exp ect the curve to remain on this arc.

The gures 7.7 and 7.8 shows the same b ehaviour for b oth curves - the p endulum motion.

Note that Lerp and Slerp would pro duce the same curve. 80 1.2 Angular Velocity Key Frames

1

0.8

0.6

0.4

0.2

0 0 20 40 60 80 100 120 140 160 180 200 220

Frame nr.

Figure 7.8: Spring displaying pendulum motion over 200 frames and 700 iterations in three

steps. The relative weight of the curvature around the key frames is 1.5 see section 6.3.7 page

73.

7.5 Example: A p erturb ed p endulum

Even though it is very reasonable that the interp olation curve remains on the same arc when

the key frames are all on an arc, this is not necessarily correct. In principle the curve has

in nite curvature at the center key frame. Since Spring is supp osed to minimize curvature this

is somewhat disapp ointing.

To understand this, it is necessary to b ear the algorithm in mind. Using gradient descent, each

frame will move slightly in each step to decrease the curvature. But in which direction should

the frames close to the center key frame move? Since the curve is symmetric, the gradient at

each frame will b e zero. The problem is that this do es not imply a lo cal minimum but a lo cal

maximum instead.

Thus, the p endulum is an example of how it is p ossible to confuse Spring . We investigate this

further by p erturbing the rst and last key frames slightly so the curve is no longer a pure

p endulum. It is only just p ossible to see in the curve for Squad  gure 7.9.

Figure 7.10 shows how the pure arc is no longer a rep elling x p oint for the gradient descent

algorithm Spring . The minimal p erturbation allows the interp olation curve to be nice and

rounded at the center key frame.

7.6 Example: Global prop erties

The nal example demonstrates a fundamental di erence between Squad and Spring . In each

interval the interp olation curve for Squad is de ned exclusively from the two previous and the

two following key frames | i. e. a lo cal de nition. In contrast, the interp olation curve for Spring

is globally de ned. 81 1.2 Angular Velocity Key Frames

1

0.8

0.6

0.4

0.2

0 0 50 100 150 200 250

Frame nr.

Figure 7.9: The perturbed pendulum interpolated by Squad using 250 frames.

1.2 Angular Velocity Key Frames

1

0.8

0.6

0.4

0.2

0 0 20 40 60 80 100 120 140 160 180 200

Frame nr.

Figure 7.10: The perturbedpendulum interpolated by Spring using 200 frames and 700 iterations

in three steps. The relative weight of the curvature around the key frames is 1.5 see section

6.3.7 page 73

Figure 7.11 shows the interp olation curve for Squad on a set of vekey frames. The rst three

key frames lie approximately on an arc and therefore the interp olation curve is an arc in the

rst interval. Likewise the interp olation curve form an arc in the last interval.

In contrast the interp olation curve for Spring  gure 7.12 is nice and smo oth. The global

structure of the algorithm allows the curve to distribute the curvature evenly across all the

intervals. Instead of having excessive curvature at the center key frame, a part of the curvature

is propagated to the outer intervals.

It should b e noted that it is necessary to add a relatively large weight to the curvature around

the key frames in this example. However, we have no doubt that an algorithm with a b etter

00

numerical approximation for the constituent expressions in particular q in equation 6.26 would

i

pro duce the same result | without having to t the parameters of the program to the example. 82 1.2 Angular Velocity Key Frames

1

0.8

0.6

0.4

0.2

0 0 100 200 300 400 500 600

Frame nr.

Figure 7.11: Squad producing pointy curve using 550 frames.

1.2 Angular Velocity Key Frames

1

0.8

0.6

0.4

0.2

0 0 50 100 150 200 250 300 350 400 450

Frame nr.

Figure 7.12: Spring avoiding the pointy curve using 430 frames and 900 iterations. The relative

weight of the curvature around the key frames is 4 see section 6.3.7 page 73. 83

7.7 Conclusion

The fundamental di erences b etween the to metho ds are displayed b elow.

Prop erty for the Characteristics for Squad Characteristics for Spring

Algorithm Simple Complex

Analytical Numerical

Continuous Discrete

Lo cal Global

Interp olation curve Nice at simple curves. Nice at all examples.

Sharp corners at key frames with The parameters of the program

large curvature must b e tted to some examples.

The choice b etween Squad and Spring is not obvious. If a simple algorithm yielding nice results in

most cases is needed, then the simple Squad will suce. If really nice interp olation is mandatory

in all cases the more complex Spring will b e more appropriate. 84

Chapter 8

The Big Picture

In this nal chapter we will rst attempt to discuss our work in relation to the available literature

on quaternions and interp olation of rotations. Using this as a starting p oint we will p oint out

relevant topics for future work.

8.1 Comparison to previous work

This pap er has covered ve main topics:

 Rotation mo dalities Section 3.

 Quaternion mathematics Section 3.3.

 Curves for interp olation of rotations | Heuristic approach Section 6.2.

 Curves for interp olation of rotations | Analytic minimization of the lo cal curvature Sec-

tion 6.3.5.

 Curves for interp olation of rotations { Numerical minimization of the tangential curvature

Section 6.3.7.

For each of the main topics we will summarize our contributions compared to the previous work.

Quaternion mathematics

Quaternion mathematics has b een treated several times in the literature [Hamilton, 1853 ],

[Hamilton, 1899 ], [Pervin & Webb, 1992 ], [Sho emake, 1994b ], [Maillot, 1990 ], and [Kim et al., 1996 ].

[Pervin & Webb, 1992 ] should b e noted for a treatment of the basic mathematical prop erties |

including the logarithm and exp onential functions. In [Kim et al., 1996 ], a general framework

for di erentiation is given though the reader is referred to a di erential geometry text for the

pro of , and the derivative of exp is derived based on this framework. None of the articles have 85

given a complete treatment of the necessary mathematics. Di erentiation of the quaternion

functions is very central in the study of the smo othness of the interp olation curves.

This rep ort includes a comprehensive treatment of quaternion math. In particular, we have

derived all the di erentiation equations necessary for proving the desired prop erties of the in-

terp olation curves in section 3.3.8.

Curves for interp olation of rotations | Heuristic approach

Interp olation curves in the plane have inspired several interp olation curves for rotations. The two

most imp ortant are Slerp [Sho emake, 1985 ] and Squad [Sho emake, 1987 ]. Sho emake attempts

1

to prove the di erentiability of Squad but the pro of is awed . In [Kim et al., 1996 ], a more

general result is given that entails the di erentiabilityof Squad . Our result is derived using less

advanced mathematics, and may b e more easily accessible.

This is the rst rep ort which contains a comprehensive treatment of the two most imp ortant

heuristic quaternion curves section 6.2. All the known expressions for Slerp are stated and

the correctness of their prop erties is proven. For Squad we apply the derived di erentiation

equations to prove the di erentiability of the function.

Other heuristic approaches

Like Squad , a number of quaternion interp olation curves have b een made from general spher-

ical cubic curves. These curves are tted to the control p oints, thus yielding relatively nice

interp olation curves. Most often these curves are inspired by cubic curves in the plane.

Examples of this are the fairly simple spherical Catmull-Rom B-spline in [Schlag, 1994 ] and a

spherical B ezier curve in [Sho emake, 1985 ].

In this rep ort, wehave not investigated this approach.

Curves for interp olation of rotations | Analytic approach

The rst attempt to derive an optimal interp olation curve from a set of ob jective criteria can b e

seen in [Barr et al., 1992 ]. The pap er states an expression minimizing the tangential curvature

in this pap er also called the local curvature . However, the pap er makes no attempt to state or

solve the di erential equation, that corresp onds to the optimal curve.

In this pap er we state a set of ob jective criteria for the optimal interp olation curve section

6.3.5 | inspired by [Barr et al., 1992 ]. We then derive the fourth order di erential equation

whose solution will minimize the lo cal curvature. Unfortunately, we are not able to solve the

di erential equation analytically.

1

As mentioned earlier [Sho emake, 1987 ] is unavailable but Sho emake himself has stated [Sho emake, 1997 ] that

the pro of was awed. 86

Minimization of the lo cal curvature | Numerical approach

A brief description of a numerical solution to the problem of minimizing the tangential curvature

is sketched in [Barr et al., 1992 ]. [Platt & Barr, 1988 ] contains a more sophisticated metho d

using Augmented Lagrangian constraints in a Finite elements metho d. A metho d yeilding

faster convergence is presented in [Ramamo orthi & Barr, 1997 ].

We give a complete algorithm for nding a discrete solution to the numerical version of the

minimization problem section 6.3.7.

Complete treatment

To our knowledge, there exists no other complete treatment of quaternion mathematics and the

applications in interp olation of rotations.

This rep ort combines a comprehensiveoverview including b oth a thorough treatment of the basic

quaternion mathematics and as well, the most imp ortant metho ds for interp olating orientations

is space. This is where quaternions really show their strength see sections 3.3.6, 3.4, and chapter

6.

8.2 Future work

Obviously,itwould b e very nice to derive an analytic solution of the di erential equation that

minimizes the lo cal curvature of the interp olation curve. Since di erential equations are centuries

old this is not very likely to happ en in the immediate future. Therefore it would b e more realistic

to establish a more robust numerical solution with a faster convergence. This is b eyond the scop e

of this rep ort. An excellent starting p oint for this approachwould b e [Platt & Barr, 1988 ] and

[Ramamo orthi & Barr, 1997 ].

Another direction could be the development of more sp ecialized applications. As an example,

the movements of a camera should not necessarily be interp olated in the same manner as the

moving ob ject during animation. A stable horizon is p ossibly a desired feature for the camera

i. e. the camera must not tilt upside down. Relevant intro ductions to this line of work are

[Sho emake, 1994b ] and [Sho emake, 1994a ].

Another example of sp ecialization is applications where the interp olation need not b e smo oth.

For instance, in the plane the interp olation of a y or a UFO need not be smo oth either. An

example of extraction of certain prop erties of interp olation curves in 3D tension, continuity

and bias control  can b e found in [Ko chanek & Bartels, 1984 ].

Finally, yet another example of sp ecialization of the interp olation curve can be studied in

[Barr et al., 1992 ]. In this metho d, the angular velo city can b e given explicitly at the rst and

last key frame the authors call this Angular Velocity Constraints . An obvious generalization

of this would b e the ability to supply the angular velo city at an arbitrary key frame. 87

Acknowledgements

Wewould like to thank Ken Sho emake, who patiently and enthusiastically help ed with answers

2

to questions p osed via e-mail. We also owe thanks to Jrgen Sand , who o ered comprehensive

3

suggestions concerning di erential equations and the calculus of variations, and Gerd Grubb ,

who help ed with di erential equations.

For thorough pro of reading of the Danish version wewould like to thank Tommy Hjfeld Olesen.

We would like to thank Theo Engell for the illustration in the intro duction. Finally we would

like to thank our advisor Knud Henriksen.

2

Asso ciate Professor at the Institute of Computer Science, the University of Cop enhagen, sp ecializing in the

solution of systems of equations.

3

Professor at the Institute of Mathematics, the University of Cop enhagen, sp ecializing in di erential equations. 88

App endix A

Conventions

In this rep ort wehave used following conventions:

Co ordinate system

We use a right-handed co ordinate system. In computer graphics it is common to use

a left-handed co ordinate system. This allows the z -axis to p oint \into" the screen which

seems natural. Since we primarily use co ordinates for mathematical derivations we have

chosen to use the mathematical standard | the right-handed co ordinate system.

Rotation

Still using the mathematical standard we rotate counter-clo ckwise. The direction of ro-

tation ab out an axis is obtained by the right-hand rule: Hold the axis with right hand

and the thumb p ointing in the p ositive direction of the axis. A p ositive rotation will now

rotate in the direction of the ngers apart from the thumb.

This is illustrated b elow:

y

Rotation about z brings x into y

otation about y brings z into x

x R

Rotation about x brings y into z

z

Euler angles

Rotation by Euler angles is de ned by a rotation ab out each of the three co ordinate axes.

To make this unambiguous it is necessary to de ne the order of rotation.

The sp eci c order of rotation is of no imp ortance in this pap er and we arbitrarily cho ose

x, y , z . Other conventions are describ ed in [Craig, 1986 ]. 89

App endix B

Conversions

In this app endix we show the conversions b etween di erent representations for rotation: Euler

angles, matrices, and quaternions.

B.1 Euler angles to matrix

Rotation ab out the x-axis by the angle followed by rotation ab out the y -axis by the angle

1

concluded by rotation ab out the z -axis by the angle is written in matrix notation:

R  ; ;  = R  R  R  

z y x

2 3 2 3 2 3

cos sin 0 0 cos 0 sin 0 1 0 0 0

6 7 6 7 6 7

sin cos 0 0 0 1 0 0 0 cos sin 0

6 7 6 7 6 7

=

4 5 4 5 4 5

0 0 1 0 sin 0 cos 0 0 sin cos 0

0 0 0 1 0 0 0 1 0 0 0 1

2 3

cos cos cos sin sin cos sin cos cos sin + sin sin 0

6 7

cos sin cos cos + sin sin sin cos sin  + cos sin sin 0

6 7

=

4 5

sin cos sin cos cos 0

0 0 0 1

B.2 Matrix to Euler angles

The rotation matrix derived ab ove is the starting p oint for the conversion from matrix to Euler

angles. The conversion to Euler angles requires the inverse trigonometric functions. Neither

arcsin nor arccos will, by itself, yield values on the entire interval from  to  . We therefore

want to establish b oth the sin and cos values for all the angles. Using b oth the sin and cos

values the original angles can b e determined in the interval ] ; ]as v = sgnsin v  arccos v ,

x

. where sgn is de ned: sgn0 = 0 and sgnx=

jxj

1

Using homogeneous matrices the rotation matrices are 4  4. 90

We can directly determine sin as R . Isolating cos yields the following equations:

31

2

cos = R R R R R =R

11 32 31 33 21 12

2

cos = R R R + R R =R

11 33 31 32 21 13

2

cos = R R R + R R =R

32 31 21 11 33 22

2

cos = R R R R R =R

31 33 21 11 32 23

From this it is not p ossible to determine the sign of cos . This means that we might as well

determine directly from sin . Either way it is only p ossible to determine in the interval

 

[ ; ] corresp onding to the assumption that cos is p ositive.

2 2

Determining cos and sin for and requires cos . If the assumption that cos is p ositivedoes

not hold, then also and are determined incorrectly. Unfortunately this is the b est that can

b e done.

The equations for cos and sin for each of the constituent angles are shown b elow. From this the

angles can b e determined as stated ab ove.

h i

 

= arcsinR  Assuming 2 ; 

31

2 2

R

33

cos =

cos

R

32

sin =

cos

R

11

cos =

cos

R

21

sin =

cos



Obviously this requires that cos 6=0. If cos =0 then =  . This corresp onds to gimbal

2

lo ck see section 4.1 and therefore it is imp ossible to distinguish from . Thus we arbitrarily

de ne 0. In this situation the angles can b e determined:

h i

 

= arcsinR  assuming 2 ; 

31

2 2

cos = R

22

sin = R

23

= 0

B.3 Quaternion to matrix

1

Rotation of the vector p =x; y ; z  with the quaternion q is done by the op eration q [0;p] q .

T

We want to determine the corresp onding matrix which multiplied on [x y z 1] from the left

will yield the same result. 91

The pro duct of two quaternions q =[w; a; b; c] and q =[s; x; y ; z ] written in i; j; k-notation

v

h

is:

q q = w + ia + jb + kcs + ix + jy + kz 

v h

= ws ax by cz +ias + wx cy + bz +

jbs + wy + cx az +kcs + wz bx + ay 

2

Written as columns using sloppy notation this equals:

3 3 2 2 3 2

wx cy + bz + as x a

7 7 6 6 7 6

cx + wy az + bs y b

7 7 6 6 7 6

=  q q =

q v

h

5 5 4 4 5 4

bx + ay + wz + cs z c

ax by cz + ws s w

From this we can write the matrices corresp onding to multiplying from the left and from the

right with a quaternion. First we determine V such that V q = q q , where q and q q are

q q v v v

h h h

v v

written as columns:

2 3

w c b a

6 7

c w a b

6 7

V =

q

v

4 5

b a w c

a b c w

Then we write H , such that H q = q q :

q q v v

h

h h

2 3

s z y x

6 7

z s x y

6 7

H =

q

h

4 5

y x s z

x y z s

1

We are now ready to write the matrix M , such that Mp = q [0;p] q . Using q =[s; x; y ; z ]

1

and q =[s; x; y; z ] we get:

M = V H

1

q

q

2 3 2 3

s z y x s z y x

6 7 6 7

z s x y z s x y

6 7 6 7

=

4 5 4 5

y x s z y x s z

x y z s x y z s

2 3

2 2

1 2y + z  2xy 2sz 2sy +2xz 0

2 2

6 7

2xy +2sz 1 2x + z  2sx +2yz 0

6 7

=

2 2

4 5

2sy +2xz 2sx +2yz 1 2x + y  0

0 0 0 1

2 T

The quaternion [s; x; y ; z ] is written as the column [x; y; z; s] , and  denotes quaternion multiplication

q 92

B.4 Matrix to Quaternion

Conversion from a rotation matrix to the corresp onding unit quaternion uses the matrix M

derived ab ove. First we nd s:

2 2 2

M + M + M + M = 4 4x + y + z 

11 22 33 44

2 2 2 2 2

= 4 41 s  Da s + x + y + z =1

2

= 4s

2

This yields s . Now the other values follow:

p

1

M + M + M + M s = 

11 22 33 44

2

M M

32 23

x =

4s

M M

13 31

y =

4s

M M

21 12

z =

4s

The sign of s cannot be determined. Dep ending on the choice of sign for s the signs for x,

y and z change as well. This means cho osing between a quaternion and the corresp onding

negative quaternion. These quaternions yield the same rotation but the interp olation curve can

b e in uenced by this choice.

Since the entire interp olation is calculated on quaternions this will p ose no practical problem.

Therefore we simply cho ose the p ositive square ro ot.

B.5 Between quaternions and Euler angles

These conversions can simply be achieved by going via matrices using the conversions stated

ab ove.

Therefore the limitation on the angle from the conversion between matrix and Euler angles

will hold for the conversion from quaternions to Euler angles as well. It is not p ossible to avoid

this limitation or a similar one using a direct conversion b etween quaternions and Euler angles. 93

App endix C

Implementation

This chapter contains a brief description of the program we have develop ed for visualization

including the standard packages wehave used.

quat displays in a window on the screen how an ob ject the letter \R" lo oks when it is rotated

in space. The desired key orientations are supplied through a resource le together with various

parameters. The interp olation metho d is supplied as a command line parameter. The available

metho ds are:

lineuler Linear interp olation b etween Euler angles section 6.1.1.

linmat Linear interp olation b etween rotation matrices section 6.1.2.

lerp Linear interp olation b etween quaternions section 6.1.3

slerp Spherical linear interp olation b etween quaternions section 6.1.5.

squad Spherical spline interp olation b etween quaternions section 6.2.1

slerpsvupti Minimization of the tangential curvature using a gradient descent

metho d with Slerp as initial solution section 6.3.7.

squadsvupti Minimization of the tangential curvature using a gradient descent

metho d with Squad as initial solution section 6.3.7.

justdoit Minimization of the tangential curvature using a gradient descent

metho d applied three times with Slerp as initial solution section 6.3.7.

The curious names slerpsvupti, squadsvupti and justdoit are used for historical reasons.

We use the graphics library SPHIGS [Sklar & Brown, 1993 ] for displaying the animation on the

screen. However, wehave added the ability to exp ort the animation as a series of PPM les. The

PPM les are converted to an animated GIF using the program convert [ImageMagic, 1997 ].

A few examples of this can b e seen at http://kantine.diku.dk/~myth/gif

The program quat pro duces a visualization of the interp olated quaternions and an approxi-

mation of the velo city see chapter 5. The velo city is displayed as a two dimensional graph

generated by the program gnuplot [Williams & Kelley, 1993 ]. The visualization of the interp o-

lation curve is made using the ray tracer POV-ray [POV, 1997 ]. 94

C.1 The basic structure of quat

We have used C++ for writing quat. The ob ject oriented language allows us to implement

classes for each mathematical concept: matrix, vector, quaternion and so on. Apart from this

separate ob jects handle interp olation and visualization.

The source co de can b e obtained from the authors. 95

Bibliography

[Barr et al., 1992] Alan H. Barr, Bena Currin, Steven Gabriel, & John F. Hughes. Smo oth inter-

p olation of orientations with angular velo city constraints using quaternions. Computer

Graphics, 262:313{320, July 1992.

[Burtnyk&Wein, 1971] Nester Burtnyk & Marceli Wein. Computer generated keyframe ani-

mation. SMPTE, 80:149{153, March 1971.

[Craig, 1986] John J. Craig. Introduction to Robotics. Mechanics and Control, chapter 2.

Addison-Wesley, 1986.

[Euler, 1752] Leonhard Euler. Decouverte d'un nouveau princip e de m echanique. Opera omnia

1957, Ser. secundaVol. 5:81{108, 1752. Orell Fusli  Turici.

[Foley et al., 1990] James D. Foley, Andries van Dam, Steven K. Feiner, & John F. Hughes.

Computer Graphics Principles and Practice. Addison-Wesley, Reading, Massachusetts,

2nd. edition, 1990.

[Hallenb erg et al., 1993] Niels Hallenb erg, Martin Ko ch, & Ole Fogh Olsen. Vektorernes opstaen

og udvikling The construction and development of vector calculus . 1993.

[Hamilton, 1853] Sir W. R. Hamilton. Lectures on Quaternions. Ho dges Smith & Co., Dublin,

1853.

[Hamilton, 1899] Sir W. R. Hamilton. Elements of Quaternions,volume 1-2. Longmans, Green

and Co., 1899.

[ImageMagic, 1997] ImageMagic. Convert. E. I. du Pont de Nemours and Company, 1997. Part

of the ImageMagic version 3.9.0 library. http://www.wizards.dupont.com/cristy-

/ImageMagick.html.

[Jakobsen, 1993] Hans Plesner Jakobsen. Course notes for Mathematics 3GE di erential ge-

ometry. Matematisk Notetryk, Institute of Mathematics, University of Cop enhagen,

Denmark, Cop enhagen, 1993.

[Kim et al., 1996] Myoung-Jun Kim, Myung-So o Kim, & Sung Yong Shin. A compact dif-

ferential formula for the rst derivative of a unit quaternion curve. The Journal of

Visualization and Computer Animation, 7:43{57, 1996.

[Kincaid & Cheney, 1991] David Kincaid & Ward Cheney. Numerical Analysis. Bro oks/Cole

Publishing Company,Paci c Grove, California, 1991. 96

[Ko chanek & Bartels, 1984] Doris H. U. Ko chanek & Richard H. Bartels. Interp olating splines

with lo cal tension, continuity, and bias control. Computer Graphics, 18:33{41, July 1984.

[Lasseter, 1987] John Lasseter. Principles of traditional animation applied to 3D computer

animation. Computer Graphics, 214:35{44, July 1987.

[Madsen, 1991] Tage Gutmann Madsen. Course notes for Mathematics 1MA calculus. Matem-

atisk Notetryk, Institute of Mathematics, University of Cop enhagen, Denmark, Cop en-

hagen, 1991.

[Maillot, 1990] Patrick-Gilles Maillot. Using quaternions for co ding 3d transformations. In

Andrew Glassner, editor, Graphics Gems 1,chapter 10, pages 498{515. Academic Press,

Inc., 1990.

[McCo ol, 1995] Michael McCo ol. Orientation interaction tester.

http://www.cgl.uwaterloo.ca/Gallery/image html/gimbal.jpg.html, June 1995.

[Pervin & Webb, 1992] Edward Pervin & Jon A. Webb. Quaternions in Computer Vision and

Robotics. Carnegie-Mellon University, 1992.

[Platt & Barr, 1988] John C. Platt & Alan H. Barr. Constraint metho ds for exible mo dels.

Computer Graphics, 224:279{288, August 1988.

[POV, 1997] POV-team. Persistence of Vision Ray Tracer, Febuary 1997.

http://www.povray.org.

[Ramamo orthi & Barr, 1997] Ravi Ramamo orthi & Alan H. Barr. Fast construction of accurate

quaternion splines. Computer Graphics, pages 287{292, 1997.

[Schlag, 1994] John Schlag. Using geometric constructions to interp olate orientation with

quaternions. Graphics Gems IV, pages 230{236, 1994.

[Schwarz, 1989] H. R. Schwarz. Numerical Analysis, A Comprehensive Introduction. John Wiley

& Sons, Chicester, 1989.

[Sho emake & Du , 1994] Ken Sho emake&Tom Du . Matrix animation and p olar decomp osi-

tion. ftp://ftp.cis.upenn.edu/pub/graphics/shoemake/polar-decomp.ps.Z, 1994.

[Sho emake, 1985] Ken Sho emake. Animating rotation with quaternion curves. Computer Graph-

ics, 193:245{254, 1985.

[Sho emake, 1987] Ken Sho emake. Quaternion calculus and fast animation. SIGGRAPH Course

Notes, 10:101{121, 1987. Not available.

[Sho emake, 1994a] Ken Sho emake. Fib er bundle twist reduction. Graphics Gems IV, pages

230{236, 1994.

[Sho emake, 1994b] Ken Sho emake. Quaternions. ftp://ftp.cis.upenn.edu/pub/graphics/-

shoemake/quatut.ps.Z, 1994.

[Sho emake, 1997] Ken Sho emake. Re: Siggraph 1987 tutorial, June 1997. E-mail corre-

sp ondence June/July 1997. 97

[Sklar & Brown, 1993] David Frederick Sklar & Christopher R. Brown. Simple Programmer's

Hierarchical Graphics Standard SPHIGS for ANSI-C Version 1.0, March 1993. A

detailed description can b e found in [Foley et al., 1990 ].

[Verplaetse, 1995] Christopher Verplaetse. Can a pen remember what it has written

using inertial navigation?: An evaluation of current accelerometer technology.

http://verp.www.media.mit.edu/projects/SmartPen/smartpen.html,May 1995.

[Watt & Watt, 1992] Alan Watt & Mark Watt. AdvancedAnimation and Rendering Techniques

Theory and Practice,chapter 15. Addsion-Wesley,Wokingham, England, 1992.

[Williams & Kelley, 1993] Thomas Williams & Colin Kelley. GNUPLOT

| An Interactive Plotting Program Version 3.4, June 1993.

http://science.nas.nasa.gov/~woo/gnuplot/gnuplot.html. 98