73
CSCE 689: Computer Animation Rotation Representation and Interpolation Jinxiang Chai

CSCE 689: Computer Animation Rotation Representation and Interpolation Jinxiang Chai

  • View
    245

  • Download
    5

Embed Size (px)

Citation preview

Page 1: CSCE 689: Computer Animation Rotation Representation and Interpolation Jinxiang Chai

CSCE 689: Computer Animation Rotation Representation and

InterpolationJinxiang Chai

Page 2: CSCE 689: Computer Animation Rotation Representation and Interpolation Jinxiang Chai

Joints and Rotation

Rotational dofs are widely used in character animation

3 translation dofs

48 rotational dofs

1 dof: knee 2 dof: wrist 3 dof: shoulder

Page 3: CSCE 689: Computer Animation Rotation Representation and Interpolation Jinxiang Chai

• Orientation is described relative to some reference alignment

• A rotation changes object from one orientation to another

• Can represent orientation as a rotation from the reference alignment 

Orientation vs. Rotation 

Page 4: CSCE 689: Computer Animation Rotation Representation and Interpolation Jinxiang Chai

Ideal Orientation Format 

• Represent 3 degrees of freedom with minimum number of values

• Allow concatenations of rotations

• Math should be simple and efficient – concatenation – interpolation – rotation

Page 5: CSCE 689: Computer Animation Rotation Representation and Interpolation Jinxiang Chai

Outline

• Rotation matrix

• Fixed angle and Euler angle

• Axis angle

• Quaternion

Page 6: CSCE 689: Computer Animation Rotation Representation and Interpolation Jinxiang Chai

3D Transformation

• A 3D point (x,y,z) – x,y, and z coordinates

• We will still use column vectors to represent points

• Homogeneous coordinates of a 3D point

(x,y,z,1)T

• Transformation will be performed using 4x4 matrix

x

y

z

Page 7: CSCE 689: Computer Animation Rotation Representation and Interpolation Jinxiang Chai

Right-handed Coordinate System

x

y

z

;zyx ;xzy yxz

Left hand coordinate system

Not used in this class and

Not in OpenGL

Page 8: CSCE 689: Computer Animation Rotation Representation and Interpolation Jinxiang Chai

3D Transformation

• Very similar to 2D transformation

• Translation transformation

11000

100

010

001

1

z

y

x

t

t

t

z

y

x

x

y

x

Homogenous coordinates

Page 9: CSCE 689: Computer Animation Rotation Representation and Interpolation Jinxiang Chai

3D Transformation

• Very similar to 2D transformation

• Scaling transformation

11000

000

000

000

1

z

y

x

s

s

s

z

y

x

z

y

x

Homogenous coordinates

Page 10: CSCE 689: Computer Animation Rotation Representation and Interpolation Jinxiang Chai

3D Rotation

• 3D rotation is done around a rotation axis

• Fundamental rotations – rotate about x, y, or z axes

• Counter-clockwise rotation is referred to as positive rotation (when you look down negative axis)

x

y

z

+

Page 11: CSCE 689: Computer Animation Rotation Representation and Interpolation Jinxiang Chai

3D Rotation

• Rotation about z – similar to 2D rotation

x

y

z

+

11000

0100

00cossin

00sincos

1

z

y

x

z

y

x

zz

yxy

yxx

'

cossin'

sincos'

Page 12: CSCE 689: Computer Animation Rotation Representation and Interpolation Jinxiang Chai

3D Rotation

• Rotation about y: z -> y, y -> x, x->z

x

y

z

11000

0cos0sin

0010

0sin0cos

1

z

y

x

z

y

x

yy

xzx

xzz

'

cossin'

sincos'

y

z

x

Page 13: CSCE 689: Computer Animation Rotation Representation and Interpolation Jinxiang Chai

3D Rotation

• Rotation about x (z -> x, y -> z, x->y)

x

y

z

11000

0cossin0

0sincos0

0001

1

z

y

x

z

y

x

xx

zyz

zyy

'

cossin'

sincos'

z

x

y

Page 14: CSCE 689: Computer Animation Rotation Representation and Interpolation Jinxiang Chai

3D Rotation

• An arbitrary rotation can be defined by a matrix

x

y

z

11 44434241

34333231

24232221

14131211

z

y

x

mmmm

mmmm

mmmm

mmmm

z

y

x

Page 15: CSCE 689: Computer Animation Rotation Representation and Interpolation Jinxiang Chai

Matrices as Orientation 

• Matrices just fine, right?

• No… – 9 values to interpolate – don’t interpolate well

Page 16: CSCE 689: Computer Animation Rotation Representation and Interpolation Jinxiang Chai

Representation of orientation

Homogeneous coordinates (review):– 4X4 matrix used to represent translation,

scaling, and rotation

– a point in the space is represented as

– Treat all transformations the same so that they can be easily combined

1

z

y

x

P

Page 17: CSCE 689: Computer Animation Rotation Representation and Interpolation Jinxiang Chai

Rotation

New points rotation matrix old points

Page 18: CSCE 689: Computer Animation Rotation Representation and Interpolation Jinxiang Chai

Interpolation

• In order to “move things”, we need both translation and rotation

• Interpolating the translation is easy, but what about rotations?

Page 19: CSCE 689: Computer Animation Rotation Representation and Interpolation Jinxiang Chai

Interpolation of Orientation

• How about interpolating each entry of the rotation matrix?

• The interpolated matrix might no longer be orthonormal, leading to nonsense for the inbetween rotations

Page 20: CSCE 689: Computer Animation Rotation Representation and Interpolation Jinxiang Chai

Interpolation of Orientation

Example: interpolate linearly from a positive 90 degree rotation about y axis to a negative 90 degree rotation about y

Linearly interpolate each component and halfway between, you get this...

1000

0001

0010

0100

1000

0001

0010

0100

Rotate about y-axis with 90

Rotate about y-axis with -90

1000

0000

0010

0000

Page 21: CSCE 689: Computer Animation Rotation Representation and Interpolation Jinxiang Chai

Properties of Rotation Matrix

Easily composed?

Interpolation?

Compact representation?

Page 22: CSCE 689: Computer Animation Rotation Representation and Interpolation Jinxiang Chai

Properties of Rotation Matrix

Easily composed? yes

Interpolation?

Compact representation?

Page 23: CSCE 689: Computer Animation Rotation Representation and Interpolation Jinxiang Chai

Properties of Rotation Matrix

Easily composed? yes

Interpolation? not good

Compact representation?

Page 24: CSCE 689: Computer Animation Rotation Representation and Interpolation Jinxiang Chai

Properties of Rotation Matrix

Easily composed? yes

Interpolation? not good

Compact representation? - 9 parameters (only needs 3 parameters)

Page 25: CSCE 689: Computer Animation Rotation Representation and Interpolation Jinxiang Chai

Outline

• Rotation matrix

• Fixed angle and Euler angle

• Axis angle

• Quaternion

Page 26: CSCE 689: Computer Animation Rotation Representation and Interpolation Jinxiang Chai

Fixed Angles

• Angles used to rotate about fixed axes

• Orientations are specified by a set of 3 ordered parameters that represent 3 ordered rotations about fixed axes

• Many possible orderings: x-y-z, x-y-x,y-x-z - as long as axis does immediately follow itself such as x-x-y

Page 27: CSCE 689: Computer Animation Rotation Representation and Interpolation Jinxiang Chai

E.g., (z, y, x)

XZ

Y

Q = Rx(x). Ry(y). Rz(z). P

Ordered triple of rotations about global axes, any triple can be used that doesn’t immediately repeat an axis, e.g., x-y-z, is fine, so is x-y-x. But x-x-z is not.

Fixed Angles

Page 28: CSCE 689: Computer Animation Rotation Representation and Interpolation Jinxiang Chai

Euler Angles vs. Fixed Angles 

One point of clarification

Euler angle

- rotates around local axes

Fixed angle

- rotates around world axes Rotations are reversed

- x-y-z Euler angles == z-y-x fixed angles

Page 29: CSCE 689: Computer Animation Rotation Representation and Interpolation Jinxiang Chai

Euler Angle Interpolation

• Interpolating each components separately

• Might have singularity problem – Halfway between (0, 90, 0) & (90, 45, 90) – Interpolate directly, get (45, 67.5, 45)– Desired result is (90, 22.5, 90) (verify this!)

Page 30: CSCE 689: Computer Animation Rotation Representation and Interpolation Jinxiang Chai

Euler Angle Concatenation 

• Can't just add or multiply components • Best way:

– Convert to matrices – Multiply matrices – Extract Euler angles from resulting matrix

• Not cheap

Page 31: CSCE 689: Computer Animation Rotation Representation and Interpolation Jinxiang Chai

Gimbal Lock 

• Euler/fixed angles not well-formed • Different values can give same rotation • Example with z-y-x fixed angles:

( -90, 90, 90 ) = ( 0, 90, 0 )

Page 32: CSCE 689: Computer Animation Rotation Representation and Interpolation Jinxiang Chai

Gimbal Lock 

• Euler/fixed angles not well-formed • Different values can give same rotation • Example with z-y-x fixed angles:

( -90, 90, 90 ) = ( 0, 90, 0 )

z

y

x

Page 33: CSCE 689: Computer Animation Rotation Representation and Interpolation Jinxiang Chai

Gimbal Lock 

• Euler/fixed angles not well-formed • Different values can give same rotation • Example with z-y-x fixed angles:

( -90, 90, 90 ) = ( 0, 90, 0 )

z

y

x

z

y

x

(-90,0,0)

Page 34: CSCE 689: Computer Animation Rotation Representation and Interpolation Jinxiang Chai

Gimbal Lock 

• Euler/fixed angles not well-formed • Different values can give same rotation • Example with z-y-x fixed angles:

( -90, 90, 90 ) = ( 0, 90, 0 )

z

y

x

z

y

x

z

y

x

(-90,0,0) (-90,90,0)

Page 35: CSCE 689: Computer Animation Rotation Representation and Interpolation Jinxiang Chai

Gimbal Lock 

• Euler/fixed angles not well-formed • Different values can give same rotation • Example with z-y-x fixed angles:

( -90, 90, 90 ) = ( 0, 90, 0 )

z

y

x

z

y

x

z

y

x y

x

z

(-90,0,0) (-90,90,0) (-90,90,90)

Page 36: CSCE 689: Computer Animation Rotation Representation and Interpolation Jinxiang Chai

Gimbal Lock

• A Gimbal is a hardware implementation of Euler angles used for mounting gyroscopes or expensive globes

• Gimbal lock is a basic problem with representing 3D rotation using Euler angles or fixed angles

Page 37: CSCE 689: Computer Animation Rotation Representation and Interpolation Jinxiang Chai

Gimbal Lock

• When two rotational axis of an object pointing in the same direction, the rotation ends up losing one degree of freedom

Page 38: CSCE 689: Computer Animation Rotation Representation and Interpolation Jinxiang Chai

Outline

• Rotation matrix

• Fixed angle and Euler angle

• Axis angle

• Quaternion

Page 39: CSCE 689: Computer Animation Rotation Representation and Interpolation Jinxiang Chai

(Ax,Ay,Az,)

Euler’s rotation theorem: An arbitrary rotation may be described by only three parameters.

X

Y

Z

Rotate object by around A

Axis Angle

Page 40: CSCE 689: Computer Animation Rotation Representation and Interpolation Jinxiang Chai

Axis-angle Rotation

rr’

n

Given r – Vector in space to rotate n – Unit-length axis in space about which to rotate – The amount about n to rotate

Solve r’ – The rotated vector

Page 41: CSCE 689: Computer Animation Rotation Representation and Interpolation Jinxiang Chai

Axis-angle Rotation

rr’

rpar

• Compute rpar: the projection of r along the n direction

rpar = (n·r)n

Page 42: CSCE 689: Computer Animation Rotation Representation and Interpolation Jinxiang Chai

Axis-angle Rotation

r

r’rperprpar

• Compute rperp: rperp = r-rpar

Page 43: CSCE 689: Computer Animation Rotation Representation and Interpolation Jinxiang Chai

Axis-angle Rotation

r

r’rperp

v

rpar

• Compute v: a vector perpedicular to rpar and rperp: v= rparxrperp

Page 44: CSCE 689: Computer Animation Rotation Representation and Interpolation Jinxiang Chai

Axis-angle Rotation

r

r’rperp

v

Use rpar, rperp and v, θ to compute the new vector!

rpar

• Compute v: a vector perpedicular to rpar and rperp: v= rparxrperp

Page 45: CSCE 689: Computer Animation Rotation Representation and Interpolation Jinxiang Chai

Axis-angle Rotation

r

r’

n

rpar = (n·r) n

rperp = r – (n·r) n

V = n x (r – (n·r) n) = n x r

r’ = r’par + r’perp

= r’par + (cos ) rperp + (sin ) V=(n·r) n + cos (r – (n·r)n) + (sin ) n x r= (cos )r + (1 – cos ) n (n·r) + (sin ) n x r

Page 46: CSCE 689: Computer Animation Rotation Representation and Interpolation Jinxiang Chai

Axis-angle Rotation

• Can interpolate rotation well

Page 47: CSCE 689: Computer Animation Rotation Representation and Interpolation Jinxiang Chai

1. Interpolate axis from A1 to A2 Rotate axis about A1 x A2 to get A

X

Y

Z

2. Interpolate angle from 1 to to get

3. Rotate the object by around A

A1 x A2

Axis-angle Interpolation

Page 48: CSCE 689: Computer Animation Rotation Representation and Interpolation Jinxiang Chai

Axis-angle Rotation

• Can interpolate rotation well

• Compact representation

• Messy to concatenate - might need to convert to matrix form

Page 49: CSCE 689: Computer Animation Rotation Representation and Interpolation Jinxiang Chai

Outline

• Rotation matrix

• Fixed angle and Euler angle

• Axis angle

• Quaternion

Page 50: CSCE 689: Computer Animation Rotation Representation and Interpolation Jinxiang Chai

Quaternion

Remember complex numbers: a+ib, where i2=-1

Quaternions are a non-commutative extension of complex numbers

Invented by Sir William Hamilton (1843) Quaternion: - Q = a + bi + cj + dk: where i2=j2=k2=ijk=-1,ij=k,jk=i,ki=j - Represented as: q = (w, v) = w + xi + yj + zk

Page 51: CSCE 689: Computer Animation Rotation Representation and Interpolation Jinxiang Chai

Quaternion

• 4 tuple of real numbers: w, x, y, z

• Same information as axis angles but in a more computational-friendly form

Page 52: CSCE 689: Computer Animation Rotation Representation and Interpolation Jinxiang Chai

Quaternion Math

Unit quaternion

Multiplication

Associative

Non-commutative

Page 53: CSCE 689: Computer Animation Rotation Representation and Interpolation Jinxiang Chai

Quaternion Math

Conjugate

Inverse

Page 54: CSCE 689: Computer Animation Rotation Representation and Interpolation Jinxiang Chai

Quaternion Example

let

then

Page 55: CSCE 689: Computer Animation Rotation Representation and Interpolation Jinxiang Chai

Quaternion Rotation

Page 56: CSCE 689: Computer Animation Rotation Representation and Interpolation Jinxiang Chai

Quaternion Rotation

Page 57: CSCE 689: Computer Animation Rotation Representation and Interpolation Jinxiang Chai

Quaternion Example

• Rotate a point (1,0,0) about y-axis with -90 degrees

z

x

y

(1,0,0)

(0,0,1)

Page 58: CSCE 689: Computer Animation Rotation Representation and Interpolation Jinxiang Chai

Quaternion Example

• Rotate a point (1,0,0) about y-axis with 90 degrees

z

x

y

(1,0,0)

(0,0,1)

)

1

0

0

,0(

)

0

1

0

2

90sin,

2

90)(cos

0

0

1

,0)(

0

1

0

2

90sin,

2

90(cos *

Page 59: CSCE 689: Computer Animation Rotation Representation and Interpolation Jinxiang Chai

Quaternion Example

• Rotate a point (1,0,0) about y-axis with 90 degrees

z

x

y

(1,0,0)

(0,0,1)

)

1

0

0

,0(

)

0

1

0

2

90sin,

2

90)(cos

0

0

1

,0)(

0

1

0

2

90sin,

2

90(cos *

Point (1,0,0)

Page 60: CSCE 689: Computer Animation Rotation Representation and Interpolation Jinxiang Chai

Quaternion Example

• Rotate a point (1,0,0) about y-axis with 90 degrees

z

x

y

(1,0,0)

(0,0,1)

)

1

0

0

,0(

)

0

1

0

2

90sin,

2

90)(cos

0

0

1

,0)(

0

1

0

2

90sin,

2

90(cos *

Point (1,0,0)

Quaternion rotation

Page 61: CSCE 689: Computer Animation Rotation Representation and Interpolation Jinxiang Chai

Quaternion Example

• Rotate a point (1,0,0) about y-axis with 90 degrees

z

x

y

(1,0,0)

(0,0,1)

)

1

0

0

,0(

)

0

1

0

2

90sin,

2

90)(cos

0

0

1

,0)(

0

1

0

2

90sin,

2

90(cos *

Page 62: CSCE 689: Computer Animation Rotation Representation and Interpolation Jinxiang Chai

Quaternion Composition

Rotq (Rotp (v)) Rotq (p 0 v p 1)

qp 0 v p 1q 1

qp 0 v (qp) 1

Rotqp (v)

Rotation by p then q is the same as rotation by qp

Page 63: CSCE 689: Computer Animation Rotation Representation and Interpolation Jinxiang Chai

Matrix Form

1

0

1

'

'

'

q

z

y

xq

z

y

x

1

)(

1

'

'

'

z

y

x

qRz

y

x

For a 3D point (x,y,z)

Page 64: CSCE 689: Computer Animation Rotation Representation and Interpolation Jinxiang Chai

Quaternion Interpolation

1-angle rotation can berepresented by a unit circle

Page 65: CSCE 689: Computer Animation Rotation Representation and Interpolation Jinxiang Chai

Quaternion Interpolation

1-angle rotation can berepresented by a unit circle

2-angle rotation can berepresented by a unit sphere

Page 66: CSCE 689: Computer Animation Rotation Representation and Interpolation Jinxiang Chai

Quaternion Interpolation

• Interpolation means moving on n-D sphere

• Now imagine a 4-D sphere for 3-angle rotation

1-angle rotation can berepresented by a unit circle

2-angle rotation can berepresented by a unit sphere

Page 67: CSCE 689: Computer Animation Rotation Representation and Interpolation Jinxiang Chai

Quaternion Interpolation

Moving between two points on the 4D unit

Sphere:

• a unit quaternion at each step - another point on the 4D unit sphere

• move with constant angular velocity along the great circle between the two points on the 4D unit sphere

Page 68: CSCE 689: Computer Animation Rotation Representation and Interpolation Jinxiang Chai

Quaternion Interpolation

Direct linear interpolation does not workLinearly interpolated intermediate points are not uniformly spaced when projected onto the circle

Page 69: CSCE 689: Computer Animation Rotation Representation and Interpolation Jinxiang Chai

Quaternion Interpolation

Spherical linear interpolation (SLERP) Normalize to regain unit quaternion

Page 70: CSCE 689: Computer Animation Rotation Representation and Interpolation Jinxiang Chai

Quaternion Interpolation

Spherical linear interpolation (SLERP) Normalize to regain unit quaternion

Page 71: CSCE 689: Computer Animation Rotation Representation and Interpolation Jinxiang Chai

Quaternion Interpolation

Spherical linear interpolation (SLERP) Normalize to regain unit quaternion

Page 72: CSCE 689: Computer Animation Rotation Representation and Interpolation Jinxiang Chai

Quaternions

• Can interpolate rotation well

• Compact representation

• Also easy to concatenate