Rotation representation and Interpolation CSE 3541 Matt Boggus.

39
Rotation representation and Interpolation CSE 3541 Matt Boggus

Transcript of Rotation representation and Interpolation CSE 3541 Matt Boggus.

Page 1: Rotation representation and Interpolation CSE 3541 Matt Boggus.

Rotation representation and Interpolation

CSE 3541Matt Boggus

Page 2: Rotation representation and Interpolation CSE 3541 Matt Boggus.

Rotation Matrices

1000

0100

00cossin

00sincos

1000

0cos0sin

0010

0sin0cos

1000

0cossin0

0sincos0

0001

Page 3: Rotation representation and Interpolation CSE 3541 Matt Boggus.

Interpolating Orientations in 3D• Rotation matrices• Given rotation matrices Mi and time ti,

find M(t) such that M(ti)=Mi

x

y

z

M

uv

n

ux

vx

nx

uy

vy

ny

uz

vz

nz

Page 4: Rotation representation and Interpolation CSE 3541 Matt Boggus.

Flawed Solution• Interpolate each entry independently• Example: M0 is identity and

M1 is 90o around x-axis

• Is the result a rotation matrix?

1 0 0 1 0 0 1 0 0

Interpolate ( 0 1 0 , 0 0 1 ) 0 0.5 0.5

0 0 1 0 1 0 0 0.5 0.5

1 0 0 1 0 0 1 0 0

Interpolate ( 0 1 0 , 0 0 1 ) 0 0.5 0.5

0 0 1 0 1 0 0 0.5 0.5

Page 5: Rotation representation and Interpolation CSE 3541 Matt Boggus.

Orientation Representations

Rotation matrixFixed angles: rotate about global coordinate systemEuler angles: rotate about local coordinate systemAxis-angle: arbitrary axis and angleQuaternions: mathematically handy axis-angle 4-tuple

Page 6: Rotation representation and Interpolation CSE 3541 Matt Boggus.

Fixed Angles

• Any orientation can be described by composing three rotations, one around each global coordinate axis

• Roll, pitch and yaw(perfect for flight simulation)

http://www.fho-emden.de/~hoffmann/gimbal09082002.pdf

Page 7: Rotation representation and Interpolation CSE 3541 Matt Boggus.

Gimbal Lock• Two or more axes align resulting in a loss of

rotation degrees of freedom.

http://www.fho-emden.de/~hoffmann/gimbal09082002.pdf

Page 8: Rotation representation and Interpolation CSE 3541 Matt Boggus.

Fixed Angles in the Real World

• Apollo inertial measurement unit• To “prevent” lock, they added a fourth Gimbal

http://www.hq.nasa.gov/office/pao/History/alsj/gimbals.html

Page 9: Rotation representation and Interpolation CSE 3541 Matt Boggus.

Axis-Angle

zyx

A

Rotate about given axisEuler’s Rotation TheoremFairly easy to interpolate between orientationsDifficult to concatenate rotations

X

Y

Z

A Q

Page 10: Rotation representation and Interpolation CSE 3541 Matt Boggus.

Axis-angle to rotation matrix

X

Y

Z

A Q Concatenate the following:Rotate A around z to x-z planeRotate A’ around y to x-axisRotate theta around xUndo rotation around y-axisUndo rotation around z-axis

Page 11: Rotation representation and Interpolation CSE 3541 Matt Boggus.

Quaternions (intuitionally)

ARot A *)

2sin(

2cos

Same as axis-angle, but different formStill rotate about given axisMathematically convenient form

X

Y

Z

vs

qNote: in this form v is a scaled version of the given axis of rotation, A (which is a vector)

A Q

Page 12: Rotation representation and Interpolation CSE 3541 Matt Boggus.

Quaternion

Rotation Quaternions

Identity (no rotation) 1, -1

180 degrees about x-axis i, -i

180 degrees about y-axis j, -j

180 degrees about z-axis k, -k

angle θ, axis (unit vector)

q = s + xi + yj + zk where i, j, and k are imaginary numbers

Page 13: Rotation representation and Interpolation CSE 3541 Matt Boggus.

Quaternion Arithmetic

Addition

Multiplication

Length

Inner Product

22112121 vsvsvvss

212112212121 vvvsvsvvssqq

212121 vvssqq

qqq

Page 14: Rotation representation and Interpolation CSE 3541 Matt Boggus.

Quaternion Arithmetic

Inverse vsqq

2

11

000111 qqqq

111 pqpq

Unit quaternionq

qq ˆ

Identity

Page 15: Rotation representation and Interpolation CSE 3541 Matt Boggus.

Quaternion Representation and Rotation

Vector

Rotation

v0

1)(' qvqvRotv q

Page 16: Rotation representation and Interpolation CSE 3541 Matt Boggus.

Unit Quaternion Conversions

22

22

22

2212222

2222122

2222221

yxsxyzsyxz

sxyzzxszxy

syxzszxyzy

Rot zyxs

vvzyx

s

/),,(

)(cos2 1

Axis-Angle

Page 17: Rotation representation and Interpolation CSE 3541 Matt Boggus.

QuaternionsWhat an animator needs to know

Avoid gimbal lock

Easy to rotate a point

Easy to convert to a rotation matrix

Easy to concatenate – quaternion multiply

Easy to interpolate – interpolate 4-tuples

Page 18: Rotation representation and Interpolation CSE 3541 Matt Boggus.

Rotations within Unity

transform.Rotate(eulerAngles : Vector3, relativeTo : Space = Space.Self)

DescriptionApplies a rotation of eulerAngles.z degrees around the z axis, eulerAngles.x degrees around the x axis, and eulerAngles.y degrees around the y axis (in that order).

Page 19: Rotation representation and Interpolation CSE 3541 Matt Boggus.

Rotations within Unity

transform.Rotate(axis : Vector3, angle : float, relativeTo : Space = Space.Self)

DescriptionRotates the transform around axis by angle degrees.

Page 20: Rotation representation and Interpolation CSE 3541 Matt Boggus.

Rotations within Unity

transform.RotateAround(point : Vector3, axis : Vector3, angle : float)

DescriptionRotates the transform about axis passing through point in world coordinates by angle degrees.This modifies both the position and the rotation of the transform.

Page 21: Rotation representation and Interpolation CSE 3541 Matt Boggus.

Rotations within Unity

Vector3.RotateTowards(current : Vector3, target : Vector3, maxRadiansDelta : float, maxMagnitudeDelta : float)

DescriptionRotates a vector current towards target.

Page 22: Rotation representation and Interpolation CSE 3541 Matt Boggus.

Orientation along a curve

Page 23: Rotation representation and Interpolation CSE 3541 Matt Boggus.

Orientation on a curve in 2D

Page 24: Rotation representation and Interpolation CSE 3541 Matt Boggus.

Orientation on a curve in 2D

Page 25: Rotation representation and Interpolation CSE 3541 Matt Boggus.

Orientation on a curve in 2D

q1 and q2 are orthogonal to P’(u)i.e. q1 = Rotate(90) * P’(u) q2 = Rotate(-90) * P’(u)

Page 26: Rotation representation and Interpolation CSE 3541 Matt Boggus.

Frenet Frame

Global axes: x, y, zLocal axes: u, v, wP(s) = parametric curve function with s on [0,1]

a moving (coordinate) frame that provides a coordinate system at each point of the curve that is "best adapted" to the curve near that point

Page 27: Rotation representation and Interpolation CSE 3541 Matt Boggus.

Frenet Frame tangent & curvature vector

Page 28: Rotation representation and Interpolation CSE 3541 Matt Boggus.

Frenet Frame tangent & curvature vector

MBUuP

MBUuP

UMBuP

'')(''

')('

)(

0026''

0123'

12

23

uU

uuU

uuuU

Page 29: Rotation representation and Interpolation CSE 3541 Matt Boggus.

Frenet Framelocal coordinate system

Directly control orientation of object/camera

Use for direction and bank into turn, especially for ground-planar curves (e.g. roads)

w = P’(s)u = P’’(s) × P’(s)v = w × u

Page 30: Rotation representation and Interpolation CSE 3541 Matt Boggus.

Frenet Frame – sometimes undefined

Page 31: Rotation representation and Interpolation CSE 3541 Matt Boggus.

Frenet Frame – discontinuity

Page 32: Rotation representation and Interpolation CSE 3541 Matt Boggus.

Other ways to control orientation

Use point P(s+ds) for direction

Use auxiliary curve to define direction or up vector

Page 33: Rotation representation and Interpolation CSE 3541 Matt Boggus.

Direction & Up vector

Direction vector

w

u=w × y-axis

v = u × wTo keep ‘head up’, use y-axis to compute over and up vectors perpendicular to direction vector

If up vector supplied, use that instead of y-axis

Page 34: Rotation representation and Interpolation CSE 3541 Matt Boggus.

Orientation interpolation

Preliminary note:1. Remember that2. Affects of scale are divided out by the inverse appearing in quaternion

rotation3. When interpolating quaternions, use UNIT quaternions – otherwise

magnitudes can interfere with spacing of results of interpolation

)()( vRotvRot kqq

Page 35: Rotation representation and Interpolation CSE 3541 Matt Boggus.

Orientation interpolation

2 problems analogous to issues when interpolating positions:1. How to take equidistant steps along orientation path?2. How to pass through orientations smoothly (1st order continuous)3. And another particular to quaternions: with dual unit quaternion

representations, which to use?

Quaternions can be interpolated to produce in-between orientations:

21)1( kqqkq

Page 36: Rotation representation and Interpolation CSE 3541 Matt Boggus.

Dual representation

Dual unit quaternion representations: q = –q

)()( vRotvRot kqq

For Interpolation between q1 and q2, compute cosine between q1 and q2 and between q1 and –q2; choose smallest angle

Page 37: Rotation representation and Interpolation CSE 3541 Matt Boggus.

Interpolating quaternions

Linearly interpolating unit quaternions: not equally spaced

Unit quaternions form set of points on 4D sphere

Page 38: Rotation representation and Interpolation CSE 3541 Matt Boggus.

Interpolating quaternions in great arc => equal spacing

Page 39: Rotation representation and Interpolation CSE 3541 Matt Boggus.

Interpolating quaternions with equal spacing

2121 sin

sin

sin

)1sin(),,(slerp q

uq

uuqq

‘slerp’, sphereical linear interpolation is a function of • the beginning quaternion orientation, q1• the ending quaternion orientation, q2• the interpolant, u

Still a linear order interpolation

cos21 qqwhere