3D orientation

Download Report

Transcript 3D orientation

3D orientation

• Rotation matrix • Fixed angle and Euler angle • Axis angle • Quaternion • Exponential map

Joints and rotations

Rotational 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

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

Translation

new point translation matrix old point

Scaling

new point scaling matrix old point

Rotation

X axis Y axis Z axis

Composite transformations

A series of transformations on an object can be applied as a series of matrix multiplications : position in the global coordinate : position in the local coordinate

Interpolation

• • In order to “move things”, we need both translation and rotation Interpolating the translation is easy, but what about rotations?

Motivation

• Finding the most natural and compact way to present rotation and orientations • Orientation interpolation which result in a natural motion • A closed mathematical form that deals with rotation and orientations (expansion for the complex numbers)

Rotation Matrix

• A general rotation can be represented by a single 3x3 matrix • Length Preserving (Isometric) • Reflection Preserving • Orthonormal

R

u x

  

v w x x u y v y w y u z v w z z

  

Fixed Angle Representation

• 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, ie. first about x, then y, then z • Many possible orderings, don’t have to use all 3 axes, but can’t do the same axis back to back

Fixed Angle Representation

• A rotation of 10,45, 90 would be written as • Rz(90) Ry(45), Rx(10) since we want to first rotate about x, y, z. It would be applied then to the point P…. RzRyRx P • Problem occurs when two of the axes of rotation line up on top of each other. This is called “Gimbal Lock”

Gimbal Lock

essentially makes the first axis of rotation align with the third.

• Incremental changes in x,z produce the same results – you’ve lost a degree of freedom

Gimbal Lock

• Phenomenon of two rotational axis of an object pointing in the same direction.

• Simply put, it means your object won't rotate how you think it ought to rotate.

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

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

Properties of rotation matrix

• • Easily composed?

Interpolate?

• Rotation matrix • Fixed angle and Euler angle • Axis angle • Quaternion • Exponential map

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

Fixed angle

• A rotation of Rz(90)Ry(60)Rx(30) looks like

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

Euler angle vs. fixed angle

• •

R

z (90)

R

y (60)

R

x (30) =

E

x (30)

E

y (60)

E

z (90) Euler angle rotations about moving axes written in reverse order are the same as the fixed axis rotations Z Y X

Gimbal Lock (again!)

• Rotation by 90 o causes a loss of a degree of freedom  1

x z z y x

 1

x’

 1  /2

y x z

 3

x’

 1

y

Gimbal Lock

• Phenomenon of two rotational axis of an object pointing in the same direction.

• Simply put, it means your object won't rotate how you think it ought to rotate.

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

Gimbal lock

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

Properties of Euler angle

• • • • Easily composed?

Interpolate?

How about joint limit?

What seems to be the problem?

Euler Angles

• A general rotation is a combination of three elementary rotations: around the x-axis (x-roll) , around the y-axis (y-roll) and around the z-axis (z-roll).

Euler Angles

Euler Angles and Rotation 1

x

roll

(  1 )    0 0 0 0  cos sin  1  1 0 0 sin  1 cos  1 0 Matrices 0 cos  2 0 0   y roll(  2 )    sin 0  2 1 0 0 1 0 0  sin  2 0 cos  2 0 0 0 0   1

z

roll

(  3 )     cos  sin 3  3 0 0 sin  3 cos  3 0 0 0 0 1 0 0 0 0   1

R

(  1 ,  2 ,  3 )   

s

1

s c

1

s

2

c

2

c

3

c

2

c

3 3 

c

1

s

3 

s

1

s

3 0

s

1

s c

1

s

2 2

s c

2

s

3

s

3 3 

c

1

c

3 

s

1

c

3 0 

s

2

s

1

c

2

c

1

c

2 0 0 0 0   1

Euler angles interpolation

y π x z x-roll π y x z R(0,0,0),…,R(  t,0,0),…,R(  ,0,0) t  [0,1] y π x y-roll π z y π x z z-roll π y R(0,0,0),…,R(0,  t,  t),…,R(0,  ,  ) x z

Euler Angles Interpolation  Unnatural movement !

• Rotation matrix • Fixed angle and Euler angle • Axis angle • Quaternion • Exponential map

Goal

• Find a parameterization in which • a simple steady rotation exists between two key orientations • moves are independent of the choice of the coordinate system

Axis angle

• • • Represent orientation as a vector and a scalar vector is the axis to rotate about scalar is the angle to rotate by

Angle and Axis

Any orientation can be represented by a 4-tuple • angle, vector(x,y,z) where the angle is the amount to rotate by and the vector is the axis to rotate about • Can interpolate the angle and axis separately • No gimbal lock problems!

• But, can’t efficiently compose rotations…must convert to matrices first!

Angular displacement

v

||  (

n

v

)

n R

[

v

 ]

R

[

v

|| ] 

v

 

v

 

v

||

v

 cos  cos  

v

v

||   (

n

v

 ) sin (

n

v

) sin   (  ,n) defines an angular displacement of  about an axis n

n v v

||

n

v

 

R

[

v

v

] 

R

[

v

]   

v

cos

R

[

v

||   

v

 ] (

n

v

)

n

 (

v

R

[

v

|| ] 

R

[

v

 ]  (

n

v

)

n

) cos 

n

(

n

v

)( 1  cos  ) 

v

|| 

v

  (

n

v

) sin   (

n

v

) sin  cos   (

n

v

) sin 

Properties of axis angle

• • Can avoid Gimbal lock. Why?

Can interpolate the vector and the scalar separately. How?

Axis angle interpolation

• Rotation matrix • Fixed angle and Euler angle • Axis angle • Quaternion • Exponential map

Quaternion

4 tuple of real numbers: scalar vector Same information as axis angles but in a different form

• Quaternions ?

Extend the concept of rotation in 3D to 4D.

• Avoids the problem of "gimbal-lock" and allows for the implementation of smooth and continuous rotation. • In effect, they may be considered to add a additional rotation angle to spherical coordinates ie. Longitude, Latitude and Rotation angles • A Quaternion is defined using four floating point values |x y z w|. These are calculated from the combination of the three coordinates of the rotation axis and the rotation angle.

How do quaternions relate to 3D

• Instead of rotating an object through a series of successive rotations, a quaternion allows the programmer to rotate an object through a single arbitary rotation axis. • Because the rotation axis is specifed as a unit direction vector, it may be calculated through vector mathematics or from spherical coordinates ie (longitude/latitude). • Quaternions interpolation : smooth and predictable rotation effects.

Quaternion to Rotation Matrix

Q

 

X Y Z W

M

     1 2 2  2

XY Y XZ

2    2 2 2

Z ZW YW

2 2

XY

 2

ZW

1  2

X

2  2

Z

2 2

YZ

 2

XW

1 2 2 

XZ YZ

2

X

  2 2 

YW

2

XW

2

Y

2    

Quaternions Definition

Extension of complex numbers • 4-tuple of real numbers • s,x,y,z or [s,v] • s is a scalar • v is a vector • Same information as axis/angle but in a different form • Can be viewed as an original orientation or a rotation to apply to an object

Quaternions Math

Quaternions properties

• The conjugate and magnitude are similar to complex numbers

q

 (

s

, 

v

)

q

q

*

q

s

2 

v x

2 

v

2

y

v z

2 • Quaternions are non commutative • •

q 1 = (s 1 ,v 1 ) q 2 = (s 2 ,v 2 ) q 1 *q 2 = (s 1 s 2 – v 1.

v 2 , s 1 v 2 + s 2 v 1 + v 1

x

v 2 )

inverse:

q

 1 

q

unit quaternion:

q

*

q q

 1 

q

 1 

q

Quaternion Rotation

To rotate a vector, v using quaternion math • represent the vector as [0,v] •

q

represent the rotation as a quaternion, q 

Rot

 , 

x

,

y

,

z

   cos     

x

,

y

,

z

 

v

 

Rot

q

v

q

 1

Quaternions as Rotations

Rotation of P=(0,

r

) about the unit vector

n

θ using the unit quaternion q=(s,v) by an angle

R

q [

P

] 

qPq

 1  ( 0 , (

s

2 

v

v

)

r

 2

v

(

v

r

)  2

sv

r

) but q=(cos ½ θ, sin ½ θ • n) where |n|=1

R q

[

P

]  ( 0 , (cos 2  2  sin 2 (

n

r

) cos  2 sin 2    2 )

r

2 )  2

n

(

n

r

) sin 2  2  ( 0 , cos 

r

 ( 1  cos  )

n

(

n

r

)  (

n

r

) sin  )

Quaternions as Rotations

• Concatenating rotations then using q 2 – rotate using q 1 is like rotation using q 2 *q 1

q

2 * (

q

1 *

P

*

q

1  1 ) *

q

2  1  (

q

2 *

q

1 ) *

P

* (

q

1  1 *

q

2  1 )  (

q

2 *

q

1 ) *

P

* (

q

2 *

q

1 )  1 and

Quaternion math

Unit quaternion Multiplication

Quaternion math

Conjugate Inverse the unit length quaternion

Quaternion Rotation

If is a unit quaternion and then results in rotating about by proof: see

Quaternions

by Shoemaker

Quaternion Rotation

Quaternion composition

If and are unit quaternion the combined rotation of first rotating by and then by is equivalent to

Matrix form

Quaternion interpolation

1-angle rotation can be represented by a unit circle 2-angle rotation can be represented by a unit sphere • • Interpolation means moving on n-D sphere Now imagine a 4-D sphere for 3-angle rotation

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

Quaternion interpolation

Direct linear interpolation does not work Linearly interpolated intermediate points are not uniformly spaced when projected onto the circle Spherical linear interpolation (SLERP) Normalize to regain unit quaternion

Rotations in Reality

• It’s easiest to express rotations in Euler angles or Axis/angle • We can convert to/from any of these representations • Choose the best representation for the task • input:Euler angles • interpolation: quaternions • composing rotations: quaternions, orientation matrix

• Rotation matrix • Fixed angle and Euler angle • Axis angle • Quaternion • Exponential map

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

Properties of exponential map • • • • No need to re-normalize the parameters Fewer DOFs Good interpolation behavior Singularities exist but can be avoided

Choose a representation

• • • • • • Choose the best representation for the task input: Euler angles joint limits: interpolation: compositing: rendering: Euler angles, quaternion (harder) quaternion or exponential map quaternions or orientation matrix orientation matrix ( quaternion can be represented as matrix as well)