CSE4203: Computer Graphics Chapter 6 (part - A ...

51
CSE4203: Computer Graphics Chapter – 6 (part - A) Transformation Matrices Mohammad Imrul Jubair M. I. Jubair 1

Transcript of CSE4203: Computer Graphics Chapter 6 (part - A ...

Page 1: CSE4203: Computer Graphics Chapter 6 (part - A ...

CSE4203: Computer Graphics

Chapter – 6 (part - A)

Transformation Matrices

Mohammad Imrul Jubair

M. I. Jubair 1

Page 2: CSE4203: Computer Graphics Chapter 6 (part - A ...

Outline

– Transformation

– Linear Transformation

• Scaling

• Shearing

• Rotation

– Composite Transformation

M. I. Jubair 2

Page 3: CSE4203: Computer Graphics Chapter 6 (part - A ...

Credit

M. I. Jubair 3

CS4620: Introduction to Computer GraphicsCornell UniversityInstructor: Steve Marschnerhttp://www.cs.cornell.edu/courses/cs4620/2019fa/

Page 4: CSE4203: Computer Graphics Chapter 6 (part - A ...

2D Linear Transformations (1/1)

Linear Transformation: Operation of taking a vector and produces another vector by a simple matrix multiplication.

M. I. Jubair 4

Credit: Fundamentals of Computer Graphics 3rd Edition by Peter Shirley, Steve Marschner | http://www.cs.cornell.edu/courses/cs4620/2019fa/

Page 5: CSE4203: Computer Graphics Chapter 6 (part - A ...

Scaling (1/6)

• The most basic transform is a scale along the coordinate axes.

M. I. Jubair 5

Credit: Fundamentals of Computer Graphics 3rd Edition by Peter Shirley, Steve Marschner | http://www.cs.cornell.edu/courses/cs4620/2019fa/

Page 6: CSE4203: Computer Graphics Chapter 6 (part - A ...

Scaling (2/6)

• The most basic transform is a scale along the coordinate axes.

The matrix does to a vector with Cartesian components (x, y):

M. I. Jubair 6

Credit: Fundamentals of Computer Graphics 3rd Edition by Peter Shirley, Steve Marschner | http://www.cs.cornell.edu/courses/cs4620/2019fa/

Page 7: CSE4203: Computer Graphics Chapter 6 (part - A ...

Scaling (3/6)

M. I. Jubair 7

Credit: Fundamentals of Computer Graphics 3rd Edition by Peter Shirley, Steve Marschner | http://www.cs.cornell.edu/courses/cs4620/2019fa/

(0,0)

(4,0) (4,4)

(4,0)

Page 8: CSE4203: Computer Graphics Chapter 6 (part - A ...

Scaling (4/6)

M. I. Jubair 8

Credit: Fundamentals of Computer Graphics 3rd Edition by Peter Shirley, Steve Marschner | http://www.cs.cornell.edu/courses/cs4620/2019fa/

(0,0)

(4,0) (4,4)

(4,0) (0,0)

(2,0) (2,2)

(2,0)

Page 9: CSE4203: Computer Graphics Chapter 6 (part - A ...

Scaling (5/6)

M. I. Jubair 9

Credit: Fundamentals of Computer Graphics 3rd Edition by Peter Shirley, Steve Marschner | http://www.cs.cornell.edu/courses/cs4620/2019fa/

Page 10: CSE4203: Computer Graphics Chapter 6 (part - A ...

Scaling (6/6)

M. I. Jubair 10

Credit: Fundamentals of Computer Graphics 3rd Edition by Peter Shirley, Steve Marschner | http://www.cs.cornell.edu/courses/cs4620/2019fa/

Page 11: CSE4203: Computer Graphics Chapter 6 (part - A ...

Scaling (6/6)

M. I. Jubair 11

b

c

a

Scale (2,2)

Page 12: CSE4203: Computer Graphics Chapter 6 (part - A ...

Shearing (1/5)

• A shear is something that pushes things sideways

M. I. Jubair 12

Credit: Fundamentals of Computer Graphics 3rd Edition by Peter Shirley, Steve Marschner | http://www.cs.cornell.edu/courses/cs4620/2019fa/

Page 13: CSE4203: Computer Graphics Chapter 6 (part - A ...

Shearing (2/5)

• A shear is something that pushes things sideways

M. I. Jubair 13

Source: https://www.tutorialspoint.com/computer_graphics/2d_transformation.htm

Page 14: CSE4203: Computer Graphics Chapter 6 (part - A ...

Shearing (3/5)

M. I. Jubair 14

Page 15: CSE4203: Computer Graphics Chapter 6 (part - A ...

Shearing (4/5)

M. I. Jubair 15

Credit: Fundamentals of Computer Graphics 3rd Edition by Peter Shirley, Steve Marschner | http://www.cs.cornell.edu/courses/cs4620/2019fa/

Page 16: CSE4203: Computer Graphics Chapter 6 (part - A ...

Shearing (5/5)

M. I. Jubair 16

Credit: Fundamentals of Computer Graphics 3rd Edition by Peter Shirley, Steve Marschner | http://www.cs.cornell.edu/courses/cs4620/2019fa/

Page 17: CSE4203: Computer Graphics Chapter 6 (part - A ...

Rotation (1/11)

M. I. Jubair 17Credit: Fundamentals of Computer Graphics 3rd Edition by Peter Shirley, Steve Marschner | http://www.cs.cornell.edu/courses/cs4620/2019fa/

Page 18: CSE4203: Computer Graphics Chapter 6 (part - A ...

Rotation (2/11)

M. I. Jubair 18Credit: Fundamentals of Computer Graphics 3rd Edition by Peter Shirley, Steve Marschner | http://www.cs.cornell.edu/courses/cs4620/2019fa/

Page 19: CSE4203: Computer Graphics Chapter 6 (part - A ...

Rotation (3/11)

M. I. Jubair 19Credit: Fundamentals of Computer Graphics 3rd Edition by Peter Shirley, Steve Marschner | http://www.cs.cornell.edu/courses/cs4620/2019fa/

Page 20: CSE4203: Computer Graphics Chapter 6 (part - A ...

Rotation (4/11)

M. I. Jubair 20Credit: Fundamentals of Computer Graphics 3rd Edition by Peter Shirley, Steve Marschner | http://www.cs.cornell.edu/courses/cs4620/2019fa/

Page 21: CSE4203: Computer Graphics Chapter 6 (part - A ...

Rotation (5/11)

M. I. Jubair 21Credit: Fundamentals of Computer Graphics 3rd Edition by Peter Shirley, Steve Marschner | http://www.cs.cornell.edu/courses/cs4620/2019fa/

Page 22: CSE4203: Computer Graphics Chapter 6 (part - A ...

Rotation (6/11)

M. I. Jubair 22Credit: Fundamentals of Computer Graphics 3rd Edition by Peter Shirley, Steve Marschner | http://www.cs.cornell.edu/courses/cs4620/2019fa/

Page 23: CSE4203: Computer Graphics Chapter 6 (part - A ...

Rotation (7/11)

M. I. Jubair 23

Credit: Fundamentals of Computer Graphics 3rd Edition by Peter Shirley, Steve Marschner | http://www.cs.cornell.edu/courses/cs4620/2019fa/

Page 24: CSE4203: Computer Graphics Chapter 6 (part - A ...

Rotation (8/11)

M. I. Jubair 24

Credit: Fundamentals of Computer Graphics 3rd Edition by Peter Shirley, Steve Marschner | http://www.cs.cornell.edu/courses/cs4620/2019fa/

Page 25: CSE4203: Computer Graphics Chapter 6 (part - A ...

Rotation (9/11)

M. I. Jubair 25

Q: What about – ve angle?

Credit: Fundamentals of Computer Graphics 3rd Edition by Peter Shirley, Steve Marschner | http://www.cs.cornell.edu/courses/cs4620/2019fa/

Page 26: CSE4203: Computer Graphics Chapter 6 (part - A ...

Rotation (10/11)

M. I. Jubair 26

Rotate(90)

b

c

a

Page 27: CSE4203: Computer Graphics Chapter 6 (part - A ...

Rotation (11/11)

M. I. Jubair 27

Rotate(90)

a' b

c

ac'

d'

Page 28: CSE4203: Computer Graphics Chapter 6 (part - A ...

Reflection (1/5)

M. I. Jubair 28

Credit: Fundamentals of Computer Graphics 3rd Edition by Peter Shirley, Steve Marschner | http://www.cs.cornell.edu/courses/cs4620/2019fa/

Page 29: CSE4203: Computer Graphics Chapter 6 (part - A ...

Reflection (2/5)

M. I. Jubair 29

Credit: Fundamentals of Computer Graphics 3rd Edition by Peter Shirley, Steve Marschner | http://www.cs.cornell.edu/courses/cs4620/2019fa/

Page 30: CSE4203: Computer Graphics Chapter 6 (part - A ...

Reflection (3/5)

M. I. Jubair 30

Credit: Fundamentals of Computer Graphics 3rd Edition by Peter Shirley, Steve Marschner | http://www.cs.cornell.edu/courses/cs4620/2019fa/

Page 31: CSE4203: Computer Graphics Chapter 6 (part - A ...

Reflection (5/5)

M. I. Jubair 31

Credit: Fundamentals of Computer Graphics 3rd Edition by Peter Shirley, Steve Marschner | http://www.cs.cornell.edu/courses/cs4620/2019fa/

Page 32: CSE4203: Computer Graphics Chapter 6 (part - A ...

Affine transformation (1/2)

M. I. Jubair 32

Source: https://www.graphicsmill.com/docs/gm/affine-and-projective-transformations.htm | https://en.wikipedia.org/wiki/Affine_transformation

• Maps points to points, lines to lines, planes to planes.• Preserves the ratio of lengths of parallel line segments.• Sets of parallel lines remain parallel.• Does not necessarily preserve angles between lines or

distances between points.

Page 33: CSE4203: Computer Graphics Chapter 6 (part - A ...

Affine transformation (2/2)

M. I. Jubair 33

Source: https://www.graphicsmill.com/docs/gm/affine-and-projective-transformations.htm | https://en.wikipedia.org/wiki/Affine_transformation

• Maps points to points, lines to lines, planes to planes.• Preserves the ratio of lengths of parallel line segments.• Sets of parallel lines remain parallel.• Does not necessarily preserve angles between lines or

distances between points.

Page 34: CSE4203: Computer Graphics Chapter 6 (part - A ...

Composition of Transformations (1/11)

M. I. Jubair 34

Credit: Fundamentals of Computer Graphics 3rd Edition by Peter Shirley, Steve Marschner | http://www.cs.cornell.edu/courses/cs4620/2019fa/

Page 35: CSE4203: Computer Graphics Chapter 6 (part - A ...

Composition of Transformations (2/11)

• Apply more than one transformation:

– i.e., for a 2D point v1 we might want to –

1. first apply a scale S

2. then a rotation R.

• This would be done in two steps:

1. first, v2 = S v1

2. then,v3 = R v2.

M. I. Jubair 35

Credit: Fundamentals of Computer Graphics 3rd Edition by Peter Shirley, Steve Marschner | http://www.cs.cornell.edu/courses/cs4620/2019fa/

Page 36: CSE4203: Computer Graphics Chapter 6 (part - A ...

Composition of Transformations (3/11)

Therefore –

1. v2 = S v1

2. v3 = R v2

3. v3 = R (Sv1)

4. v3 = (RS) v1 [matrix multiplication is associative]

5. v3 = Mv1 [Where M=RS]

M. I. Jubair 36

Credit: Fundamentals of Computer Graphics 3rd Edition by Peter Shirley, Steve Marschner | http://www.cs.cornell.edu/courses/cs4620/2019fa/

Page 37: CSE4203: Computer Graphics Chapter 6 (part - A ...

Composition of Transformations (4/11)

vout = M vin

[Where M = R S]

• We can represent the effects of transforming a vector by two matrices in sequence using a single matrix of the same size

– which we can compute by multiplying the two matrices: M = RS

M. I. Jubair 37

Credit: Fundamentals of Computer Graphics 3rd Edition by Peter Shirley, Steve Marschner | http://www.cs.cornell.edu/courses/cs4620/2019fa/

Page 38: CSE4203: Computer Graphics Chapter 6 (part - A ...

Composition of Transformations (6/11)

M. I. Jubair 38

R

S

Credit: Fundamentals of Computer Graphics 3rd Edition by Peter Shirley, Steve Marschner | http://www.cs.cornell.edu/courses/cs4620/2019fa/

Page 39: CSE4203: Computer Graphics Chapter 6 (part - A ...

Composition of Transformations (7/11)

M. I. Jubair 39

R

S

M

RS = M

Credit: Fundamentals of Computer Graphics 3rd Edition by Peter Shirley, Steve Marschner | http://www.cs.cornell.edu/courses/cs4620/2019fa/

Page 40: CSE4203: Computer Graphics Chapter 6 (part - A ...

Composition of Transformations (8/11)

M. I. Jubair 40

• It is very important to remember that these transforms are applied :

– from the right side first.

– So the matrix M= RS

• first applies S and then R.

Credit: Fundamentals of Computer Graphics 3rd Edition by Peter Shirley, Steve Marschner | http://www.cs.cornell.edu/courses/cs4620/2019fa/

Page 41: CSE4203: Computer Graphics Chapter 6 (part - A ...

Composition of Transformations (9/11)

M. I. Jubair 41

M= RS

Credit: Fundamentals of Computer Graphics 3rd Edition by Peter Shirley, Steve Marschner | http://www.cs.cornell.edu/courses/cs4620/2019fa/

Page 42: CSE4203: Computer Graphics Chapter 6 (part - A ...

Composition of Transformations (10/11)

M. I. Jubair 42

M= RS M = ?

Credit: Fundamentals of Computer Graphics 3rd Edition by Peter Shirley, Steve Marschner | http://www.cs.cornell.edu/courses/cs4620/2019fa/

Page 43: CSE4203: Computer Graphics Chapter 6 (part - A ...

M. I. Jubair 43

M= RS M=

Q: What about more than two

transformations: T1→T2→T3…. →Tn.

Composition of Transformations (11/11)

Credit: Fundamentals of Computer Graphics 3rd Edition by Peter Shirley, Steve Marschner | http://www.cs.cornell.edu/courses/cs4620/2019fa/

Page 44: CSE4203: Computer Graphics Chapter 6 (part - A ...

Practice Problem - 1

M. I. Jubair 44

• Stretch the clock by 50% along one of its diagonals

– so that 8:00 through 1:00 move to the northwest and 2:00 through 7:00 move to the southeast.

a

b

c

o

a b

co

Credit: Fundamentals of Computer Graphics 3rd Edition by Peter Shirley, Steve Marschner | http://www.cs.cornell.edu/courses/cs4620/2019fa/

Page 45: CSE4203: Computer Graphics Chapter 6 (part - A ...

Practice Problem – 1 (Sol.)

M. I. Jubair 45

a b

co

Page 46: CSE4203: Computer Graphics Chapter 6 (part - A ...

Practice Problem – 1 (Sol.)

M. I. Jubair 46

a'

b'

c'

o'

rotate(?)

Page 47: CSE4203: Computer Graphics Chapter 6 (part - A ...

Practice Problem – 1 (Sol.)

M. I. Jubair 47

scale(?)

a''

b''

c''

o''

Page 48: CSE4203: Computer Graphics Chapter 6 (part - A ...

Practice Problem – 1 (Sol.)

M. I. Jubair 48

a'''

b'''

c'''

o'''

rotate(?)

Page 49: CSE4203: Computer Graphics Chapter 6 (part - A ...

Practice Problem – 1 (Sol.)

M. I. Jubair 49

• rotate(45◦) → scale(1.5, 1) → rotate(− 45◦).

– Q: Draw the steps

• M = R(−45◦) S(1.5, 1) R(45◦)

= RT S R

– Q: Calculate the matrix

Page 50: CSE4203: Computer Graphics Chapter 6 (part - A ...

Practice Problem – 2

• Reflect the clock along a line goes through origin:

y = mx + c

M. I. Jubair 50

w.r.t y-axis w.r.t arbitrary line

Page 51: CSE4203: Computer Graphics Chapter 6 (part - A ...

Thank you

M. I. Jubair 51