Animating Rotations and Using Quaternions - PowerPoint PPT Presentation

1 / 20
About This Presentation
Title:

Animating Rotations and Using Quaternions

Description:

Euler Angles ... Euler Angles. . ?1. ?2. Can you do it? Line 1: P1 = (0,1,0) P2 = (1,0,1) ... Alternative to Euler angles for specifying orientation ... – PowerPoint PPT presentation

Number of Views:191
Avg rating:3.0/5.0
Slides: 21
Provided by: Ali5153
Category:

less

Transcript and Presenter's Notes

Title: Animating Rotations and Using Quaternions


1
Animating Rotations and Using Quaternions
2
What Well Talk About
  • Animating Translation
  • Animating 2D Rotation
  • Euler Angle representation
  • 3D Angle problems
  • Quaternions
  • Animating with quaternions

3
Review Translation
Translation2D Rotation3D RotationEulerProblems
QuaternionsQ. Animation
P X Y Z 1
P TP
x txy tyz tz 1
1 tx 1 ty 1tz
1
T
Animation interpolate over tx,ty,tz in T Move
from (10,20,30) to (10,50,40), in time 0 to
10 ?x (50-20)/10 ?y (40-30)/10
1 10 1 20 130
1
1 10 1 23 131
1
1 10 1 50 140
1
1 10 1 26 132
1

Time 0
Time 1
Time 2
Time 10
4
Review 2D Rotation
2D Rotation3D RotationEulerProblemsQuaternions
Q. Animation
cos ? -sin ? sin ? cos ?
1
P RP
?
R
Animating 2D Rotations
Number of frames 3?R (90-0)/3 30
cos 90 -sin 90 sin 90 cos 90
1
cos 60 -sin 60 sin 60 cos 60
1
cos 0 -sin 0 sin 0 cos 0
1
cos 30 -sin 30 sin 30 cos 30
1
5
Review 3D Rotations
3D RotationEulerProblemsQuaternionsQ.
Animation
1 cos ? -sin ? sin ? cos ?
1
Rx
Orientation specified by a combination of
rotations in a predetermined order RxRyRz
cos ? sin ? 1 -sin ?
cos ? 1

Ry
cos ? -sin ? sin ? cos ?
1 1

Rz
6
Euler Angles
EulerQuaternionsQ. Animation
  • Eulers Theorem any orientation can be expressed
    as a single rotation about an axis
  • Can lead to Gimbal lock
  • Gives you the basic idea
  • Euler representation is good basis for
    calculating quaternions, which work well
  • Ideas
  • Orientation represented by an angle and an
    (x,y,z) vector, e.g. (A1, ?1)
  • Axes represent local coordinate system, not
    global
  • Rotation order is reverse of global, i.e. RzRyRx

7
Euler Angles
EulerQuaternionsQ. Animation
  • Determine axis of rotation from 1st line a to
    second line b cross product a x b
  • Determine angle between linesdot product a
    b cos ØØ acos ( a b/ (ab) ) note
    normalized angle
  • Animation with k 0..1 axisk rotate(k Ø ) a
    anglek (1-k)?1 k?2

?1
Ø
?2
8
Can you do it?
  • Line 1 P1 (0,1,0) P2 (1,0,1)
  • Line 2 Q1 (1,1,1) Q2 (3,3,3)
  • Cross product(-4,0,-4)
  • acos ab/ab acos(2/(v3 2v3) acos(1/3)
    70.5 degrees

9
Motivation
ProblemsEulerQuaternionsQ. Animation
  • We would like to represent 3D rotations about an
    arbitrary axis
  • We would like to be able to apply a series of
    arbitrary rotations and have it actually work..
  • Direct interpolation of matrices leads to
    nonsense
  • Gimbal lock occurs when the axes of two of the
    three gimbals needed to compensate for rotations
    in 3D space are driven to the same direction,
    e.g. (0,90,0)

10
What is a quaternion?
QuaternionsQ. Animation
  • Alternative to Euler angles for specifying
    orientation
  • 4-tuple use 3 numbers for axis of rotation 1
    for angle of rotation
  • Let q be a quaternion
  • q s,v
  • s, vx, vy, vz
  • s vxi vyj Vzk

11
Quaternion algebra
QuaternionsQ. Animation
Quaternions are like complex numbers, with one
normal component and 3 imaginary components,
i,j,k. (abi)(cdi) (ac-bd) (cb-ad)i
  • i2 j2 k2 -1 i-j-k
  • ij k -ji jk i -kj ki j -ik
  • q1 q2 (s1 s2, v1 v2)
  • q1q2 q3if s1 s2 0, then q3 (v1v2 ,v1 x
    v2)general q3 (s1s2- v1v2, s1v2 s2v1 v1x
    v2 )
  • q1q2 (s1s2 v1v2)

12
Not all Quaternions Represent Rotations
QuaternionsQ. Animation
  • Only unit-length quaternions are rotations
  • q sqrt( s2 v v) 1
  • q 1/q s,v
  • q-1 1/q2 s,-v
  • The inverse rotation is rotation by the same
    amount by the negative axis
  • Unit quaternion defined by
  • q (cos ?/2, sin ?/2x,y,z)

13
Suppose I had an Euler Rotation
  • q (cos ?/2, sin ?/2x,y,z) where ? and
    (x,y,z) are the Euler angle and axis respectively
  • Normalize using quaternion normalization rules q

14
Note
QuaternionsQ. Animation
  • q -q (-s,-v) cos (-?/2),
    sin(-?/2)-x,-y,-z cos (?/2),
    -sin(?/2)-x,-y,-z ( cos (?/2),
    sin(?/2)x,y,z )

15
Convert Q to matrix form
QuaternionsQ. Animation
  • M 1-2y2-2z2 2xy 2sz 2xy -2sy 2xy
    2sz 1-2x2-2z2 2yz 2sx
  • 2xz 2sy 2yz 2sx 1-2x2-2y2

16
Rotating a point p by q
QuaternionsQ. Animation
  • Rq(p) q p qwhere q s,-v (conjugate of
    q)where p 0,(px, py, pz)Rq(p)
    s,v0,ps,-v 0,(s2-v v)p 2v(v p) 2s(v
    x p)

17
Consecutive Rotations
  • R2(R1(p))
  • q2(q1 p q1)q2 (q2 q1) p (q2 q1)
  • R21(p)
  • Very convenient

18
Note about conjugates
  • q s,-v
  • q-1 1/q2 q (normalize!!)
  • For unit quaternions, q-1 q

19
Animating Rotations Using Quaternions
  • How to find intermediate rotations?
  • Linear interpolationlerp( q1, q2, u) q1(1-u)
    uq2
  • Advantage easier to find q vs. animating
    rotation matrix
  • Problem will speed up in the midst of rotation

q1
q point on a 4D unit sphere
?
q2
20
Animating Rotations Using Quaternions
  • Spherical Interpolation
  • slerp( q1, q2, u) sin(1-u) ?/sin ? q1 sin
    u?/sin ? q2
  • Where q1q2 cos ? (note use smaller ? )
  • Why?
  • Plane trigonometry
  • a b c
  • sin sin ß sin

Spherical Trigonometry Same formula, but a,b,c
arearc lengths
b
a
ß
b
a
ß
c
c
Write a Comment
User Comments (0)
About PowerShow.com