Computer Graphics Lecture - 2 - V2024
Computer Graphics Lecture - 2 - V2024
3/13/2022
CSC 405:Computer Graphics
3/13/2022
CSC 405: Introduction to Computer Graphics
3/13/2022
Lecture 2
TRANSFORMATIONS
in 2-D
3/13/2024
2D TRANSFORMATIONS AND MATRICES
¨ Representation of Points:
𝑥
¨ 2 x 1 matrix:
𝑦
¨ General Problem: [B] = [T] [A]
obtained by calculating B.
General Transformation of 2D points
𝑥′ 𝑎 𝑐 𝑥 𝑥′ 𝑇 𝑥 𝑇 𝑎 𝑐
v = v = 𝑦
𝑦′ 𝑏 𝑑 𝑦 𝑦′ 𝑏 𝑑
v 𝑥 ! = 𝑎𝑥 + 𝑐𝑦 v 𝑥 ! = 𝑎𝑥 + 𝑐𝑦
v 𝑦 ! = 𝑏𝑥 + 𝑑𝑦 v 𝑦 ! = 𝑏𝑥 + 𝑑𝑦
30/01/2024
Special cases of 2D Transformations
¨ 1) T = identity matrix:
¨ 𝑎 = 𝑑 = 1, 𝑏 = 𝑐 = 0 ⇒ 𝑥 ! = 𝑥, 𝑦 ! = 𝑦
¨ 2) Scaling & Reflections:
¨ 𝑏 = 0, 𝑐 = 0 ⇒ 𝑥′ = 𝑎. 𝑥, 𝑦′ = 𝑑. 𝑦;
¨ This is scaling by a in x, d in y.
¨ If a = d, we have uniform scaling, else non-uniform scaling.
𝑆𝑥 0
¨ Scale matrix: let Sx = a, Sy = d:
0 𝑆𝑦
30/01/2024
Example of Scaling
Sx = 3
Sy = 2
3/13/2022
Special cases of Reflections (|T| = -1)
a = d = 1; let c = 0, 𝑎 𝑐 𝑥
=
𝑥′
𝑏 𝑑 𝑦 𝑦′
b=2
𝑥 ! = 𝑎𝑥 + 𝑐𝑦
=> x' = x, y' = 2x + y ; 𝑦 ! = 𝑏𝑥 + 𝑑𝑦
y' depends linearly on x ; This effect is called
shear.
Similarly for b=0, c not equal to zero. The shear
in this case is proportional to y-coordinate.
ROTATION
n 𝑋! = 𝑥 cos 𝜃 − 𝑦 sin(𝜃)
n 𝑌! = 𝑥 sin 𝜃 − 𝑦 cos(𝜃)
cos(𝜃) − sin(𝜃)
n𝑇 =
sin(𝜃) cos(𝜃)
0 0 0 0
1 0 ! 𝑎 𝑏 𝑎 𝑏
¨ 𝑆= ¨ 𝑆 =𝑆 =
1 1 𝑐 𝑑 𝑎+𝑐 𝑏+𝑑
0 1 𝑐 𝑑
Area of the unit square after transformation = ad - bc = |T|.
Extend this idea for any arbitrary area. 3/13/2022
Translations
3/13/2022
Translations
𝑇
¨ 𝐵 = 𝐴 + 𝑇𝑑 , 𝑤ℎ𝑒𝑟𝑒 𝑇𝑑 = [𝑡 𝑥 𝑡 𝑦 ]
3/13/2022
¨ Note: we cannot directly represent translations as matrix
multiplication, as we can for:
SCALING ROTATION
3/13/2022
HOMOGENEOUS COORDINATES
Use a 3 x 3 matrix: 𝑥′ 𝑎 𝑐 𝑡𝑥 𝑥
𝑦′ = 𝑏 𝑑 𝑡𝑦 𝑦
𝑧′ 0 0 1 𝑧
We have:
x' = ax + cy + tx
y' = bx + cy + ty
3/13/2022
q Two homogeneous coordinates (x1, y1, w 1) & (x2, y2, w2) may
represent the same point, iff they are multiples of one another:
say, (1, 2, 3) & (3, 6, 9).
q There is no unique homogeneous representation of a point.
q All triples of the form (t.x, t.y, t.w) form a line in x, y, w space.
q Cartesian coordinates are just the plane w=1 in this space.
q w=0, are the points at infinity.
3/13/2022
General Purpose 2D transformations in homogeneous
coordinate representation
𝒂 𝒃 𝒑
𝑻= 𝒄 𝒅 𝒒
𝒎 𝒏 𝒔
Parameters involved in scaling, rotation, reflection and shear are: a, b,
c, d.
If B = T.A, then If B = A.T, then
Translation Translation
parameters: parameters:
What about (m, n)
(p, q)
S? 3/13/2022
COMPOSITE TRANSFORMATIONS
¨ Rotations:
Ø Rotate by θ1, then by θ2:
¨ As we mentioned before, rotations are applied about the origin. So, to rotate
about any arbitrary point P in space, translate so that P coincides with the
origin, then rotate , then translate back. Steps are:
3/13/2022
Rotation about an arbitrary point P in space
𝑇 = 𝑇3(𝑃𝑥, 𝑃𝑦) ∗ 𝑇2(𝜃) ∗ 𝑇1(−𝑃𝑥, −𝑃𝑦)
3/13/2022
Scaling about an arbitrary point in Space
¨ Again,
Ø Translate P to the origin
Ø Scale
Ø Translate P back
𝑆𝑥 0 {𝑃𝑥 ∗ (1 − 𝑆𝑥)}
𝑇 = 0 𝑆𝑦 {𝑃𝑦 ∗ (1 − 𝑆𝑦)}
0 0 1
3/13/2022
Reflection through an arbitrary line
¨ Steps:
Ø Translate line to the origin
Ø Reflection matrix
3/13/2022
3/13/2022
WINDOW TO VIEWPORT TRANSFORMATION
3/13/2022
Window – Viewport Transformation
The overall transformation:
Ø Translate the window to the origin
3/13/2022
Exercise -Transformations of Parallel Lines
v Consider two parallel lines:
A[X 1, Y 1] to B[X 2, Y 2]
C[X 3, Y 3] to B[X 4, Y 4]
)*+), ).+)/
Slope of the lines: -*+-,
= -.+-/
Solve the problem: If the lines are 𝑎 𝑏
𝑇=
Transformed by a matrix: 𝑐 𝑑
! 0123
The slope of the transformed lines is: m =
4153
3/13/2022