Download as pdf or txt
Download as pdf or txt
You are on page 1of 25

The Use of Quaternions and SLERP for Character Animation

Verena Kremer
Saarland University
vekr5001@stud.cs.uni-sb.de

8. Mai 2008

Verena Elisabeth Kremer () Quaternions and SLERP 8. Mai 2008 1 / 20


The Need for Rotations in Character Animation

Character Animation

character motion consists of vector movements in 3D


vector motion = rotation + translation
translations are mathematical trivial; rotations are quite interesting

⇒ we will discuss the computing of rotations today

Verena Elisabeth Kremer () Quaternions and SLERP 8. Mai 2008 2 / 20


The Need for Rotations in Character Animation

Structure

1 The Need for Rotations in Character Animation

2 Traditional Approaches

3 Quaternions

4 Interpolation

5 Conclusion

Verena Elisabeth Kremer () Quaternions and SLERP 8. Mai 2008 3 / 20


Traditional Approaches

Rotation Matrices in 3D

0 1 0 1
1 0 0 cos φ 0 sin φ
Rotx (φ) = @0 cos φ − sin φA Roty (φ) = @ 0 1 0 A
0 sin φ cos φ − sin φ 0 cos φ
0 1
cos φ − sin φ 0
Rotz (φ) = @ sin φ cos φ 0A
0 0 1

⇒ to achieve a 90◦ - rotation of a vector ~v ∈ R3 around the x-axis,


we compute

Rotx (φ)~v with φ = 90◦

size, shape, and handedness are preserved


rotation, or change matrices, may also perform translations
change matrices form a group under matrix multiplication
used to compute start- and ending points of a rotation

Verena Elisabeth Kremer () Quaternions and SLERP 8. Mai 2008 4 / 20


Traditional Approaches

Rotation Matrices in 3D

0 1 0 1
1 0 0 cos φ 0 sin φ
Rotx (φ) = @0 cos φ − sin φA Roty (φ) = @ 0 1 0 A
0 sin φ cos φ − sin φ 0 cos φ
0 1
cos φ − sin φ 0
Rotz (φ) = @ sin φ cos φ 0A
0 0 1

⇒ to achieve a 90◦ - rotation of a vector ~v ∈ R3 around the x-axis,


we compute

Rotx (φ)~v with φ = 90◦

size, shape, and handedness are preserved


rotation, or change matrices, may also perform translations
change matrices form a group under matrix multiplication
used to compute start- and ending points of a rotation

Verena Elisabeth Kremer () Quaternions and SLERP 8. Mai 2008 4 / 20


Traditional Approaches

Euler Angles and Gimbal Lock

Euler Angles describe objects in space through their spatial orientation


e.g. the angles between an object and fixed axes in space
changing one of the angles rotates space and objects
rotations are not commutative
operations and definitions follow conventions
several rotations together may cause gimbal lock:

introducing quaternions...

Verena Elisabeth Kremer () Quaternions and SLERP 8. Mai 2008 5 / 20


Traditional Approaches

Euler Angles and Gimbal Lock

Euler Angles describe objects in space through their spatial orientation


e.g. the angles between an object and fixed axes in space
changing one of the angles rotates space and objects
rotations are not commutative
operations and definitions follow conventions
several rotations together may cause gimbal lock:

introducing quaternions...

Verena Elisabeth Kremer () Quaternions and SLERP 8. Mai 2008 5 / 20


Traditional Approaches

Euler Angles and Gimbal Lock

Euler Angles describe objects in space through their spatial orientation


e.g. the angles between an object and fixed axes in space
changing one of the angles rotates space and objects
rotations are not commutative
operations and definitions follow conventions
several rotations together may cause gimbal lock:

introducing quaternions...

Verena Elisabeth Kremer () Quaternions and SLERP 8. Mai 2008 5 / 20


Traditional Approaches

Euler Angles and Gimbal Lock

Euler Angles describe objects in space through their spatial orientation


e.g. the angles between an object and fixed axes in space
changing one of the angles rotates space and objects
rotations are not commutative
operations and definitions follow conventions
several rotations together may cause gimbal lock:

introducing quaternions...

Verena Elisabeth Kremer () Quaternions and SLERP 8. Mai 2008 5 / 20


Traditional Approaches

Euler Angles and Gimbal Lock

Euler Angles describe objects in space through their spatial orientation


e.g. the angles between an object and fixed axes in space
changing one of the angles rotates space and objects
rotations are not commutative
operations and definitions follow conventions
several rotations together may cause gimbal lock:

introducing quaternions...

Verena Elisabeth Kremer () Quaternions and SLERP 8. Mai 2008 5 / 20


Quaternions

Inventing Hypercomplex Numbers

quaternions were invented by William Rowan


Hamilton in 1843
irish mathematician, philosopher and
astronomer
first to describe complex numbers as vectors
searched for nearly 15 years on possible
extensions of C
quaternions form a finite-dimensional normed
division algebras over R
⇒ H is a group under multiplication
quaternion multiplication can be substituted
for rotation matrix multiplication
designed them to be beautiful as well as useful

i 2 = j2 = k 2 = ijk = −1
⇒ H = {t + xi + yj + zk|t, x, y, z ∈ R}

Verena Elisabeth Kremer () Quaternions and SLERP 8. Mai 2008 6 / 20


Quaternions

The Hamilton Algebra H

notation: 0 1
x
~q := (i, j, k) @yA ⇒ q = t + ~q; while q ∈ H
z

Graham Product (Quaternion Multiplication):


ˆ ˜ ˆ ˜
q~1 q~2 = − 1(q~1 • q~2 ) + q~1 × q~2
ˆ ˜ ˆ ˜
q1 q2 = t1 t2 (−1q~1 • q~2 ) + t1 q~2 + t2 q~1 + (q~1 × q~2 )

while inner and outer product are defined as in R

ij = k jk = i ki = j
ik = −j ji = −k kj = −i

identity, inverse element, and √


norm:
e = 1 ∈ H q̄ = t − ~q |q| = qq̄

[VK05, Rei01, Lan98, Wik08a, Joh03]

Verena Elisabeth Kremer () Quaternions and SLERP 8. Mai 2008 7 / 20


Quaternions

Rotation Matrices to Quaternions Part I

0 1 0 1
m11 m12 m13 ix
M = @m21 m22 m23 A , M ∈ R3×3 q = t + ~q, q ∈ H ~q = @ jy A
m31 m32 m33 kt

0 < 41 (1 + m11 + m22 + m33 )

1p
⇒t = (1 + m11 + m22 + m33 )
2
1
x = (m23 − m32 )
4t
1
y = (m13 − m13 )
4t
1
z = (m12 − m21 )
4t
···

Verena Elisabeth Kremer () Quaternions and SLERP 8. Mai 2008 8 / 20


Quaternions

Rotation Matrices to Quaternions Part II

0 1 0 1
m11 m12 m13 ix
M = @m21 m22 m23 A , M ∈ R3×3 q = t + ~q, q ∈ H ~q = @ jy A
m31 m32 m33 kt

1
0≥ 4
(1 + m11 + m22 + m33 ) and
0 < − 21 (m22 + m33 )

⇒ t = 0
r
1
x = − (m22 + m33 )
2
1
y = (m12 )
2x
1
z = (m13 )
2x
···

Verena Elisabeth Kremer () Quaternions and SLERP 8. Mai 2008 9 / 20


Quaternions

Rotation Matrices to Quaternions Part III

0 1 0 1
m11 m12 m13 ix
M = @m21 m22 m23 A , M ∈ R3×3 q = t + ~q, q ∈ H ~q = @ jy A
m31 m32 m33 kt

1
0≥ 4
(1 + m11 + m22 + m33 ) and
0≥ − 21 (m22 + m33 ) and
0 < 21 (1 − m33 )

⇒ t, x = 0
r
1
y = (1 − m33 )
2
1
z = m23
2y
···

Verena Elisabeth Kremer () Quaternions and SLERP 8. Mai 2008 10 / 20


Quaternions

Rotation Matrices to Quaternions Part IV

0 1 0 1
m11 m12 m13 ix
M = @m21 m22 m23 A , M ∈ R3×3 q = t + ~q, q ∈ H ~q = @ jy A
m31 m32 m33 kt

1
0≥ 4
(1 + m11 + m22 + m33 ) and
0 ≥ − 21 (m22 + m33 ) and
0 ≥ 21 (1 − m33 )

⇒ t = x = y = 0, z = 1

Verena Elisabeth Kremer () Quaternions and SLERP 8. Mai 2008 11 / 20


Quaternions

Quaternions to Rotation Matrices

0 1
ix
q = t + ~q, q ∈ H with ~q = @ jy A , t 2 + x 2 + y2 + z 2 = 1
kt
0 1
m11 m12 m13
and M = @m21 m22 m23 A , M ∈ R3×3
m31 m32 m33

1 − 2y2 − 2x 2
0 1
2xy + 2tz 2xz − 2ty
⇒M = @ 2xy − 2tz 1 − 2x 2 − 2z 2 2yz + 2tx A
2xz + 2ty 2yz − 2tx 1 − 2x 2 − 2y2

[Sho85]

Verena Elisabeth Kremer () Quaternions and SLERP 8. Mai 2008 12 / 20


Interpolation

Linear Interpolations

until now, we can compute starting and ending points of motions


to achieve smooth movements, interpolations are necessary
interpolations cannot be computed by using rotation matrices
can not be computed using quaternion multiplication

linear interpolation (short LERP) simply computes


~ + ~b)
~c = 12 (a
length not preserved
normalizing ~c yields normalized LERP (short NLERP)
⇒ length preserved

[Sho85, Blo04]

Verena Elisabeth Kremer () Quaternions and SLERP 8. Mai 2008 13 / 20


Interpolation

SLERP

(N)LERP is fast and easy to understand


and implement, but it has a drawback:
it yields results with varying velocity

a solution is SLERP; spherical LERP:


sin (1−t)θ sin (t)θ
Slerp(q1 , q2 , t) := sin θ
q1 + sin θ
q2
with cos θ = q1 q2

[Sho85, Blo04]

Verena Elisabeth Kremer () Quaternions and SLERP 8. Mai 2008 14 / 20


Interpolation

SLERP and Beziér Curves

now we are able to interpolate between to quaternions


to interpolate between more than 2 points, Beziér curves
are needed
Beziér curves are defined through several (at least 2)
parameters

to use SLERP on Beziér curves we construct two additional points an , and


bn+1 between each quaternion pair qn , qn+1 and define a curve through
them with starting point qn and ending point qn+1

[Mor01, Wik08b, Sho85]

Verena Elisabeth Kremer () Quaternions and SLERP 8. Mai 2008 15 / 20


Interpolation

Computing SLERP on Beziér Curves

to interpolate points on a Beziér curve through qn , an , bn+1 , and qn+1 ,


we compute:

p0,0 = qn , p1,0 = an , p2,0 = bn+1 , and p3,0 = qn+1


p0,1 = Slerp(p0,0 , p1,0 , t), p1,1 = Slerp(p1,0 , p2,0 , t),
and p2,1 = Slerp(p2,0 , p3,0 , t)
p0,2 = Slerp(p0,1 , p1,1 , t),
and p1,2 = Slerp(p1,1 , p2,1 , t)
p0,3 = Slerp(p0,2 , p1,2 , t)
p0,3 =: qn+t

[Mor01, Wik08b, Sho85]

Verena Elisabeth Kremer () Quaternions and SLERP 8. Mai 2008 16 / 20


Interpolation

How to use SLERP in H

1 conversion from matrix to quaternions;


obtaining a set of quaternions on unit sphere
M → {q1 , q2 , ...qn , qn+1 }
2 construction of Beziér curves – with additional control points –
between each quaternion pair
Bez(qn , an , bn+1 , qn+1 )
3 animation through frames along the curves, using time as a parameter
computing qn+t
4 interpolation of single quaternions along curves using SLERP and back
conversion
qn+t → Mt

[Mor01, Sho85]

Verena Elisabeth Kremer () Quaternions and SLERP 8. Mai 2008 17 / 20


Conclusion

Conclusion

SLERP (on Beziér curves)

yields the best results (pro)


is non commutative, slow, and difficult (contra)

NLERP (on Beziér curves)

is commutative and faster (pro)


yields results with varying velocity (contra)

Euler Angles

are easier to understand and fast (pro)


are non-commutative, yield results with varying velocity, and may result
in gimbal lock (contra)

Verena Elisabeth Kremer () Quaternions and SLERP 8. Mai 2008 18 / 20


Conclusion

The End

“Time is said to have only one dimension,


and space to have three dimensions. ...
The mathematical quaternion partakes of both these elements;
in technical language it may be said to be
’time plus space’, or ’space plus time’:
and in this sense it has,
or at least involves
a reference to four dimensions.

And how the One of Time,


of Space the Three,
Might in the Chain
of Symbols girdled be."

– William Rowan Hamilton

Verena Elisabeth Kremer () Quaternions and SLERP 8. Mai 2008 19 / 20


Conclusion

Bibliography

[Blo04] Jonathan Blow. Understanding slerp, then not using it. The Inner Produc,
2004.
[Joh03] M. P. Johnson. Exploiting Quaternions to Support Expressive Interactive
Character Motion. PhD thesis, MIT Media Lab, 2003.
[Lan98] Jeff Lander. Better 3d: The writing is on the wall. Game Developer, 1998.
[Mor01] Mortenson. Mathematics for Computer Graphics Applications. dtv, 2001.
[Rei01] Falk Reinhardt, Soeder. Atlas der Mathematik. dtv, 2001. Band 1.
[Sho85] Ken Shoemaker. Animating rotation with quaternion curves. The Singer
Company; Link Flight Simulation Division, 1985.
[VK05] M. Fleck V. Kremer. Hypercomplex Fouriertransformations, 2005. Seminar
Geometric Algebra in Computer Vision.
[Wik08a] Wikipedia. Quaternions, 2008.
[Wik08b] Wikipedia. Slerp, 2008.

Hyperlinks were valid on May 04, 2008.


Questions and remarks are much appreciated, please contact me via email:
vekr5001@stud.cs.uni-sb.de

Verena Elisabeth Kremer () Quaternions and SLERP 8. Mai 2008 20 / 20

You might also like