CSE4203: Computer Graphics Chapter 6 (part - A ...
Transcript of CSE4203: Computer Graphics Chapter 6 (part - A ...
CSE4203: Computer Graphics
Chapter – 6 (part - A)
Transformation Matrices
Mohammad Imrul Jubair
M. I. Jubair 1
Outline
– Transformation
– Linear Transformation
• Scaling
• Shearing
• Rotation
– Composite Transformation
M. I. Jubair 2
Credit
M. I. Jubair 3
CS4620: Introduction to Computer GraphicsCornell UniversityInstructor: Steve Marschnerhttp://www.cs.cornell.edu/courses/cs4620/2019fa/
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/
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/
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/
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)
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)
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/
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/
Scaling (6/6)
M. I. Jubair 11
b
c
a
Scale (2,2)
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/
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
Shearing (3/5)
M. I. Jubair 14
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/
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/
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/
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/
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/
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/
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/
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/
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/
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/
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/
Rotation (10/11)
M. I. Jubair 26
Rotate(90)
b
c
a
Rotation (11/11)
M. I. Jubair 27
Rotate(90)
a' b
c
ac'
d'
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/
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/
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/
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/
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.
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.
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/
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/
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/
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/
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/
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/
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/
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/
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/
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/
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/
Practice Problem – 1 (Sol.)
M. I. Jubair 45
a b
co
Practice Problem – 1 (Sol.)
M. I. Jubair 46
a'
b'
c'
o'
rotate(?)
Practice Problem – 1 (Sol.)
M. I. Jubair 47
scale(?)
a''
b''
c''
o''
Practice Problem – 1 (Sol.)
M. I. Jubair 48
a'''
b'''
c'''
o'''
rotate(?)
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
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
Thank you
M. I. Jubair 51