computer graphics cs630 lecture 3 – transformation and coordinate systems

96
Computer Graphics Computer Graphics CS630 CS630 Lecture 3 – Transformation Lecture 3 – Transformation And Coordinate Systems And Coordinate Systems

Post on 21-Dec-2015

235 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Computer Graphics CS630 Lecture 3 – Transformation And Coordinate Systems

Computer GraphicsComputer GraphicsCS630CS630

Computer GraphicsComputer GraphicsCS630CS630

Lecture 3 – Transformation And Lecture 3 – Transformation And Coordinate SystemsCoordinate Systems

Page 2: Computer Graphics CS630 Lecture 3 – Transformation And Coordinate Systems

2

What is a Transformation?

• Maps points (x, y) in one coordinate system to points (x', y') in another coordinate system

x' = ax + by + c

y' = dx + ey + f

Page 3: Computer Graphics CS630 Lecture 3 – Transformation And Coordinate Systems

3

Transformations• Simple transformation

– Translation– Rotation– Scaling

Page 4: Computer Graphics CS630 Lecture 3 – Transformation And Coordinate Systems

4

Transformations• Deformable transformations

– Shearing– Tapering– Twisting– Etc..

• Issues– Can be combined– Are these operations invertible?

Page 5: Computer Graphics CS630 Lecture 3 – Transformation And Coordinate Systems

5

Transformations• Why use transformations?

– Position objects in a scene (modeling)– Change the shape of objects– Create multiple copies of objects– Projection for virtual cameras– Animations

Page 6: Computer Graphics CS630 Lecture 3 – Transformation And Coordinate Systems

6

Classes of Transformation

• Rigid-Body/ Euclidean transformation

• Similarity Transforms• Linear Transforms• Affine Transforms• Projective Transforms

Page 7: Computer Graphics CS630 Lecture 3 – Transformation And Coordinate Systems

7

Rigid-Body / Euclidean Transforms

• Preserves distances• Preserves angles

TranslationRotation

Rigid / Euclidean

Identity

Page 8: Computer Graphics CS630 Lecture 3 – Transformation And Coordinate Systems

8

How are Transforms Represented?

x' = ax + by + c

y' = dx + ey + f

x'

y'

a b

d e

c

f=

x

y+

p' = M p + t

Page 9: Computer Graphics CS630 Lecture 3 – Transformation And Coordinate Systems

9

Translation

z

y

x

z

y

x

t

t

t

= +

z

y

x

tttT zyx ),,(

z

y

x

z

y

x

t

t

t

= +

'

'

'

z

y

x

Page 10: Computer Graphics CS630 Lecture 3 – Transformation And Coordinate Systems

10

Properties of Translation

v=v)0,0,0(T

=v),,(),,( zyxzyx tttTsssT

=

=v),,(1zyx tttT

v),,(),,( zyxzyx tttTsssT v),,(),,( zyxzyx sssTtttT

v),,( zzyyxx tststsT

v),,( zyx tttT

Page 11: Computer Graphics CS630 Lecture 3 – Transformation And Coordinate Systems

11

Scaling

zs

ys

xs

z

y

x

z

y

x

'

'

'

z

y

x

zyx

s

s

s

sssS

00

00

00

),,(

Uniform scaling iff zyx sss

Page 12: Computer Graphics CS630 Lecture 3 – Transformation And Coordinate Systems

12

Rotations (2D)

sin

cos

ry

rx

cos)sin(sin)cos('

sin)sin(cos)cos('

rry

rrx

)sin('

)cos('

ry

rx

cossinsincos)sin(

sinsincoscos)cos(

cossin'

sincos'

yxy

yxx

yx,

',' yx

x

y

Page 13: Computer Graphics CS630 Lecture 3 – Transformation And Coordinate Systems

13

Rotations 2D• So in matrix notation

y

x

y

x

cossin

sincos'

'

Page 14: Computer Graphics CS630 Lecture 3 – Transformation And Coordinate Systems

14

Rotations (3D)

100

0cossin

0sincos

)(

cos0sin

010

sin0cos

)(

cossin0

sincos0

001

)(

z

y

x

R

R

R

Page 15: Computer Graphics CS630 Lecture 3 – Transformation And Coordinate Systems

15

Properties of RotationsIRa )0(

)()()()( aaaa RRRR

)()()( aaa RRR

)()()(1 Taaa RRR

)()()()( abba RRRR order matters!

Page 16: Computer Graphics CS630 Lecture 3 – Transformation And Coordinate Systems

16

Combining Translation & Rotation

)1,1(T

)45( R

)45( R

)1,1(T

Page 17: Computer Graphics CS630 Lecture 3 – Transformation And Coordinate Systems

17

Combining Translation & Rotation

Tvv'

RTR

TR

R

vv

vv

vv

''

)(''

'''

vv R'

TR

T

vv

vv

''

'''

Page 18: Computer Graphics CS630 Lecture 3 – Transformation And Coordinate Systems

18

Homogeneous Coordinates

• Add an extra dimension• in 2D, we use 3 x 3 matrices• In 3D, we use 4 x 4 matrices

• Each point has an extra value, w

x'

y'

z'

w'

=

x

y

z

w

a

e

i

m

b

f

j

n

c

g

k

o

d

h

l

p

p' = M p

Page 19: Computer Graphics CS630 Lecture 3 – Transformation And Coordinate Systems

19

Homogeneous Coordinates

• Most of the time w = 1, and we can ignore it

x'

y'

z'

1

=

x

y

z

1

a

e

i

0

b

f

j

0

c

g

k

0

d

h

l

1

Page 20: Computer Graphics CS630 Lecture 3 – Transformation And Coordinate Systems

20

Homogeneous Coordinates

z

y

x

w

Z

Y

X

can be represented as

wherew

Zz

w

Yy

w

Xx ,,

Page 21: Computer Graphics CS630 Lecture 3 – Transformation And Coordinate Systems

21

Translation Revisited

11000

100

010

001

),,(z

y

x

t

t

t

z

y

x

tttTz

y

x

zyx

Page 22: Computer Graphics CS630 Lecture 3 – Transformation And Coordinate Systems

22

Rotation & Scaling Revisited

11000

000

000

000

),,(z

y

x

s

s

s

z

y

x

sssSz

y

x

zyx

11000

0cossin0

0sincos0

0001

)(z

y

x

z

y

x

Rx

Page 23: Computer Graphics CS630 Lecture 3 – Transformation And Coordinate Systems

23

Combining Transformations

vv

vvvv

vvv

vv

M

TRSTRT

RSR

S

'''

''''''

'''

'

where TRSM

Page 24: Computer Graphics CS630 Lecture 3 – Transformation And Coordinate Systems

24

Transforming Tangents

t

qp

qp

qpt

qpt

M

M

MM

)(

'''

Page 25: Computer Graphics CS630 Lecture 3 – Transformation And Coordinate Systems

25

Transforming Normals

nnn

nn

nn

tntn

tn

tn

tn

TT

T

TT

TT

T

T

T

MM

M

M

M

M

11'

'

'

'

0'

0''

0

Page 26: Computer Graphics CS630 Lecture 3 – Transformation And Coordinate Systems

26

Surface Normal• Surface Normal: unit vector that is locally

perpendicular to the surface

Page 27: Computer Graphics CS630 Lecture 3 – Transformation And Coordinate Systems

27

Why is the Normal important?

• It's used for shading — makes things look 3D!

object color only Diffuse Shading

Page 28: Computer Graphics CS630 Lecture 3 – Transformation And Coordinate Systems

28

Visualization of Surface Normal

± x = Red± y = Green± z = Blue

Page 29: Computer Graphics CS630 Lecture 3 – Transformation And Coordinate Systems

29

How do we transform normals?

Object SpaceWorld Space

nOS

nWS

Page 30: Computer Graphics CS630 Lecture 3 – Transformation And Coordinate Systems

30

Transform the Normal like the Ray?

• translation?• rotation?• isotropic scale?• scale?• reflection?• shear?• perspective?

Page 31: Computer Graphics CS630 Lecture 3 – Transformation And Coordinate Systems

31

More Normal Visualizations

Incorrect Normal Transformation Correct Normal Transformation

Page 32: Computer Graphics CS630 Lecture 3 – Transformation And Coordinate Systems

32

Transforming Normals

nnn

nn

nn

tntn

tn

tn

tn

TT

T

TT

TT

T

T

T

MM

M

M

M

M

11'

'

'

'

0'

0''

0

Page 33: Computer Graphics CS630 Lecture 3 – Transformation And Coordinate Systems

33

Rotations about an arbitrary axis

Rotate by around a unit axis r

r

Page 34: Computer Graphics CS630 Lecture 3 – Transformation And Coordinate Systems

34

An Alternative View• We can view the rotation around an

arbitrary axis as a set of simpler steps

• We know how to rotate and translate around the world coordinate system

• Can we use this knowledge to perform the rotation?

Page 35: Computer Graphics CS630 Lecture 3 – Transformation And Coordinate Systems

35

Rotation about an arbitrary axis

• Translate the space so that the origin of the unit vector is on the world origin

• Rotate such that the extremity of the vector now lies in the xz plane (x-axis rotation)

• Rotate such that the point lies in the z-axis (y-axis rotation)

• Perform the rotation around the z-axis• Undo the previous transformations

Page 36: Computer Graphics CS630 Lecture 3 – Transformation And Coordinate Systems

36

Rotation about an arbitrary axis

• Step 1Rotate x-axis

x

y

z

(a,b,c)

x

(a’,b’,c’)

Page 37: Computer Graphics CS630 Lecture 3 – Transformation And Coordinate Systems

37

Closer Look at Y-Z Plane

• Need to rotate degrees around the x-axis

y

z

Page 38: Computer Graphics CS630 Lecture 3 – Transformation And Coordinate Systems

38

Equations for

||)1,0,0(||||),,0(||

)1,0,0(),,0()cos(

||),,0(||||)1,0,0(||

||),,0()1,0,0(||)sin(

cb

cb

cb

cb

Page 39: Computer Graphics CS630 Lecture 3 – Transformation And Coordinate Systems

39

Rotation about the Y-axis

• Using the same analysis as before, we need to rotate degrees around the Y-axis

y

z

x

(a’,b’,c’)=Rx () (a,b,c)T

Page 40: Computer Graphics CS630 Lecture 3 – Transformation And Coordinate Systems

40

Equations for

||)1,0,0(||||)',','(||

)1,0,0()',','()cos(

||)',','(||||)1,0,0(||

||)',','()1,0,0(||)sin(

cba

cba

cba

cba

Page 41: Computer Graphics CS630 Lecture 3 – Transformation And Coordinate Systems

41

Rotation about the Z-axis

• Now, it is aligned with the Z-axis, thus we can simply rotate degrees around the Z-axis.

• Then undo all the transformations we just did

Page 42: Computer Graphics CS630 Lecture 3 – Transformation And Coordinate Systems

42

Equation summary

c

b

a

TRRRRRT

c

b

a

rot xyzyxaxis )()()()()(

'

'

'

)( 111

Page 43: Computer Graphics CS630 Lecture 3 – Transformation And Coordinate Systems

43

Deformations

Transformations that do not preserve shape Non-uniform scaling Shearing Tapering Twisting Bending

Page 44: Computer Graphics CS630 Lecture 3 – Transformation And Coordinate Systems

44

Shearing

11000

01

01

01

1

'

'

'

z

y

x

ss

ss

ss

z

y

x

zyzx

yzyx

xzxy

0

0

0

1

zyzx

yzyx

xz

xy

ss

ss

s

s

x

y

x

y

Page 45: Computer Graphics CS630 Lecture 3 – Transformation And Coordinate Systems

45

Tapering

11000

0)(00

00)(0

0001

1

'

'

'

z

y

x

xf

xf

z

y

x

Page 46: Computer Graphics CS630 Lecture 3 – Transformation And Coordinate Systems

46

Twisting

11000

0))(cos(0))(sin(

0010

0))(sin(0))(cos(

1

'

'

'

z

y

x

yy

yy

z

y

x

Page 47: Computer Graphics CS630 Lecture 3 – Transformation And Coordinate Systems

47

Bending

11000

0)()(0

0)()(0

0001

1

'

'

'

z

y

x

ykyh

ygyf

z

y

x

Page 48: Computer Graphics CS630 Lecture 3 – Transformation And Coordinate Systems

48

Quick Recap• Computer Graphics is using a

computer to generate an image from a representation.

Model Imagecomputer

Page 49: Computer Graphics CS630 Lecture 3 – Transformation And Coordinate Systems

49

Modeling• What we have been studying so

far is the mathematics behind the creation and manipulation of the 3D representation of the object.

Model Imagecomputer

Page 50: Computer Graphics CS630 Lecture 3 – Transformation And Coordinate Systems

50

What have we seen so far?

• Basic representations (point, vector)• Basic operations on points and vectors

(dot product, cross products, etc.)• Transformation – manipulative

operators on the basic representation (translate, rotate, deformations) – 4x4 matrices to “encode” all these.

Page 51: Computer Graphics CS630 Lecture 3 – Transformation And Coordinate Systems

51

Why do we need this?• In order to generate a picture from

a model, we need to be able to not only specify a model (representation) but also manipulate the model in order to create more interesting images.

Page 52: Computer Graphics CS630 Lecture 3 – Transformation And Coordinate Systems

52

Overview• The next set of slides will deal with

the other half of the process. • From a model, how do we

generate an image

Model Imagecomputer

Page 53: Computer Graphics CS630 Lecture 3 – Transformation And Coordinate Systems

53

Scene Description

Scene

LightsCamera ObjectsMaterialsBackground

Page 54: Computer Graphics CS630 Lecture 3 – Transformation And Coordinate Systems

54

Graphics Pipeline

Page 55: Computer Graphics CS630 Lecture 3 – Transformation And Coordinate Systems

55

Graphics Pipeline

• Modeling transforms orient the models within a common coordinate frame (world space)

Page 56: Computer Graphics CS630 Lecture 3 – Transformation And Coordinate Systems

56

Graphics Pipeline

Page 57: Computer Graphics CS630 Lecture 3 – Transformation And Coordinate Systems

57

Graphics Pipeline

• Maps world space to eye space

• Viewing position is transformed to origin & direction is oriented along some axis (usually z)

Page 58: Computer Graphics CS630 Lecture 3 – Transformation And Coordinate Systems

58

Graphics Pipeline

• Transform to Normalized Device Coordinates (NDC)

• Portions of the object outside the view volume (view frustum) are removed

Page 59: Computer Graphics CS630 Lecture 3 – Transformation And Coordinate Systems

59

Graphics Pipeline

• The objects are projected to the 2D image place (screen space)

Page 60: Computer Graphics CS630 Lecture 3 – Transformation And Coordinate Systems

60

Graphics Pipeline

Page 61: Computer Graphics CS630 Lecture 3 – Transformation And Coordinate Systems

61

Graphics Pipeline

• Z-buffer - Each pixel remembers the closest object (depth buffer)

Page 62: Computer Graphics CS630 Lecture 3 – Transformation And Coordinate Systems

62

Graphics Pipeline• Almost every step in the graphics

pipeline involves a change of coordinate system. Transformations are central to understanding 3D computer graphics.

Page 63: Computer Graphics CS630 Lecture 3 – Transformation And Coordinate Systems

63

IntuitivelyObjectSpace

WorldSpace

CameraSpace +Projection+NDC

Rasterization

Page 64: Computer Graphics CS630 Lecture 3 – Transformation And Coordinate Systems

64

Coordinate Systems Object coordinates World coordinates Camera coordinates Normalized device coordinates Window coordinates

Page 65: Computer Graphics CS630 Lecture 3 – Transformation And Coordinate Systems

65

Object CoordinatesConvenient place to model the

object

O

Page 66: Computer Graphics CS630 Lecture 3 – Transformation And Coordinate Systems

66

World CoordinatesCommon

coordinates for the scene

O

O

W

TSRM wo

Page 67: Computer Graphics CS630 Lecture 3 – Transformation And Coordinate Systems

67

Positioning Synthetic Camera

What are our “degrees of freedom” in camera positioning?To achieve effective visual simulation, we want:1) the eye point to be in proximity of modeled scene2) the view to be directed toward region of interest, and3) the image plane to have a reasonable “twist”

Page 68: Computer Graphics CS630 Lecture 3 – Transformation And Coordinate Systems

68

Eye Coordinates

Eyepoint at originu axis toward “right” of image planev axis toward “top” of image planeview direction along negative n axis

Page 69: Computer Graphics CS630 Lecture 3 – Transformation And Coordinate Systems

69

Transformation to Eye Coordinates

Our task: construct the transformation M that re-expresses world coordinates in the viewer frame

Page 70: Computer Graphics CS630 Lecture 3 – Transformation And Coordinate Systems

70

Machinery: Changing Orthobases

Suppose you are given an orthobasis u, v, nWhat is the action of the matrix M withrows u, v, and n as below?

Page 71: Computer Graphics CS630 Lecture 3 – Transformation And Coordinate Systems

71

Applying M to u, v, n

Two equally valid interpretations, depending on reference frame:1: Think of uvn basis as a rigid object in a fixed world spaceThen M “rotates” uvn basis into xyz basis2: Think of a fixed axis triad, with “labels” from xyz spaceThen M “reexpresses” an xyz point p in uvn coords!It is this second interpretation that we use todayto “relabel” world-space geometry with eye space coordinates

Page 72: Computer Graphics CS630 Lecture 3 – Transformation And Coordinate Systems

72

Positioning Synthetic Camera

Given eyepoint e, basis ˆu, ˆv, ˆnDeduce M that expresses world in eye coordinates:Overlay origins, then change bases:

Page 73: Computer Graphics CS630 Lecture 3 – Transformation And Coordinate Systems

73

Positioning Synthetic Camera

Check: does M re-express world geometry in eye coordinates?

Page 74: Computer Graphics CS630 Lecture 3 – Transformation And Coordinate Systems

74

Positioning Synthetic Camera

Camera specification must include:World-space eye position eWorld-space “lookat direction” -n

Are e and -n enough to determine the camera DOFs (degrees of freedom)?

Page 75: Computer Graphics CS630 Lecture 3 – Transformation And Coordinate Systems

75

Positioning Synthetic Camera

Are e and -n enough to determine the camera DOFs?No. Note that we were not given u and v!(Why not simply require the user to specify them?)

We must also determine u and v, i.e., camera “twist” about n.Typically done by specification of a world-space “up vector”provided by user interface, e.g., using gluLookat(e, c, up)“Twist” constraint: Align v with world up vector (How?)

Page 76: Computer Graphics CS630 Lecture 3 – Transformation And Coordinate Systems

76

Positioning Synthetic Camera

Page 77: Computer Graphics CS630 Lecture 3 – Transformation And Coordinate Systems

77

Where are we?

Page 78: Computer Graphics CS630 Lecture 3 – Transformation And Coordinate Systems

78

What is Projection?

Any operation that reduces dimension (e.g., 3D to 2D)

Orthographic ProjectionPerspective Projection

Page 79: Computer Graphics CS630 Lecture 3 – Transformation And Coordinate Systems

79

Orthographic Projection• focal point at infinity • rays are parallel and orthogonal to the image

plane

Image

World

F

F

Image

World

I

W

Page 80: Computer Graphics CS630 Lecture 3 – Transformation And Coordinate Systems

80

Comparison

Page 81: Computer Graphics CS630 Lecture 3 – Transformation And Coordinate Systems

81

Simple Perspective Camera

• camera looks along z-axis• focal point is the origin• image plane is parallel to xy-plane at

distance d• d is call focal length

Page 82: Computer Graphics CS630 Lecture 3 – Transformation And Coordinate Systems

82

Similar TrianglesY

Z

[0, d][0, 0]

[Y, Z]

[(d/Z)Y, d]

• Similar situation with x-coordinate• Similar Triangles:

point [x,y,z] projects to [(d/z)x, (d/z)y, d]

Page 83: Computer Graphics CS630 Lecture 3 – Transformation And Coordinate Systems

83

Projection Matrix Projection using homogeneous coordinates:

– transform [x, y, z] to [(d/z)x, (d/z)y, d]

•2-D image point:•discard third coordinate•apply viewport transformation to

obtain physical pixel coordinates

d 0 0 0

0 d 0 0

0 0 d 0

0 0 1 0

x

y

z

1

dx dy dz z d

zx

d

zy d

Divide by 4th coordinate

(the “w” coordinate)

Page 84: Computer Graphics CS630 Lecture 3 – Transformation And Coordinate Systems

84

Perspective Projection

Page 85: Computer Graphics CS630 Lecture 3 – Transformation And Coordinate Systems

85

Perspective Projection

z = 0 not allowed (what happens to points on plane z = 0?)Operation well-defined for all other points

Page 86: Computer Graphics CS630 Lecture 3 – Transformation And Coordinate Systems

86

Perspective Projection

Matrix formulation using “homogeneous 4-vectors”:

Finally, recover projected point using homogenous convention:Divide by 4th element to convert 4-vector to 3-vector:

Page 87: Computer Graphics CS630 Lecture 3 – Transformation And Coordinate Systems

87

Camera CoordinatesCoordinate system with the camera

in a convenient pose

1000

nr

vr

ur

zyx

zyx

zyx

cw nnn

vvv

uuu

Mu

v

n

x

y

z

Page 88: Computer Graphics CS630 Lecture 3 – Transformation And Coordinate Systems

88

View Volume and Normalized Device

Coordinates

Page 89: Computer Graphics CS630 Lecture 3 – Transformation And Coordinate Systems

89

Normalized Device Coordinates

Device independent coordinatesVisible coordinate usually range from:

11

11

11

z

y

x

Page 90: Computer Graphics CS630 Lecture 3 – Transformation And Coordinate Systems

90

Perspective ProjectionTaking the camera coordinates to

NDC

z

x

near

Page 91: Computer Graphics CS630 Lecture 3 – Transformation And Coordinate Systems

91

Perspective Projection

z

x

near'p

p

z

xnearx

z

x

near

x

'

'

Page 92: Computer Graphics CS630 Lecture 3 – Transformation And Coordinate Systems

92

Perspective Projection + NDC

0100

200

02

0

002

nearfar

nearfar

nearfar

nearfarbottomtop

bottomtop

bottomtop

nearleftright

leftright

leftright

near

M pc

Page 93: Computer Graphics CS630 Lecture 3 – Transformation And Coordinate Systems

93

Window CoordinatesAdjusting the NDC to fit the window

),( 00 yx is the lower left of the window

Page 94: Computer Graphics CS630 Lecture 3 – Transformation And Coordinate Systems

94

Window CoordinatesAdjusting the NDC to fit the window

0

0

2)1(

2)1(

yheight

yy

xwidth

xx

ndw

ndw

),( 00 yx is the lower left of the window

width

height

Page 95: Computer Graphics CS630 Lecture 3 – Transformation And Coordinate Systems

95

Window Coordinates

1000

01002

02

0

200

2

0

0

_

heighty

height

widthx

width

M pw

Page 96: Computer Graphics CS630 Lecture 3 – Transformation And Coordinate Systems

96

Summary : Object Coordinate to Device

Coordinate• Take your representation (points) and transform it

from Object Space to World Space (Mwo)• Take your World Space point and transform it to

Camera Space (Mcw)• Perform the remapping and projection onto the

image plane in Normalized Device Coordinates (Mw_p Mpc)

• Perform this set of transformations on each point of the polygonal object (M= Mw_pMpcMcwMwo)