33
1 Representations and Transformations 2 Objectives • Derive homogeneous coordinate transformation matrices • Introduce standard transformations - Rotations - Translation - Scaling - Shear

Representations and Transformations - University of …vbz/cs230w14-04.pdf ·  · 2014-01-21•Scalars can be defined as members of a set ... [x y z w] T •We can return to a simple

  • Upload
    hadat

  • View
    213

  • Download
    0

Embed Size (px)

Citation preview

1

Representations and

Transformations

2

Objectives

•Derive homogeneous coordinate transformation matrices

• Introduce standard transformations- Rotations- Translation- Scaling- Shear

2

3

Scalars, Points, Vectors

•Three basic elements from geometry:Scalars, Points, Vectors

•Scalars can be defined as members of a set which can be combined by the operations of addition and multiplication and obey the fundamental axioms:

associativity, commutivity, inversion•Examples include the real and complex numbers under the rules we are all familiar with

•Scalars alone have no geometric properties

4

• A vector is a quantity with two attributes direction & magnitude and its own rules as we saw last lecture

• The set defines a vector space

Scalars, Points, Vectors

•But, vectors lack positionSame length and magnitude ->

•Vectors are insufficient to specify geometryWe need points

3

5

•Points, we know, are locations in space

•Certain operations translate between points and vectors

- Point-point subtraction yields a vector

- Leads to equivalent to point-vector addition

P=v+Q

v=P-Q

Points and Vectors

6

• Consider a basis v1, v2,…., vn

• A vector is written v=1v1+ 2v2 +….+nvn

• The list of scalars {1, 2, …. n} then is therepresentation of v with respect to the given basis

• And we write the representation as a row or column array of scalars

a=[1 2 …. n]T=

n

2

1

.

Vector Spaces

4

7

•Vector spaces do not represent points

• Instead, we work in an affine space and add a special point, the origin, to the basis vectors, this is called a frame

P0

v1

v2

v3

Affine Spaces

8

Affine Spaces

•An affine space is both point and vector space

• It allows operations from vectors, points and scalars:

- Vector-vector addition

- Scalar-vector multiplication

- Point-vector addition

- All scalar-scalar operations

• Define our space with a coordinate “Frame”

5

9

•A frame is determined by (P0, v1, v2, v3, ...)•Within this frame:

Every vector can be written as v=1v1+ 2v2 +….+nvn

And every point can be written asP = P0 + 1v1+ 2v2 +….+nvn

Affine Spaces

10

Consider the point and the vector

P = P0 + 1v1+ 2v2 +….+nvn

v=1v1+ 2v2 +….+nvn

They appear to have the similar representations

p=[1 2 3] v=[1 2 3]

which confuse the point with the vector

But, a vector has no position v

pv

can be placed anywherefixed

Homogeneous Coordinates

6

11

•An affine space distinguishes point and vector with

( 1 )( P ) = P

( 0 )( P ) = 0 (zero vector)

Homogeneous Coordinates

12

With these rules, we can keep track of the difference:

v=1v1+ 2v2 +3v3 = [1 2 3 0 ] [v1 v2 v3 P0] T

P = P0 + 1v1+ 2v2 +3v3= [1 2 3 1 ] [v1 v2 v3 P0] T

Thus we obtain a four-dimensional representation for both:

v = [1 2 3 0 ] T

p = [1 2 3 1 ] T

Homogeneous Coordinates

7

13

Homogeneous Coordinates

• Homogeneous coordinates are key to all computer graphics systems

• Hardware pipeline all work with 4 dimensional representations

• All standard transformations (rotation, translation, scaling) can be implemented by matrix multiplications with 4 x 4 matrices

14

Homogeneous Coordinates

•Most generally, the form of homogeneous coordinates is

p=[x y z w] T

•We can return to a simple three dimensional point by

x'x/wy'y/wz'z/w

•But if w=0, the representation is that of a vector

8

15

Transformations

•A transformation maps points to other points and/or vectors to other vectors

Q=T(P)

v=T(u)

16

Affine Transformations

•Line preserving

•Characteristic of many physically important transformations

- Rigid body transformations: rotation, translation

- Non-rigid: Scaling, shear

• Importance in graphics is that we need only transform vertices (points) of line segments and polygons, then system draws between the transformed points

9

17

Translation

•Move (translate, displace) a point to a new location

•Displacement determined by a vector d- Three degrees of freedom- P’=P+d

P

P’

d

18

Moving objects

When we move a point on an object to a new location, to preserve the object, we must move all other points on the object in the same way

object translation: every point displacedby the same vector, d

10

19

Translation Using Representations

Using the homogeneous coordinate representation in some frame

p=[ x y z 1]T

p’=[x’ y’ z’ 1]T

d=[dx dy dz 0]T

Hence p’ = p + d orx’=x+dxy’=y+dyz’=z+dz

note that this expression is in four dimensions and expressesthat point = vector + point

20

Translation Matrix

We can also express translation using a 4 x 4 matrix T in homogeneous coordinatesp’=Tp where

T = T(dx, dy, dz) =

This form is better for implementation because all affine transformations can be expressed this way and multiple transformations can be concatenated together

1000

d100

d010

d001

z

y

x

11

21

Rotation (2D)

• Consider rotation about the origin by degrees

- radius stays the same, angle increases by

What is this rotationabout the z axis?

22

Rotation (2D)

• Consider rotation about the origin by degrees

- radius stays the same, angle increases by

x’=x cos –y sin y’ = x sin + y cos

x = r cos y = r sin

x = r cos (y = r sin (

12

23

Rotation about the z axis

• Rotation about z axis in three dimensions leaves all points with the same z

- Equivalent to rotation in two dimensions in planes of constant z

- or in matrix notation (with p as a column)

p’=Rz()p

x’=x cos –y sin y’ = x sin + y cos z’ =z

24

Rotation Matrix

1000

0100

00 cossin

00sin cos

R = Rz() =

Homogeneous Coordinates:

13

25

Rotation about x and y axes

• Same argument as for rotation about z axis- For rotation about x axis, x is unchanged

- For rotation about y axis, y is unchanged

R = Rx() =

R = Ry() =

1000

0 cos sin0

0 sin- cos0

0001

1000

0 cos0 sin-

0010

0 sin0 cos

26

Scaling

1000

000

000

000

z

y

x

s

s

s

S = S(sx, sy, sz) =

x’=sxxy’=syyz’=szz

p’=Sp

Expand or contract along each axis (fixed point of origin)

14

27

Reflection

corresponds to negative scale factors

originalsx = -1 sy = 1

sx = -1 sy = -1 sx = 1 sy = -1

28

Shear

•Helpful to add one more basic transformation•Equivalent to pulling faces in opposite directions

15

29

Shear Matrix

Consider simple shear along x axis

x’ = x + y shy

y’ = yz’ = z

1000

0100

0010

00sh1 y

H() =

30

Inverses

• Although we could compute inverse matrices by general formulas, we can also use simple geometric observations, for example:

- Translation: T-1(dx, dy, dz) = T(-dx, -dy, -dz)

- Rotation: R -1() = R(-)

• Holds for any rotation matrix

• Note that since cos(-) = cos() and sin(-)= -sin()

R -1() = R T()

- Scaling: S-1(sx, sy, sz) = S(1/sx, 1/sy, 1/sz)

16

31

Composite

•In modeling, we often start with a simple object centered at the origin, oriented with the axis, and at a standard size•We apply an composite transformation to its vertices to

Scale OrientLocate

32

Composite Transformations

• Scaling about a fixed point- Simply applying the scale transformation

also moves the object being scaled.

P

Q

P'

Q'

17

33

Composite Transformations

• Scaling about origin does not move object• Origin is a fixed point for the scale transformation• We use composite transformations to create scale

transformations with different fixed points

P

Q

P'

Q'

34

Composite Transformations

• Fixed point scale transformation• Move fixed point (px,py,pz) to origin• Scale by desired amount• Move fixed point back to original position

M = T(px, py, pz) S(sx, sy, sz) T(-px, -py, -pz)

18

35

Composite Transformations

• Rotating about a fixed point- basic rotation alone will rotate about origin

but we want:

36

Composite Transformations

• Rotating about a fixed point• Move fixed point (px,py,pz) to origin• Rotate by desired amount• Move fixed point back to original position

M = T(px, py, pz) Rx() T(-px, -py, -pz)

19

37

Composite Transformations

38

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

20

39

Interpolation

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

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

40

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

21

41

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

42

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)

22

43

•Rotation matrix

•Euler angle

•Axis angle

•Quaternion

•Exponential map

Representing Rotation

44

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

Joints and rotations

23

45

Euler Angle Representation

• Angles used to rotate about cardinal axes

• Orientations are specified by a set of 3 ordered parameters that represent 3 ordered rotations about 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

46

Euler Angles

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

24

47

Euler Angles and Rotation Matrices

1000

0100

00cossin

00sincos

)(

1000

0cos0sin

0010

0sin0cos

)pitch(- y

1000

0cossin0

0sincos0

0001

)(

33

33

3

22

22

211

111

yawz

rollx

1000

0

0

0

),,(213132131321

213132131321

23232

321 cccssscsscsc

csccssssccss

ssccc

R

48

Gimbal Lock

• A 90 degree rotation about the y axis 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

25

49

Gimbal Lock

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

• Result: Lose a degree of freedom (DOF)

50

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

26

51

Euler angles interpolation

z

xy

π

x-roll π

y

z

x

y

z

xz-yaw π

z

xy

π

z

xy

π

y-pitch π

R(0,0,0),…,R(t,0,0),…,R(,0,0)

t[0,1]

R(0,0,0),…,R(0,t, t),…,R(0,, )

52

Euler Angles Interpolation Unnatural movement !

27

53

•Rotation matrix

•Euler angle

•Axis angle

•Quaternion

•Exponential map

Representing Rotation

54

Axis angle

• Represent orientation as a vector and a scalar

- vector is the axis to rotate about

- scalar is the angle to rotate by

28

55

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!

56

•Rotation matrix

•Euler angle

•Axis angle

•Quaternion

•Exponential map

Representing Rotation

29

57

Quaternions

•Extension of imaginary numbers

•Requires one real and three imaginary components i, j, k

q=q0+q1i+q2j+q3k

58

Quaternions

•Extension of imaginary numbers

•Requires one real and three imaginary components i, j, k

q = (w, x, y, z)

= cos + sin

x, y, z ] of axis

2

2

30

Quaternion interpolation

• Interpolation means moving on n-D sphere

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

1-angle rotation can be represented by a unit circle

2-angle rotation can be represented by a unit sphere

•Quaternions can express rotations on unit sphere smoothly and efficiently.

60

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 along the great circle between the two points on the 4D unit sphere as an arc

31

61

Quaternion interpolation

Spherical linear interpolation (SLERP)

Process:-Rotation matrix quaternion

-Carry out slerp/operations with quaternions

-Quaternion rotation matrix

62

Matrix form

32

63

Quaternions – points on a 4D unit hypersphere+ better interpolation+ almost unique- less intuitive

Summary

64

Quaternion Math

Unit quaternion

Multiplication

33

65

Quaternion Rotation

If is a unit quaternion and

then results in rotating about by

proof: see Quaternions by Shoemaker

66

Choose a representation

•Choose the best representation for the task

- input:

- joint limits:

- interpolation:

- compositing:

- rendering:

quaternion or exponential map

Euler angles

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

quaternions or orientation matrix

Euler angles, quaternion (harder)