25
The Use of Quaternions and SLERP for Character Animation Verena Kremer Saarland University [email protected] 8. Mai 2008 Verena Elisabeth Kremer () Quaternions and SLERP 8. Mai 2008 1 / 20

The Use of Quaternions and SLERP for Character Animationembots.dfki.de/doc/seminar_ca/ik1.pdf · The Use of Quaternions and SLERP for Character Animation ... a solution is SLERP;

Embed Size (px)

Citation preview

Page 1: The Use of Quaternions and SLERP for Character Animationembots.dfki.de/doc/seminar_ca/ik1.pdf · The Use of Quaternions and SLERP for Character Animation ... a solution is SLERP;

The Use of Quaternions and SLERP for Character Animation

Verena KremerSaarland University

[email protected]

8. Mai 2008

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

Page 2: The Use of Quaternions and SLERP for Character Animationembots.dfki.de/doc/seminar_ca/ik1.pdf · The Use of Quaternions and SLERP for Character Animation ... a solution is SLERP;

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

Page 3: The Use of Quaternions and SLERP for Character Animationembots.dfki.de/doc/seminar_ca/ik1.pdf · The Use of Quaternions and SLERP for Character Animation ... a solution is SLERP;

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

Page 4: The Use of Quaternions and SLERP for Character Animationembots.dfki.de/doc/seminar_ca/ik1.pdf · The Use of Quaternions and SLERP for Character Animation ... a solution is SLERP;

Traditional Approaches

Rotation Matrices in 3D

Rotx(φ) =

0@1 0 00 cosφ − sinφ0 sinφ cosφ

1A Roty(φ) =

0@ cosφ 0 sinφ0 1 0

− sinφ 0 cosφ

1A

Rotz(φ) =

0@cosφ − sinφ 0sinφ cosφ 0

0 0 1

1A⇒ 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

Page 5: The Use of Quaternions and SLERP for Character Animationembots.dfki.de/doc/seminar_ca/ik1.pdf · The Use of Quaternions and SLERP for Character Animation ... a solution is SLERP;

Traditional Approaches

Rotation Matrices in 3D

Rotx(φ) =

0@1 0 00 cosφ − sinφ0 sinφ cosφ

1A Roty(φ) =

0@ cosφ 0 sinφ0 1 0

− sinφ 0 cosφ

1A

Rotz(φ) =

0@cosφ − sinφ 0sinφ cosφ 0

0 0 1

1A⇒ 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

Page 6: The Use of Quaternions and SLERP for Character Animationembots.dfki.de/doc/seminar_ca/ik1.pdf · The Use of Quaternions and SLERP for Character Animation ... a solution is SLERP;

Traditional Approaches

Euler Angles and Gimbal Lock

Euler Angles describe objects in space through their spatial orientatione.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

Page 7: The Use of Quaternions and SLERP for Character Animationembots.dfki.de/doc/seminar_ca/ik1.pdf · The Use of Quaternions and SLERP for Character Animation ... a solution is SLERP;

Traditional Approaches

Euler Angles and Gimbal Lock

Euler Angles describe objects in space through their spatial orientatione.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

Page 8: The Use of Quaternions and SLERP for Character Animationembots.dfki.de/doc/seminar_ca/ik1.pdf · The Use of Quaternions and SLERP for Character Animation ... a solution is SLERP;

Traditional Approaches

Euler Angles and Gimbal Lock

Euler Angles describe objects in space through their spatial orientatione.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

Page 9: The Use of Quaternions and SLERP for Character Animationembots.dfki.de/doc/seminar_ca/ik1.pdf · The Use of Quaternions and SLERP for Character Animation ... a solution is SLERP;

Traditional Approaches

Euler Angles and Gimbal Lock

Euler Angles describe objects in space through their spatial orientatione.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

Page 10: The Use of Quaternions and SLERP for Character Animationembots.dfki.de/doc/seminar_ca/ik1.pdf · The Use of Quaternions and SLERP for Character Animation ... a solution is SLERP;

Traditional Approaches

Euler Angles and Gimbal Lock

Euler Angles describe objects in space through their spatial orientatione.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

Page 11: The Use of Quaternions and SLERP for Character Animationembots.dfki.de/doc/seminar_ca/ik1.pdf · The Use of Quaternions and SLERP for Character Animation ... a solution is SLERP;

Quaternions

Inventing Hypercomplex Numbers

quaternions were invented by William RowanHamilton in 1843

irish mathematician, philosopher andastronomer

first to describe complex numbers as vectors

searched for nearly 15 years on possibleextensions of Cquaternions form a finite-dimensional normeddivision algebras over R⇒ H is a group under multiplication

quaternion multiplication can be substitutedfor rotation matrix multiplication

designed them to be beautiful as well as useful

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

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

Page 12: The Use of Quaternions and SLERP for Character Animationembots.dfki.de/doc/seminar_ca/ik1.pdf · The Use of Quaternions and SLERP for Character Animation ... a solution is SLERP;

Quaternions

The Hamilton Algebra H

notation:

~q := (i, j,k)

0@xyz

1A⇒ q = t + ~q; while q ∈ H

Graham Product (Quaternion Multiplication):

~q1 ~q2 =ˆ− 1( ~q1 • ~q2)

˜+ˆ~q1 × ~q2

˜q1q2 =

ˆt1t2(−1 ~q1 • ~q2)

˜+ˆt1 ~q2 + t2 ~q1 + ( ~q1 × ~q2)

˜while inner and outer product are defined as in R

ij = k jk = i ki = jik = −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

Page 13: The Use of Quaternions and SLERP for Character Animationembots.dfki.de/doc/seminar_ca/ik1.pdf · The Use of Quaternions and SLERP for Character Animation ... a solution is SLERP;

Quaternions

Rotation Matrices to Quaternions Part I

M =

0@m11 m12 m13m21 m22 m23m31 m32 m33

1A , M ∈ R3×3 q = t + ~q, q ∈ H ~q =

0@ixjykt

1A0 < 1

4 (1 + m11 + m22 + m33)

⇒ t =12

p(1 + m11 + m22 + m33)

x = (m23 −m32)14t

y = (m13 −m13)14t

z = (m12 −m21)14t

· · ·

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

Page 14: The Use of Quaternions and SLERP for Character Animationembots.dfki.de/doc/seminar_ca/ik1.pdf · The Use of Quaternions and SLERP for Character Animation ... a solution is SLERP;

Quaternions

Rotation Matrices to Quaternions Part II

M =

0@m11 m12 m13m21 m22 m23m31 m32 m33

1A , M ∈ R3×3 q = t + ~q, q ∈ H ~q =

0@ixjykt

1A0 ≥ 1

4 (1 + m11 + m22 + m33) and

0 < − 12 (m22 + m33)

⇒ t = 0

x =

r−1

2(m22 + m33)

y = (m12)12x

z = (m13)12x

· · ·

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

Page 15: The Use of Quaternions and SLERP for Character Animationembots.dfki.de/doc/seminar_ca/ik1.pdf · The Use of Quaternions and SLERP for Character Animation ... a solution is SLERP;

Quaternions

Rotation Matrices to Quaternions Part III

M =

0@m11 m12 m13m21 m22 m23m31 m32 m33

1A , M ∈ R3×3 q = t + ~q, q ∈ H ~q =

0@ixjykt

1A0 ≥ 1

4 (1 + m11 + m22 + m33) and

0 ≥ − 12 (m22 + m33) and

0 < 12 (1−m33)

⇒ t, x = 0

y =

r12

(1−m33)

z = m2312y

· · ·

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

Page 16: The Use of Quaternions and SLERP for Character Animationembots.dfki.de/doc/seminar_ca/ik1.pdf · The Use of Quaternions and SLERP for Character Animation ... a solution is SLERP;

Quaternions

Rotation Matrices to Quaternions Part IV

M =

0@m11 m12 m13m21 m22 m23m31 m32 m33

1A , M ∈ R3×3 q = t + ~q, q ∈ H ~q =

0@ixjykt

1A0 ≥ 1

4 (1 + m11 + m22 + m33) and

0 ≥ − 12 (m22 + m33) and

0 ≥ 12 (1−m33)

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

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

Page 17: The Use of Quaternions and SLERP for Character Animationembots.dfki.de/doc/seminar_ca/ik1.pdf · The Use of Quaternions and SLERP for Character Animation ... a solution is SLERP;

Quaternions

Quaternions to Rotation Matrices

q = t + ~q, q ∈ H with ~q =

0@ixjykt

1A , t2 + x2 + y2 + z2 = 1

and M =

0@m11 m12 m13m21 m22 m23m31 m32 m33

1A , M ∈ R3×3

⇒ M =

0@1− 2y2 − 2x2 2xy + 2tz 2xz − 2ty2xy− 2tz 1− 2x2 − 2z2 2yz + 2tx2xz + 2ty 2yz − 2tx 1− 2x2 − 2y2

1A

[Sho85]

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

Page 18: The Use of Quaternions and SLERP for Character Animationembots.dfki.de/doc/seminar_ca/ik1.pdf · The Use of Quaternions and SLERP for Character Animation ... a solution is SLERP;

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~c = 1

2 (~a + ~b)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

Page 19: The Use of Quaternions and SLERP for Character Animationembots.dfki.de/doc/seminar_ca/ik1.pdf · The Use of Quaternions and SLERP for Character Animation ... a solution is SLERP;

Interpolation

SLERP

(N)LERP is fast and easy to understandand implement, but it has a drawback:it yields results with varying velocity

a solution is SLERP; spherical LERP:

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

sin θ q2

with cos θ = q1q2

[Sho85, Blo04]

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

Page 20: The Use of Quaternions and SLERP for Character Animationembots.dfki.de/doc/seminar_ca/ik1.pdf · The Use of Quaternions and SLERP for Character Animation ... a solution is SLERP;

Interpolation

SLERP and Beziér Curves

now we are able to interpolate between to quaternions

to interpolate between more than 2 points, Beziér curvesare 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 , andbn+1 between each quaternion pair qn , qn+1 and define a curve throughthem with starting point qn and ending point qn+1

[Mor01, Wik08b, Sho85]

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

Page 21: The Use of Quaternions and SLERP for Character Animationembots.dfki.de/doc/seminar_ca/ik1.pdf · The Use of Quaternions and SLERP for Character Animation ... a solution is SLERP;

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

Page 22: The Use of Quaternions and SLERP for Character Animationembots.dfki.de/doc/seminar_ca/ik1.pdf · The Use of Quaternions and SLERP for Character Animation ... a solution is SLERP;

Interpolation

How to use SLERP in H

1 conversion from matrix to quaternions;obtaining a set of quaternions on unit sphereM → {q1, q2, ...qn , qn+1}

2 construction of Beziér curves – with additional control points –between each quaternion pairBez(qn ,an ,bn+1, qn+1)

3 animation through frames along the curves, using time as a parametercomputing qn+t

4 interpolation of single quaternions along curves using SLERP and backconversionqn+t → Mt

[Mor01, Sho85]

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

Page 23: The Use of Quaternions and SLERP for Character Animationembots.dfki.de/doc/seminar_ca/ik1.pdf · The Use of Quaternions and SLERP for Character Animation ... a solution is SLERP;

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 resultin gimbal lock (contra)

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

Page 24: The Use of Quaternions and SLERP for Character Animationembots.dfki.de/doc/seminar_ca/ik1.pdf · The Use of Quaternions and SLERP for Character Animation ... a solution is SLERP;

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 involvesa 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

Page 25: The Use of Quaternions and SLERP for Character Animationembots.dfki.de/doc/seminar_ca/ik1.pdf · The Use of Quaternions and SLERP for Character Animation ... a solution is SLERP;

Conclusion

Bibliography

[Blo04] Jonathan Blow. Understanding slerp, then not using it. The Inner Produc,2004.

[Joh03] M. P. Johnson. Exploiting Quaternions to Support Expressive InteractiveCharacter 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 SingerCompany; Link Flight Simulation Division, 1985.

[VK05] M. Fleck V. Kremer. Hypercomplex Fouriertransformations, 2005. SeminarGeometric 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:[email protected]

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