3D orientation - Georgia Institute of · PDF fileRepresentation of orientation ... •...

45
3D orientation

Transcript of 3D orientation - Georgia Institute of · PDF fileRepresentation of orientation ... •...

Page 1: 3D orientation - Georgia Institute of  · PDF fileRepresentation of orientation ... • Euler angle rotations about moving axes written ... Euler angles orientation matrix

3D orientation

Page 2: 3D orientation - Georgia Institute of  · PDF fileRepresentation of orientation ... • Euler angle rotations about moving axes written ... Euler angles orientation matrix

• Rotation matrix

• Fixed angle and Euler angle

• Axis angle

• Quaternion

• Exponential map

Page 3: 3D orientation - Georgia Institute of  · PDF fileRepresentation of orientation ... • Euler angle rotations about moving axes written ... Euler angles orientation matrix

Joints and rotationsRotational DOFs are widely used in character animation

3 translational DOFs

48 rotational DOFs

Each joint can have up to 3 DOFs

1 DOF: knee 2 DOF: wrist 3 DOF: arm

Page 4: 3D orientation - Georgia Institute of  · PDF fileRepresentation of orientation ... • Euler angle rotations about moving axes written ... Euler angles orientation matrix

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

p =

!

"

"

#

x

y

z

1

$

%

%

&

Page 5: 3D orientation - Georgia Institute of  · PDF fileRepresentation of orientation ... • Euler angle rotations about moving axes written ... Euler angles orientation matrix

Translation

!

"

"

#

x + txy + tyz + tz

1

$

%

%

&

=

!

"

"

#

1 0 0 tx0 1 0 ty0 0 1 tz0 0 0 1

$

%

%

&

!

"

"

#

x

y

z

1

$

%

%

&

translationmatrixnew point old point

Page 6: 3D orientation - Georgia Institute of  · PDF fileRepresentation of orientation ... • Euler angle rotations about moving axes written ... Euler angles orientation matrix

Scaling

!

"

"

#

sxx

syy

szz

1

$

%

%

&

=

!

"

"

#

sx 0 0 0

0 sy 0 0

0 0 sz 0

0 0 0 1

$

%

%

&

!

"

"

#

x

y

z

1

$

%

%

&

scaling matrixnew point old point

Page 7: 3D orientation - Georgia Institute of  · PDF fileRepresentation of orientation ... • Euler angle rotations about moving axes written ... Euler angles orientation matrix

Rotation

!

"

"

#

x!

y!

z!

1

$

%

%

&

=

!

"

"

#

cos ! ! sin ! 0 0

sin ! cos ! 0 0

0 0 1 0

0 0 0 1

$

%

%

&

!

"

"

#

xyz1

$

%

%

&

!

"

"

#

x!

y!

z!

1

$

%

%

&

=

!

"

"

#

1 0 0 0

0 cos ! ! sin ! 0

0 sin ! cos ! 0

0 0 0 1

$

%

%

&

!

"

"

#

xyz1

$

%

%

&

!

"

"

#

x!

y!

z!

1

$

%

%

&

=

!

"

"

#

cos ! 0 sin ! 0

0 1 0 0

! sin ! 0 cos ! 0

0 0 0 1

$

%

%

&

!

"

"

#

xyz1

$

%

%

&

X axis

Y axis

Z axis

Page 8: 3D orientation - Georgia Institute of  · PDF fileRepresentation of orientation ... • Euler angle rotations about moving axes written ... Euler angles orientation matrix

Composite transformations

A series of transformations on an object can be applied as a series of matrix multiplications

p = T(x0, y0, z0)R(!0)R("0)R(#0)T(0, h0, 0)R(!1)R("1)R(#1)T(0, h1, 0)R(!2)T(0, h2, 0)R(!3)R("3)x

p

!3!3

!1

!0!0

!1

!2

!1

!0x0 y0 z0

p : position in the global coordinate

x : position in the local coordinate

h1

h2

h0

h3

(h3, 0, 0)

Page 9: 3D orientation - Georgia Institute of  · PDF fileRepresentation of orientation ... • Euler angle rotations about moving axes written ... Euler angles orientation matrix

Interpolation

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

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

Page 10: 3D orientation - Georgia Institute of  · PDF fileRepresentation of orientation ... • Euler angle rotations about moving axes written ... Euler angles orientation matrix

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 in-between rotations

Page 11: 3D orientation - Georgia Institute of  · PDF fileRepresentation of orientation ... • Euler angle rotations about moving axes written ... Euler angles orientation matrix

Interpolation of orientationExample: interpolate linearly from a positive 90 degree rotation about y axis to a negative 90 degree rotation about y

!

"

"

#

0 0 1 0

0 1 0 0

!1 0 0 0

0 0 0 1

$

%

%

&

!

"

"

#

0 0 !1 0

0 1 0 0

1 0 0 0

0 0 0 1

$

%

%

&

!

"

"

#

0 0 0 0

0 1 0 0

0 0 0 0

0 0 0 1

$

%

%

&

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

Page 12: 3D orientation - Georgia Institute of  · PDF fileRepresentation of orientation ... • Euler angle rotations about moving axes written ... Euler angles orientation matrix

Properties of rotation matrix

• Easily composed? Yes

• Interpolate? No

Page 13: 3D orientation - Georgia Institute of  · PDF fileRepresentation of orientation ... • Euler angle rotations about moving axes written ... Euler angles orientation matrix

• Rotation matrix

• Fixed angle and Euler angle

• Axis angle

• Quaternion

• Exponential map

Page 14: 3D orientation - Georgia Institute of  · PDF fileRepresentation of orientation ... • Euler angle rotations about moving axes written ... Euler angles orientation matrix

Fixed angle

• 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

Page 15: 3D orientation - Georgia Institute of  · PDF fileRepresentation of orientation ... • Euler angle rotations about moving axes written ... Euler angles orientation matrix

Euler angle

• Same as fixed angles, except now the axes move with the object

• An Euler angle is a rotation about a single Cartesian axis

• Create multi-DOF rotations by concatenating Euler angles

• evaluate each axis independently in a set order

Page 16: 3D orientation - Georgia Institute of  · PDF fileRepresentation of orientation ... • Euler angle rotations about moving axes written ... Euler angles orientation matrix

Euler angle vs. fixed angle

• Rz(90)Ry(60)Rx(30) = Ex(30)Ey(60)Ez(90)

• Euler angle rotations about moving axes written in reverse order are the same as the fixed axis rotations

Z

Y

X

http://www.arielnet.com/adi2001/demos/007/gimballock.asp

Page 17: 3D orientation - Georgia Institute of  · PDF fileRepresentation of orientation ... • Euler angle rotations about moving axes written ... Euler angles orientation matrix

Properties of Euler angle

• Easily composed? No

• Interpolate? Sometimes

• How about joint limit? Easy

• What seems to be the problem? Gimbal lock

Page 18: 3D orientation - Georgia Institute of  · PDF fileRepresentation of orientation ... • Euler angle rotations about moving axes written ... Euler angles orientation matrix

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 19: 3D orientation - Georgia Institute of  · PDF fileRepresentation of orientation ... • Euler angle rotations about moving axes written ... Euler angles orientation matrix

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

Page 20: 3D orientation - Georgia Institute of  · PDF fileRepresentation of orientation ... • Euler angle rotations about moving axes written ... Euler angles orientation matrix

• Rotation matrix

• Fixed angle and Euler angle

• Axis angle

• Quaternion

• Exponential map

Page 21: 3D orientation - Georgia Institute of  · PDF fileRepresentation of orientation ... • Euler angle rotations about moving axes written ... Euler angles orientation matrix

Axis angle

• Represent orientation as a vector and a scalar

• vector is the axis to rotate about

• scalar is the angle to rotate by

x

y

z

Page 22: 3D orientation - Georgia Institute of  · PDF fileRepresentation of orientation ... • Euler angle rotations about moving axes written ... Euler angles orientation matrix

Properties of axis angle

• Can avoid Gimbal lock. Why?

• It does 3D orientation in one step

• Can interpolate the vector and the scalar separately. How?

Page 23: 3D orientation - Georgia Institute of  · PDF fileRepresentation of orientation ... • Euler angle rotations about moving axes written ... Euler angles orientation matrix

Axis angle interpolation

B = A1 ! A2

! = cos!1

!

A1 · A2

|A1||A2|

"

Ak = RB(k!)A1

!k = (1 ! k)!1 + k!2

x

y

z

A2

!2

A1!1

Page 24: 3D orientation - Georgia Institute of  · PDF fileRepresentation of orientation ... • Euler angle rotations about moving axes written ... Euler angles orientation matrix

Properties of axis angle

• Easily composed? No, must convert back to matrix form

• Interpolate? Yes

• Joint limit? Yes

• Avoid Gimbal lock? Yes

Page 25: 3D orientation - Georgia Institute of  · PDF fileRepresentation of orientation ... • Euler angle rotations about moving axes written ... Euler angles orientation matrix

• Rotation matrix

• Fixed angle and Euler angle

• Axis angle

• Quaternion

• Exponential map

Page 26: 3D orientation - Georgia Institute of  · PDF fileRepresentation of orientation ... • Euler angle rotations about moving axes written ... Euler angles orientation matrix

Quaternion

!2

!1

1-angle rotation can be represented by a unit circle

(!1,"1)

(!2,"2)

2-angle rotation can be represented by a unit sphere

What about 3-angle rotation?

Page 27: 3D orientation - Georgia Institute of  · PDF fileRepresentation of orientation ... • Euler angle rotations about moving axes written ... Euler angles orientation matrix

Quaternion4 tuple of real numbers: w, x, y, z

q =

!

"

"

#

w

x

y

z

$

%

%

&

=

'

w

v

(

scalarvector

r

!q =

!

cos (!/2)sin (!/2)r

"

Same information as axis angles but in a different form

Page 28: 3D orientation - Georgia Institute of  · PDF fileRepresentation of orientation ... • Euler angle rotations about moving axes written ... Euler angles orientation matrix

Quaternion mathUnit quaternion |q| = 1

x2

+ y2

+ z2

+ w2

= 1

!

w1

v1

" !

w2

v2

"

=

!

w1w2 ! v1 · v2

w1v2 + w2v1 + v1 " v2

"

Multiplication

q1q2 != q2q1

q1(q2q3) = (q1q2)q3

Page 29: 3D orientation - Georgia Institute of  · PDF fileRepresentation of orientation ... • Euler angle rotations about moving axes written ... Euler angles orientation matrix

Quaternion math

Conjugate q!

=

!

w

v

"

!

=

!

w

!v

"

(q!)! = q

(q1q2)! = q

!

2q!

1

Inverse q!1

=

q"

|q|

qq!1

=

!

"

"

#

1

0

0

0

$

%

%

&

identity quaternion

Page 30: 3D orientation - Georgia Institute of  · PDF fileRepresentation of orientation ... • Euler angle rotations about moving axes written ... Euler angles orientation matrix

Quaternion Rotation

qp =

!

0

p

"

q =

!

cos (!/2)sin (!/2)r

"

If is a unit quaternion andq

then results in rotating about by qqpq!1

r !p

proof: see Quaternions by Shoemaker

p

x

y

z

!

r

Page 31: 3D orientation - Georgia Institute of  · PDF fileRepresentation of orientation ... • Euler angle rotations about moving axes written ... Euler angles orientation matrix

Quaternion Rotationqqpq

!1=

!

w

v

" !

0

p

" !

w

!v

"

=

!

w

v

" !

p · v

wp ! p " v

"

= 0=

!

wp · v ! v · wp + v · p " v

w(wp ! p " v) + (p · v)v + v " (wp ! p " v)

"

!

w1

v1

" !

w2

v2

"

=

!

w1w2 ! v1 · v2

w1v2 + w2v1 + v1 " v2

"

Page 32: 3D orientation - Georgia Institute of  · PDF fileRepresentation of orientation ... • Euler angle rotations about moving axes written ... Euler angles orientation matrix

Quaternion composition

If and are unit quaternionq2q1

q3 = q2 · q1

the combined rotation of first rotating by and then by is equivalent to

q1

q2

Page 33: 3D orientation - Georgia Institute of  · PDF fileRepresentation of orientation ... • Euler angle rotations about moving axes written ... Euler angles orientation matrix

Matrix form

q =

!

"

"

#

w

x

y

z

$

%

%

&

R(q) =

!

"

"

#

1 ! 2y2! 2z

2 2xy + 2wz 2xz ! 2wy 02xy ! 2wz 1 ! 2x

2! 2z

2 2yz + 2wx 02xz + 2wy 2yz ! 2wx 1 ! 2x

2! 2y

2 00 0 0 1

$

%

%

&

Page 34: 3D orientation - Georgia Institute of  · PDF fileRepresentation of orientation ... • Euler angle rotations about moving axes written ... Euler angles orientation matrix

Quaternion interpolation

• Interpolation means moving on n-D sphere

!2

!1

1-angle rotation can be represented by a unit circle

(!1,"1)

(!2,"2)

2-angle rotation can be represented by a unit sphere

Page 35: 3D orientation - Georgia Institute of  · PDF fileRepresentation of orientation ... • Euler angle rotations about moving axes written ... Euler angles orientation matrix

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 36: 3D orientation - Georgia Institute of  · PDF fileRepresentation of orientation ... • Euler angle rotations about moving axes written ... Euler angles orientation matrix

Quaternion interpolation

Direct linear interpolation does not work

Spherical linear interpolation (SLERP)

slerp(q1,q2, u) = q1

sin((1 ! u)!)

sin !+ q2

sin(u!)

sin !

Normalize to regain unit quaternion

Linearly interpolated intermediate points are not uniformly spaced when projected onto the circle

!

Page 37: 3D orientation - Georgia Institute of  · PDF fileRepresentation of orientation ... • Euler angle rotations about moving axes written ... Euler angles orientation matrix

Quaternion constraints

Cone constraint

!

1 ! cos !

2= y2

+ z2q =

!

"

"

#

w

x

y

z

$

%

%

&

tan (!/2) =qaxis

w

!

Twist constraint

Page 38: 3D orientation - Georgia Institute of  · PDF fileRepresentation of orientation ... • Euler angle rotations about moving axes written ... Euler angles orientation matrix

Properties of quaternion

• Easily composed?

• Interpolate?

• Joint limit?

• Avoid Gimbal lock?

• So what’s bad about Quaternion?

Page 39: 3D orientation - Georgia Institute of  · PDF fileRepresentation of orientation ... • Euler angle rotations about moving axes written ... Euler angles orientation matrix

• Rotation matrix

• Fixed angle and Euler angle

• Axis angle

• Quaternion

• Exponential map

Page 40: 3D orientation - Georgia Institute of  · PDF fileRepresentation of orientation ... • Euler angle rotations about moving axes written ... Euler angles orientation matrix

Exponential map

• Represent orientation as a vector

• direction of the vector is the axis to rotate about

• magnitude of the vector is the angle to rotate by

• Zero vector represents the identity rotation

Page 41: 3D orientation - Georgia Institute of  · PDF fileRepresentation of orientation ... • Euler angle rotations about moving axes written ... Euler angles orientation matrix

Properties of exponential map

• No need to re-normalize the parameters

• Fewer DOFs

• Good interpolation behavior

• Singularities exist but can be avoided

Page 42: 3D orientation - Georgia Institute of  · PDF fileRepresentation of orientation ... • Euler angle rotations about moving axes written ... Euler angles orientation matrix

Choose a representation

• Choose the best representation for the task

• input:

• joint limits:

• interpolation:

• compositing:

• rendering:

axis angle, quaternion or exponential map

Euler angles

orientation matrix ( quaternion can be represented as matrix as well)

quaternions or orientation matrix

Euler angles, quaternion (harder)

Page 43: 3D orientation - Georgia Institute of  · PDF fileRepresentation of orientation ... • Euler angle rotations about moving axes written ... Euler angles orientation matrix

Summary

• What is a Gimbal lock?

• What representations are subject to Gimbal lock?

• How does the interpolation work in each type of rotations?

Page 44: 3D orientation - Georgia Institute of  · PDF fileRepresentation of orientation ... • Euler angle rotations about moving axes written ... Euler angles orientation matrix

What’s next?

Page 45: 3D orientation - Georgia Institute of  · PDF fileRepresentation of orientation ... • Euler angle rotations about moving axes written ... Euler angles orientation matrix

• Physics!

• Ordinary differential equations

• Numeric solutions

• Read: Quaternions by Ken Shoemake