• date post

25-May-2018
• Category

Documents

• view

212

0

Embed Size (px)

Transcript of Intro to Computer Graphics Transformations to Computer Graphics Copyright C. Gotsman, G. Elber, ......

• 1

CS5620

Intro to Computer Graphics

C. Gotsman, G. Elber, M. Ben-Chen

Computer Science Dept., Technion

Transformations

Page 1

Transformations

Specifying Complex Scenes

(x,y,z)

(0,0,0) 2

Specifying Complex Scenes

Absolute position is not very natural

Need a way to describe relative relationship:

The panel is on top of the roof, which is above the house

Work locally for every object and then combine

3

Transformations

Transforming an object = transforming all its points

For a polygon = transforming its vertices

4

Scaling

=

vector in plane

Scaling operator with parameters ( , ):

(0,0) (sx,sy)=(0.7, 0.7) (sx,sy)=(0.7, 1.0) (sx,sy)=(3.0, 1.5)

(,) =

5

Matrix Form

Convenient math for representing linear transformations

Composition multiplication

Inverse transformation matrix inverse

More on that later

6

• 2

CS5620

Intro to Computer Graphics

C. Gotsman, G. Elber, M. Ben-Chen

Computer Science Dept., Technion

Transformations

Page 2

Scaling Matrix Form

Independent in and

Non-uniform scaling is allowed

, = 00

=

7

Rotation

Polar form:

=

= cos sin

Rotate v anti-clockwise by to w:

() =

= cos + sin +

= cos sin

sin + cos

(0,0)

w

v

r

(0,0)

vy

vx

= -45o = -135o

8

Rotation

Matrix form:

= cos sin sin cos

Rotation operator with parameter :

=cos sin sin cos

9

Rotation Properties

is orthogonal

1

=

Rotation by is

=cos ( ) sin

sin () cos

=

cos sin sin cos

= 1

= cos sin sin cos

10

Translation

Translation operator with parameters (, ):

, = + +

Can we express in a matrix form?

(tx,ty)=(0.0, 1.0) (tx,ty)=(1.0, 0.0) (tx,ty)=(1.5, 0.3)

11

Homogeneous Coordinates in 2

Points of the form

=

Where we identify

for all nonzero

12

• 3

CS5620

Intro to Computer Graphics

C. Gotsman, G. Elber, M. Ben-Chen

Computer Science Dept., Technion

Transformations

Page 3

Conversion Formulae

From Euclidean to homogeneous

=

=

1

From homogeneous to Euclidean

=

=

13

Example

In homogeneous coordinates

221

=442

=110.5

14

Translation using Homogeneous Coordinates

, =1 0 0 1 0 0 1

1

=

= + +

1

15

Matrix Form

Why bother expressing transformations in matrix form?

16

Transformation Composition

What operation rotates by around =

?

Translate to origin

Rotate around origin by

Translate back

17

p p

17

Transformation Composition

1 performs one transformation

2 performs a second transformation

2 1 = 21 = 21

21 performs the composed transformation

18

• 4

CS5620

Intro to Computer Graphics

C. Gotsman, G. Elber, M. Ben-Chen

Computer Science Dept., Technion

Transformations

Page 4

Transformation Composition

, , =

1 0 0 1 0 0 1

cos sin 0sin cos 00 0 1

1 0 0 1 0 0 1

19

Transformation Quiz

What do these Euclidean transformations do?

1 00 1

,1 00 1

,1 00 1

1 01 1

,1 0 1

20

Transformation Quiz

And these homogeneous ones?

1

11

1

10.5

21

Transformation Quiz

Can one rotate in the plane by reflection?

How can one reflect through an arbitrary line in the plane?

22

Arbitrary Reflection

Shift by 0,

Rotate by

Reflect through

Rotate by

Shift by (0, )

0,

0,

23

= +

(, )

Rotate by Shear

Shear 1 01 1

,1 10 1

,1 0 1

,1 0 1

Rotation by 0

2 composition of 3 shears

cos sin sin cos

=1 0 1

1 0 1

1 0 1

=

=1 +

11 0 1

=

=1 + + +

+ 1

24

• 5

CS5620

Intro to Computer Graphics

C. Gotsman, G. Elber, M. Ben-Chen

Computer Science Dept., Technion

Transformations

Page 5

Rotate by Shear

cos sin sin cos

=1 + + +

+ 1

Solve for , , :

cos = 1 + = + 1 sin = = ( + + )

Solution: = sin , = = tan(/2)

cos sin sin cos

=1 tan 2 0 1

1 0sin 1

1 tan 2 0 1

When is this useful?

25

Rotate by Shear Image Rotation

26

http://www.datagenetics.com/blog/august32013/index.html

Rotate by Shear

Can we rotate with two (scaled) shears?

1 sin 0 cos

sec 0tan 1

=cos sin sin cos

What happens for

2 ?

27

Rotation Approximation

For small angles 0 we have: cos 1 and sin (Taylor expansion of sin/cos)

Can approximate:

= cos sin = sin + cos +

Examples (steps of ):

28

3D Transformations

All 2D transformations extend to 3D In homogeneous coordinates:

,, =

1

, ,,

11

1

1

=

cos sin sin cos

1

1

What is ?

?

29

3D Transformations

Questions (commutativity):

Scaling: Is S1S2 = S2S1?

Translation: Is T1T2 = T2T1?

Rotation: Is R1R2 = R2R1?

30

• 6

CS5620

Intro to Computer Graphics

C. Gotsman, G. Elber, M. Ben-Chen

Computer Science Dept., Technion

Transformations

Page 6

Rotation Non-Commutativity

31

3D Coordinate Systems

OpenGL

swap any two axes

or reverse any one axis

Example: Arbitrary Rotation

Problem: Given two orthonormal coordinate systems

, , and [, ,], find a transformation from one to the other.

33

Transformation matrix whose columns are , ,:

=

Proof:

=

100

=

=

Similarly () = and () = 34

Arbitrary Rotation (cont.)

Inverse (=transpose) transformation, 1, maps [, ,] to , , :

1 =

= 2

00

=100

=

35

3D Graphics Coordinate Systems

36

How can we view (draw) 3D objects on a 2D screen?

3D World space

3D Camera space

2D View space

3D Object space

• 7

CS5620

Intro to Computer Graphics

C. Gotsman, G. Elber, M. Ben-Chen

Computer Science Dept., Technion

Transformations

Page 7

Viewing Pipeline object - world positioning the object modeling transformation glTranslate(tx,ty,tz), glScale(sx,sy,sz), glRotate(ang, xa,ya,za)

world - camera positioning the camera viewing transformation gluLookAt(cx,cy,cz, ax,ay,az, ux,uy,uz)

camera view taking a picture projection transformation glFrustum(left, right, bottom, top, near,far)

view - screen displaying the image viewport transformation glViewport(llx,lly, width,height)

37

3D World space

3D Camera space

2D View space

3D Object space

Viewing Transformations World Camera/Eye

38

World space

Camera/eye space

Viewing Transformations Camera View

39

Camera space View space

Projection transformation

Projection Transformations

Canonical projection

Ignore coordinate, use , coordinates as view coordinates

40

1000

0000

0010

0001

1 0 0 0

0 0 0 0

0 0 1 0

0 0 0 1

0 0 0 0

0 1 0 0

0 0 1 0

0 0 0 1

Perspective Projector Lines

A line connecting a point in 3D with its 2D projection

41

object projection

plane

center of

projection

Pinhole Camera Model

42

• 8

CS5620

Intro to Computer Graphics

C. Gotsman, G. Elber, M. Ben-Chen

Computer Science Dept., Technion

Transformations

Page 8

Comparison

43

Vanishing Points where 3D parallel lines meet in 2D

under perspective

44 Triple point perspective

Perspective Projection

45

Projection plane

= Center of projection

=

,

=

=

/ , =

/

Viewing is from point at a finite distance

Without loss of generality: Viewpoint at origin Projection (viewing) plane is

=

Triangle similarity:

Perspective Projection Euclidean coordinates:

=

Homogeneous coordinates:

1

=

1

=

/

Matrix form:

1

=

1 0 0 00 1 0 00 0 1 0

0 01

0

1

=

/

is not injective & singular: det () = 0 46

=

=

,

=

47

www.pinterest.com/explore/forced-perspective/

Fun