C O M P U T E R G R A P H I C S Stuff CMSC 435 / 634 Transformations 1/29 Geometric Transformations...

31
C O M P U T E R G R A P H I C S Stuff CMSC 435 / 634 Transformations 1/29 Geometric Transformations Readings: Chapters 5-6

Transcript of C O M P U T E R G R A P H I C S Stuff CMSC 435 / 634 Transformations 1/29 Geometric Transformations...

Page 1: C O M P U T E R G R A P H I C S Stuff CMSC 435 / 634 Transformations 1/29 Geometric Transformations Readings: Chapters 5-6.

C O M P U T E R G R A P H I C S

Stuff

CMSC 435 / 634 Transformations 1/29

GeometricTransformations

Readings: Chapters 5-6

Page 2: C O M P U T E R G R A P H I C S Stuff CMSC 435 / 634 Transformations 1/29 Geometric Transformations Readings: Chapters 5-6.

C O M P U T E R G R A P H I C S

Stuff

CMSC 435 / 634 Transformations 2/29

Announcement

• Proj 1 posted on 2/2, due two weeks from today.

Page 3: C O M P U T E R G R A P H I C S Stuff CMSC 435 / 634 Transformations 1/29 Geometric Transformations Readings: Chapters 5-6.

C O M P U T E R G R A P H I C S

Stuff

CMSC 435 / 634 Transformations 3/29

• Translate [1,3] by [7,9]

• Scale [2,3] by 5 in the X direction and 10 in the Y direction

• Rotate [2,2] by 90° (π/2)

• What is the result for each of the following two cases applied to the house in the figure.

Exercises

Case 1: Translate by

x=6, y=0 then rotate by 45º

0 1

1

2

2

3 4 5 6 7 8 9 10

3

4

5

6

Case 2: Rotate by 45 and then

translate by x=6, y=0

Page 4: C O M P U T E R G R A P H I C S Stuff CMSC 435 / 634 Transformations 1/29 Geometric Transformations Readings: Chapters 5-6.

C O M P U T E R G R A P H I C S

Stuff

CMSC 435 / 634 Transformations 4/29

• Translate [1,3] by [7,9]

• Scale [2,3] by 5 in the X direction and 10 in the Y direction

• Rotate [2,2] by 90° (π/2)

Examples

1

12

8

1

3

1

100

910

701

1

30

10

1

3

2

100

0100

005

1

2

2

1

2

2

100

001

010

1

2

2

100

0)2/cos()2/sin(

0)2/sin()2/cos(

Page 5: C O M P U T E R G R A P H I C S Stuff CMSC 435 / 634 Transformations 1/29 Geometric Transformations Readings: Chapters 5-6.

C O M P U T E R G R A P H I C S

Stuff

CMSC 435 / 634 Transformations 5/29

• Scene graph (DAG) construction from primitives

• Object motion (this lecture)• Camera motion (next lecture on viewing)

ROBOT transformation

upper body lower body

head trunk arm

base

Scenegraph(see Sceneview assignment)

stanchion

“is composed of hierarchy”

Why do we need geometric Transformations (T,R,S) in Graphics?

More on scenegraphs on Slide 18

Page 6: C O M P U T E R G R A P H I C S Stuff CMSC 435 / 634 Transformations 1/29 Geometric Transformations Readings: Chapters 5-6.

C O M P U T E R G R A P H I C S

Stuff

CMSC 435 / 634 Transformations 6/29

2D Transformations

Page 7: C O M P U T E R G R A P H I C S Stuff CMSC 435 / 634 Transformations 1/29 Geometric Transformations Readings: Chapters 5-6.

C O M P U T E R G R A P H I C S

Stuff

CMSC 435 / 634 Transformations 7/29

• Component-wise addition of vectors

v’ = v + t where

and x’ = x + dx

y’ = y + dy

To move polygons: translate vertices (vectors) and redraw lines between them

• Preserves lengths (isometric)

• Preserves angles (conformal)

• Translation is thus "rigid-body"

dx = 2dy = 3

Y

X 0

1

1

2

2

3 4 5 6 7 8 9 10

3

4

5

6

dy

dxt

y

xv

y

xv ,

'

'',

2D Translation

3

3

6

5

(Points designate origin of object's local

coordinate system)

Page 8: C O M P U T E R G R A P H I C S Stuff CMSC 435 / 634 Transformations 1/29 Geometric Transformations Readings: Chapters 5-6.

C O M P U T E R G R A P H I C S

Stuff

CMSC 435 / 634 Transformations 8/29

• Component-wise scalar multiplication of vectors

v’ = Sv where

and

• Does not preserve lengths• Does not preserve angles (except when scaling is

uniform)

'

'',

y

xv

y

xv

y

x

s

sS

0

0

ysy

xsx

y

x

'

'

2

3

y

x

s

s

2D Scaling

Side effect: House shifts position relative to origin

1

2

1

3

2

6

2

9

Page 9: C O M P U T E R G R A P H I C S Stuff CMSC 435 / 634 Transformations 1/29 Geometric Transformations Readings: Chapters 5-6.

C O M P U T E R G R A P H I C S

Stuff

CMSC 435 / 634 Transformations 9/29

v’ = Rθ v where

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

A rotation by 0 angle, i.e. no rotation at all, gives us the identity matrix

• Preserves lengths in objects, and angles between parts of objects

• Rotation is rigid-body

cossin

sincosR

'

'',

y

xv

y

xv

6

2D Rotation

Side effect: House shifts position relative to origin

Rotate by about the

origin

Page 10: C O M P U T E R G R A P H I C S Stuff CMSC 435 / 634 Transformations 1/29 Geometric Transformations Readings: Chapters 5-6.

C O M P U T E R G R A P H I C S

Stuff

CMSC 435 / 634 Transformations 10/29

• Suppose object is not centered at origin and we want to scale and rotate it.

• Solution: move to the origin, scale and/or rotate in its local coordinate system, then move it back.

• This sequence suggests the need to compose successive transformations…

2D Rotation and Scale are Relative to Origin

Object’s local coordinate system origin

Page 11: C O M P U T E R G R A P H I C S Stuff CMSC 435 / 634 Transformations 1/29 Geometric Transformations Readings: Chapters 5-6.

C O M P U T E R G R A P H I C S

Stuff

CMSC 435 / 634 Transformations 11/29

• Translation, scaling and rotation are expressed as:

• Composition is difficult to express

– translation is not expressed as a matrix multiplication

• Homogeneous coordinates allows expression of all three transformations as 3x3 matrices for easy composition

• w is 1 for affine transformations in graphics

• Note:

This conversion does not transform p. It is only changing notation to show it can be viewed as a point on w = 1 hyperplane

translation:

scale:

rotation:

v’ = v + t

v’ = Sv

v’ = Rv

w

y

w

xPyxP

wwyxP

wwwywxPyxP

dd

h

hd

',

'),(

0),,','(

0),,,(),(

22

2

Homogenous Coordinates

y x, p y,1 x, p becomes

Page 12: C O M P U T E R G R A P H I C S Stuff CMSC 435 / 634 Transformations 1/29 Geometric Transformations Readings: Chapters 5-6.

C O M P U T E R G R A P H I C S

Stuff

CMSC 435 / 634 Transformations 12/29

• For points written in homogeneous coordinates,

translation, scaling and rotation relative to the origin are expressed homogeneously as:

1

y

x

2D Homogeneous CoordinateTransformations

100

00

00

, y

x

ss s

s

Syx vss yx

Sv ,'

vdd yxTv ,'

100

10

01

, y

x

dd d

d

Tyx

100

0cossin

0sincos

R vRv '

Page 13: C O M P U T E R G R A P H I C S Stuff CMSC 435 / 634 Transformations 1/29 Geometric Transformations Readings: Chapters 5-6.

C O M P U T E R G R A P H I C S

Stuff

CMSC 435 / 634 Transformations 13/29

• Avoiding unwanted translation when scaling or rotating an object not centered at origin:

– translate object to origin, perform scale or rotate, translate back.

• How would you scale the house by 2 in “its” y and rotate it through 90° ?

• Remember: matrix multiplication is not commutative! Hence order matters! (Refer to class website: resources/SIGGRAPH2001_courseNotes_source/transformation for camera transformation)

HdydxTRdydxTHdydxTRHdydxTHHouse ),()(),(),()(),()(

HSRH,SHHouse )2,1()2/()21()(

Matrix Compositions: Using Translation

Page 14: C O M P U T E R G R A P H I C S Stuff CMSC 435 / 634 Transformations 1/29 Geometric Transformations Readings: Chapters 5-6.

C O M P U T E R G R A P H I C S

Stuff

CMSC 435 / 634 Transformations 14/29

Matrix Multiplication is NOT Commutative

Translate by x=6, y=0 then rotate by 45º

Rotate by 45º then translate by

x=6, y=0

0 1

1

2

2

3 4 5 6 7 8 9 10

3

4

5

6

Y

X 0

1

1

2

2

3 4 5 6 7 8 9 10

3

4

5

6

Page 15: C O M P U T E R G R A P H I C S Stuff CMSC 435 / 634 Transformations 1/29 Geometric Transformations Readings: Chapters 5-6.

C O M P U T E R G R A P H I C S

Stuff

CMSC 435 / 634 Transformations 15/29

3D Transformations

Page 16: C O M P U T E R G R A P H I C S Stuff CMSC 435 / 634 Transformations 1/29 Geometric Transformations Readings: Chapters 5-6.

C O M P U T E R G R A P H I C S

Stuff

CMSC 435 / 634 Transformations 16/29

• Translation

• Scaling

(right-handed coordinate system)

1000

100

010

001

dz

dy

dx

1000

000

000

000

z

y

x

s

s

s

x

y

z

3D Basic Transformations (1/2)

Page 17: C O M P U T E R G R A P H I C S Stuff CMSC 435 / 634 Transformations 1/29 Geometric Transformations Readings: Chapters 5-6.

C O M P U T E R G R A P H I C S

Stuff

CMSC 435 / 634 Transformations 17/29

• Rotation about X-axis

(right-handed coordinate system)

1000

0cossin0

0sincos0

0001

1000

0cos0sin

0010

0sin0cos

1000

0100

00cossin

00sincos

• Rotation about Y-axis

• Rotation about Z-axis

3D Basic Transformations (2/2)

Page 18: C O M P U T E R G R A P H I C S Stuff CMSC 435 / 634 Transformations 1/29 Geometric Transformations Readings: Chapters 5-6.

C O M P U T E R G R A P H I C S

Stuff

CMSC 435 / 634 Transformations 18/29

More transformation matrices

Page 19: C O M P U T E R G R A P H I C S Stuff CMSC 435 / 634 Transformations 1/29 Geometric Transformations Readings: Chapters 5-6.

C O M P U T E R G R A P H I C S

Stuff

CMSC 435 / 634 Transformations 19/29

• “Skew” a scene to the side:

• Squares become parallelograms - x coordinates skew to right, y coordinates stay same

• Degree between axes becomes Ө

• Like pushing top of deck of cards to the side – each card shifts relative to the one below

• Notice that the base of the house (at y=1) remains horizontal, but shifts to the right.

Y

X 0

1

1

2

2

3 4 5 6 7 8 9 10

3

4

5

6

4

NB: A skew of 0 angle, i.e. no skew at all, gives us the identity matrix, as it should

Skew/Shear/Translate (1/2)

10tan

11

Skew

2D non-homogeneous

100

010

0tan

11

Skew

2D homogeneous

Page 20: C O M P U T E R G R A P H I C S Stuff CMSC 435 / 634 Transformations 1/29 Geometric Transformations Readings: Chapters 5-6.

C O M P U T E R G R A P H I C S

Stuff

CMSC 435 / 634 Transformations 20/29

Scene graph manipulation

Page 21: C O M P U T E R G R A P H I C S Stuff CMSC 435 / 634 Transformations 1/29 Geometric Transformations Readings: Chapters 5-6.

C O M P U T E R G R A P H I C S

Stuff

CMSC 435 / 634 Transformations 21/29

• 3D scenes are often stored in a scene graph: – Open Scene Graph– Sun’s Java3D™– X3D ™ (VRML ™ was a precursor to X3D)

• Typical scene graph format:– objects (cubes, sphere, cone, polyhedra etc.)

– stored as nodes (default: unit size at origin)– attributes (color, texture map, etc.) and

transformations are also nodes in scene graph (labeled edges on slide 2 are an abstraction)

Transformations in Scene Graphs (1/3)

Page 22: C O M P U T E R G R A P H I C S Stuff CMSC 435 / 634 Transformations 1/29 Geometric Transformations Readings: Chapters 5-6.

C O M P U T E R G R A P H I C S

Stuff

CMSC 435 / 634 Transformations 22/29

ROBOT

upper body lower body

head trunk arm

stanchion base

1. Leaves of tree are standard size object primitives

2. We transform them

3. To make sub-groups

4. Transform subgroups

5. To get final scene

Closer look at Scenegraph from slide 2 …

Transformations in Scene Graphs (2/3)

Page 23: C O M P U T E R G R A P H I C S Stuff CMSC 435 / 634 Transformations 1/29 Geometric Transformations Readings: Chapters 5-6.

C O M P U T E R G R A P H I C S

Stuff

CMSC 435 / 634 Transformations 23/29

• Transformations affect all child nodes

• Sub-trees can be reused, called group nodes– instances of a group can have different transformations

applied to them (e.g. group3 is used twice– once under t1 and once under t4)

– must be defined before use

object nodes (geometry)

transformation nodes

group nodes

group3

obj3 obj4

t5 t6

t4

root

t0

group1

t1 t2

obj1 group3

t3

group2

group3obj2

Transformations in Scene Graphs (3/3)

Page 24: C O M P U T E R G R A P H I C S Stuff CMSC 435 / 634 Transformations 1/29 Geometric Transformations Readings: Chapters 5-6.

C O M P U T E R G R A P H I C S

Stuff

CMSC 435 / 634 Transformations 24/29

• Transformation nodes contain at least a matrix that handles the transformation;

– may also contain individual transformation parameters

• To determine final composite transformation matrix (CTM) for object node:

– compose all parent transformations during prefix graph traversal

– exact detail of how this is done varies from package to package, so be careful

Composing Transformations in a Scene Graph (1/2)

Page 25: C O M P U T E R G R A P H I C S Stuff CMSC 435 / 634 Transformations 1/29 Geometric Transformations Readings: Chapters 5-6.

C O M P U T E R G R A P H I C S

Stuff

CMSC 435 / 634 Transformations 25/29

• Example:

- for o1, CTM = m1

- for o2, CTM = m2* m3

- for o3, CTM = m2* m4* m5

- for a vertex v in o3, position in the world (root) coordinate system is:

CTM v = (m2*m4*m5)v

g: group nodes

m: matrices of transform nodes

o: object nodes

m5

m1 m2

m3 m4

o1

o2

o3

g1

g2

g3

Composing Transformations in a Scene Graph (2/2)

Page 26: C O M P U T E R G R A P H I C S Stuff CMSC 435 / 634 Transformations 1/29 Geometric Transformations Readings: Chapters 5-6.

C O M P U T E R G R A P H I C S

Stuff

CMSC 435 / 634 Transformations 26/29

Exercises

Page 27: C O M P U T E R G R A P H I C S Stuff CMSC 435 / 634 Transformations 1/29 Geometric Transformations Readings: Chapters 5-6.

C O M P U T E R G R A P H I C S

Stuff

CMSC 435 / 634 Transformations 27/29

• Create a transform matrix that takes points in the rectangle [xl, xh] x [yl, yh] to the rectangle [xl’, xh’], [yl’, yh’] (Shirley Figure 6.18)

E1: Windowing transforms

=

Page 28: C O M P U T E R G R A P H I C S Stuff CMSC 435 / 634 Transformations 1/29 Geometric Transformations Readings: Chapters 5-6.

C O M P U T E R G R A P H I C S

Stuff

CMSC 435 / 634 Transformations 28/29

• Create a transform matrix that takes a point in the (X,Y) coordinate system to the point in the (U, V) coordinate system; and vice versa (Shirley Figure 6.20)

E2: Transformation between two coordinate systems

Page 29: C O M P U T E R G R A P H I C S Stuff CMSC 435 / 634 Transformations 1/29 Geometric Transformations Readings: Chapters 5-6.

C O M P U T E R G R A P H I C S

Stuff

CMSC 435 / 634 Transformations 29/29

Take-home exercise

E3: Rotation about arbitrary axis

Page 30: C O M P U T E R G R A P H I C S Stuff CMSC 435 / 634 Transformations 1/29 Geometric Transformations Readings: Chapters 5-6.

C O M P U T E R G R A P H I C S

Stuff

CMSC 435 / 634 Transformations 30/29

(right-handed coordinate system)

Rotation axis specification

Page 31: C O M P U T E R G R A P H I C S Stuff CMSC 435 / 634 Transformations 1/29 Geometric Transformations Readings: Chapters 5-6.

C O M P U T E R G R A P H I C S

Stuff

CMSC 435 / 634 Transformations 31/29

Rotation about arbitrary axis