0% found this document useful (0 votes)
66 views35 pages

Computer Graphics Lecture - 2 - V2024

This document provides information about a computer graphics course. The instructor is Prof. Edward Baagyere and his contact details are listed. The course is CSC 405 Introduction to Computer Graphics. It will be held on Thursdays and Fridays. Prerequisites include a background in C++ and linear algebra. The document then discusses 2D transformations and matrices, including scaling, reflections, shearing, rotation and translations. It also covers homogeneous coordinates and composite transformations.

Uploaded by

amandemarvin
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
66 views35 pages

Computer Graphics Lecture - 2 - V2024

This document provides information about a computer graphics course. The instructor is Prof. Edward Baagyere and his contact details are listed. The course is CSC 405 Introduction to Computer Graphics. It will be held on Thursdays and Fridays. Prerequisites include a background in C++ and linear algebra. The document then discusses 2D transformations and matrices, including scaling, reflections, shearing, rotation and translations. It also covers homogeneous coordinates and composite transformations.

Uploaded by

amandemarvin
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 35

COMPUTER GRAPHICS

PROF. BAAGYERE Y. EDWARD

3/13/2022
CSC 405:Computer Graphics

¨ Instructor: Prof. Edward Y. Baagyere


¨ Office Location: SCIS Dean’s Office
¨ Telephone: +233249990362
¨ Email: [email protected]
¨ Office Hours: Fridays, 12:00 – 17:00
¨ Lecture Days/Time: Thursday: 09:00 – 10:55 am
Friday: 05:00 – 5:55 pm
¨ Lecture room: NHA2
¨ Pre-requisites: Computer Science standing.
¨ Good background in C++, Linear Algebra is helpful. Must have self-
motivations in self learning and independent research

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]

¨ [T] represents a generic operator to be applied

to the points in A. T is the geometric


transformation matrix.
¨ If A & T are known, the transformed points are

obtained by calculating B.
General Transformation of 2D points

𝑥′ 𝑎 𝑐 𝑥 𝑥′ 𝑇 𝑥 𝑇 𝑎 𝑐
v = v = 𝑦
𝑦′ 𝑏 𝑑 𝑦 𝑦′ 𝑏 𝑑
v 𝑥 ! = 𝑎𝑥 + 𝑐𝑦 v 𝑥 ! = 𝑎𝑥 + 𝑐𝑦
v 𝑦 ! = 𝑏𝑥 + 𝑑𝑦 v 𝑦 ! = 𝑏𝑥 + 𝑑𝑦

¨ Solid body transformations – the above equation is valid for


all set of points and lines of the object being transformed.

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

• What if Sx and/ or Sy < 0 (are negative)? Get reflections through an


axis or plane. Only diagonal terms are involved in scaling and
reflections.
• Note : House shifts position relative to origin
30/01/2024
More examples of Scaling and reflection

3/13/2022
Special cases of Reflections (|T| = -1)

Matrix T Reflection About


𝟏 𝟎 Y=0 Axis (or X-axis)
𝟎 −𝟏
−𝟏 𝟎 X=0 Axis (or Y-axis)
𝟎 𝟏
𝟎 𝟏 Y = X Axis
𝟏 𝟎
𝟎 −𝟏 Y = -X Axis
−𝟏 𝟎
30/01/2024
Off diagonal terms are involved in SHEARING ;

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(𝜃)

n Positive Rotations: counter clockwise about the origin


n For rotations, |T| = 1 and [T]T= [T]-1.
n Rotation matrices are orthogonal. 3/13/2022
Special cases of Rotations

θ (in degrees) Matrix T


90 𝟎 −𝟏
𝟏 𝟎
180 −𝟏 𝟎
𝟎 −𝟏
270 or – 90 𝟎 𝟏
−𝟏 𝟎
360 or 0 𝟏 𝟎
𝟎 𝟏
3/13/2022
Example - Transformation of a Unit Square

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
𝑇
¨ 𝐵 = 𝐴 + 𝑇𝑑 , 𝑤ℎ𝑒𝑟𝑒 𝑇𝑑 = [𝑡 𝑥 𝑡 𝑦 ]

Where else are translations introduced?


1) Rotations - when objects are not centered at the origin.
2) Scaling - when objects/lines are not centered at the origin
- if line intersects the origin, no translation.

Origin is invariant to Scaling, reflection and Shear – not translation.

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

¨ Each point is now represented by a triplet: (x, y, w).


¨ (x/w, y/w) are called the Cartesian coordinates of the homogeneous
points.
3/13/2022
Interpretation of Homogeneous Coordinates

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

¨ If we want to apply a series of transformations T1, T2, T3 to a set of


points, We can do it in two ways:
1) We can calculate p'=T1*p, p''= T2*p', p'''=T3*p"
2) Calculate T= T1*T2*T3, then p'''= T*p.
q Method 2, saves large number of additions and multiplications
(computational time) – needs approximately 1/3 of as many
operations. Therefore, we concatenate or compose the matrices into
one final transformation matrix, and then apply that to the points.
3/13/2022
¨ Translations:
1 0 (𝑡𝑥1 + 𝑡𝑥2)
Ø Translate the points by tx1, ty1, then by tx2, ty2: 0 1 (𝑡𝑦1 + 𝑡𝑦2)
0 0 1
¨ Scaling:
Ø Similar to translations

¨ Rotations:
Ø Rotate by θ1, then by θ2:

I. Stick the (θ1+ θ2) in for θ, or


II. Calculate T1 for θ1, then T2 for θ2 & multiply them.
¨ Exercise: Both gives the same result – work it out 3/13/2022
Rotation about an arbitrary point P in space

¨ 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:

Ø Translate by (-Px, -Py )


Ø Rotate
Ø Translate by (Px, Py )
Rotation about an arbitrary point P in space

3/13/2022
Rotation about an arbitrary point P in space
𝑇 = 𝑇3(𝑃𝑥, 𝑃𝑦) ∗ 𝑇2(𝜃) ∗ 𝑇1(−𝑃𝑥, −𝑃𝑦)

1 0 𝑃𝑥 cos(𝜃) − sin(𝜃) 0 1 0 −𝑃𝑥


= 0 1 𝑃𝑦 sin(𝜃) cos(𝜃) 0 0 1 −𝑃𝑦
0 0 1 0 0 1 0 0 1

3/13/2022
Scaling about an arbitrary point in Space

¨ Again,
Ø Translate P to the origin

Ø Scale

Ø Translate P back

¨ T = T1 Px, Py ∗ T2 Sx, Sy ∗ T3 (−Px, −Py)

𝑆𝑥 0 {𝑃𝑥 ∗ (1 − 𝑆𝑥)}
𝑇 = 0 𝑆𝑦 {𝑃𝑦 ∗ (1 − 𝑆𝑦)}
0 0 1
3/13/2022
Reflection through an arbitrary line
¨ Steps:
Ø Translate line to the origin

Ø Rotation about the origin

Ø Reflection matrix

Ø Reverse the rotation

Ø Translate line back

𝑇ℎ𝑎𝑡 𝑖𝑠: 𝑇GHIJKL = 𝑇M 𝑅𝑇MKL 𝑅N 𝑇MOP


Commutivity of Transformations
v If we scale, then translate to the origin, and then translate back,
is that equivalent to translate to origin, scale, translate back?

v When is the order of matrix multiplication unimportant?

v When does T1 * T2 = T2 * T1? T1 T2


translation translation
v Cases where T1 * T2 = T2 * T1: Scale Scale
Rotation Rotation
Scale (Uniform) Rotation
3/13/2022
COORDINATE SYSTEMS
v Screen Coordinates: The coordinate system used to address the
screen (device coordinates)
v World Coordinates: A user-defined application specific coordinate
system having its own units of measure, axis, origin, etc.
v Window: The rectangular region of the world that is visible.
v Viewport: The rectangular region of the screen space that is used to
display the window.

3/13/2022
3/13/2022
WINDOW TO VIEWPORT TRANSFORMATION

o Purpose is to find the transformation matrix that maps the


window in world coordinates to the viewport in screen
coordinates.

o Window: (x, y space) denoted by: xmin, ymin, xmax, ymax

o Viewport: (u, v space) denoted by: umin, vmin, umax, vmax

3/13/2022
Window – Viewport Transformation
The overall transformation:
Ø Translate the window to the origin

Ø Scale it to the size of the viewport

Ø Translate it to the viewport location

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

You might also like