Professional Documents
Culture Documents
Module – II Syllabus
• Points and lines, Line drawing algorithms, midpoint circle and ellipse
algorithms. Filled area primitives: scan line polygon fill algorithm, boundary-
fill and flood fill algorithms.
• Translation, scaling, rotation, reflection and shear transformations, matrix
representations and homogenous coordinates, composite transforms,
transformation between coordinate systems. 2-D Viewing: The viewing
pipeline, viewing coordinate reference frame, window to viewport coordinate
transformation, viewing functions, Cohen-Sutherland and Cyrus beck line
clipping algorithms After
completion
• Reference Books: there will be a
There will be
continuous
Computer Graphics by Hearn & Donald, PHI class test
evaluation in the
Computer Graphic by Plastock, McGraw Hill form of
Assignments,
Principle of Interactive graphics by Newman.W Spraul R.F., McGraw Hill
quizzes etc.
Procedural Elements of computer graphics by Rogers D.F., McGraw Hill
1
1/3/2023
Matrix Representations
Homogeneous Coordinates
Matrix Representations
• In Modeling, we perform sequences of geometric
transformation: translation, rotation, and scaling to
model components into their proper positions.
2
1/3/2023
Matrix Representations
• We have seen:
• Rotation: 𝑥 ′ = 𝑥𝑟 + (𝑥 − 𝑥𝑟 ) cos 𝜃 − (𝑦 − 𝑦𝑟 ) sin 𝜃
𝑦 ′ = 𝑦𝑟 + (𝑥 − 𝑥𝑟 ) sin 𝜃 + (𝑦 − 𝑦𝑟 ) cos 𝜃
• Scaling: 𝑥 ′ = 𝑥 ⋅ 𝑆𝑥 + 𝑥𝑓 (1 − 𝑆𝑥 )
𝑦 ′ = 𝑦 ⋅ 𝑆𝑥 + 𝑦𝑓 (1 − 𝑆𝑦 )
• The basic transformations can be expressed in the
general matrix form: 𝐏 ′ = 𝐌𝟏 ⋅ 𝐏 + 𝐌𝟐
Matrix Representations
𝐏 ′ = 𝐌𝟏 ⋅ 𝐏 + 𝐌𝟐
• M1 is a 2×2 array containing multiplicative factors.
• M2 is a two element column matrix containing translation
terms.
• Translation: M1 is the identity matrix.
• Rotation: M2 contains the translation terms associated with the
pivot point.
• Scaling: M2 contains the translation terms associated with the
fixed point.
3
1/3/2023
Matrix Representations
𝐏 ′ = 𝐌𝟏 ⋅ 𝐏 + 𝐌𝟐
• To produce a sequence of transformations, we must
calculate the transformed coordinates one step at a
time.
Matrix Representations
𝐏 ′ = 𝐌𝟏 ⋅ 𝐏 + 𝐌𝟐
We can combine the multiplicative and translation terms
for 2D transformation into a single matrix
representation
by
expanding 2×2 matrix to 3×3 matrix.
4
1/3/2023
(X,Y,h)
5
1/3/2023
6
1/3/2023
Composite
Transformation
Composite Transformation
• Combined transformations
• By matrix multiplication
𝑥′ 1 0 𝑡𝑥 cos 𝜃 −sin 𝜃 0 𝑆𝑥 0 0 𝑥
𝑦′ = 0 1 𝑡𝑦 ⋅ sin 𝜃 cos 𝜃 0 ⋅ 0 𝑆𝑦 0 𝑦
𝑤′ 0 0 1 0 0 1 0 0 1 𝑤
𝐩′ = 𝐓 𝑡𝑥 , 𝑡𝑦 ⋅ 𝐑 𝜃 ⋅ 𝐒 𝑠𝑥 , 𝑠𝑦 ⋅ 𝐩
7
1/3/2023
General
Pivot Point
Rotation
T( x , y ) R ( ) T(− x ,− y ) = R ( x , y , )
r r r r r r
8
1/3/2023
General
Fixed Point
Scaling
1 0 xr s x 0 0 1 0 − xr s x 0 xr (1 − s x )
0 1 yr 0 sy 0 0 1 − yr = 0 sy yr (1 − s y )
0 0 1 0 0 1 0 0 1 0 0 1
January 3, 2023 DOI, Kurukshetra University 18
9
1/3/2023
General Scaling
Direction
10
1/3/2023
Reflection
Reflection
Reflection: Produces a mirror image of an object.
X Axis Y Axis Origin
1 0 0 − 1 0 0 − 1 0 0
0 − 1 0 0 1 0 0 − 1 0
0 0 1 0 0 1 0 0 1
y y y
1 1 1’
2’
2 3 2 3 3’ 2’ 3’ 1’
x x x
2’ 3’ 1 3
1’
2
11
1/3/2023
Reflection
• Reflection with respect to a line y = x
0 1 0 y y=x
1 0 0
We can drive this
matrix by : 0 0 1 x
Clockwise rotation
of 45º → Reflection
about the x axis →
Counterclockwise y y 1
y
rotation of 45º
2 3
x 2’ 3’ x x
1’
January 3, 2023 DOI, Kurukshetra University 23
Reflection
Reflection with respect to a line y = mx + b:
1. Translate the line so that it passes through the origin.
2. Rotate the onto one of the coordinate axes
3. Reflect about that axis y
4. Inverse rotation
0 − 1 0
5. Inverse translation − 1 0 0 x
0 0 1 y = - x y = -x
12
1/3/2023
Shear
Shear
• Shear: A transformation that distorts the shape of an object
such that transformed shape appears as if the object were
composed of internal layers that had been caused to slide over
each other is called a shear.
13
1/3/2023
Shear
– x-direction: x ' = x + hx y , y ' = y
y y
hx = 2
1 hx 0 (0,1) (1,1) (2,1) (3,1)
0 1 0
(0,0) (1,0) x (0,0) (1,0) x
0 0 1
1 0 0 y
hy= 2
y (1,2)
h 1 0
(0,1) (1,1)
(0,1)
y (0,0) (1,0) x
0 0 1 (0,0) x
Shear
– x-direction shears relative to a reference line
y = yref
x ' = x + hx ( y − yref ), y ' = y
hx= 0.5
− hx yref
y y
1 hx yref= -1 (1,1) (2,1)
0 1 0 (0,1) (1,1)
x x
0 0 1 (0,0)
yref= –1
(1,0) (0.5,0)
yref= –1
(1.5,0)
14
1/3/2023
Shear
◼ y-direction shears relative to a reference line
x = xref
x' = x, y ' = y + hy (x − xref )
Any Question?
Thanks!
15
1/3/2023
Transformations in 3D!
• Remembering 2D transformations -> 3x3 matrices, take
a wild guess what happens to 3D transformations.
1 0 t x
x t x
T (t x , t y ) = + = 0 1 t y T=(tx, ty, tz)
y t y 0 0 1
1 0 0 t x
x t x
0 1 0 t y
T (t x , t y , t z ) = y + t y =
0 0 1 t z
z t z
0 0 0 1
Homogeneous Coordinates
• Points in four-dimensional homogeneous space are usually
specified by (x; y; z; w). This is an extension of the usual
coordinate representation that we utilize with frames (x; y; z;
1). If we look at the coordinates (x; y; z; 1) in four
dimensions, we notice that they all lie on the space w = 1.
𝑤
(𝑥, 𝑦, 𝑧, 1) 𝑤=1
𝑥,
Ԧ 𝑦, 𝑧Ԧ
16
1/3/2023
Homogeneous Coordinates
• Well there are many ways to get a point away from the w = 1 space to
identify with a point in the space. We will utilize a projective approach in
which we will identify points out of the w = 1 space with points in the
space as follows:
– Given a coordinate (x, y, z, w), we identify the point (xi, yi, z i , 1) in the w = 1 space with
(x, y, z, w) if the point (xi, yi, z i , 1) is the unique point on the line connecting (x, y, z, w)
with the origin.
𝑤
(𝑥, 𝑦, 𝑧, 1)
𝑤=1
(𝑥 ′ , 𝑦 ′ , 𝑧 ′ , 1)
𝑥,
Ԧ 𝑦, 𝑧Ԧ
January 3, 2023 DOI, Kurukshetra University 33
Homogeneous Coordinates
• we have focussed on two axes (the w and the x axis)
• a similar triangle argument to obtain that Add a 3rd coordinate to every
𝑥 𝑦 𝑧 2D point
• 𝑥 𝑖 = 𝑤 and similarly 𝑦 𝑖 = 𝑤 , 𝑧 𝑖 = 𝑤 • (x, y, w) represents a point at
location (x/w, y/w)
𝑥 𝑦 𝑧
• Thus (𝑥, 𝑦, 𝑧, 𝑤) identifies as , , ,1 • (x, y, 0) represents a point at
𝑤 𝑤 𝑤
infinity (0, 0, 0) is not allowed
w w
(x, y, z, w) (x, y, z, w)
w
w= 1
𝑥 𝑦 𝑧 w= 1
1 , , ,1
𝑤 𝑤 𝑤
x′ x y
x
17
1/3/2023
Homogeneous Coordinates
• A way of representing data i.e. Representing n−d space
by n+1 dimensions
1. representing big integer numbers for example, 16bit
word for an integer between −32768 and 32767
2. How to represent a number > 32767 ?
a position [ 60000, y, z ] homogeneous coordinates:
[ 30000, y/2, z/2, 1/2 ]
3. defining an object and its transformation
– distinguish between a vector and a point
– modify the position of the origin of the coordinate system
Homogeneous Coordinates
there is no room in the 3x3 matrix to specify translation!
linear transformation translation
(rotation, scaling,
reflection,
shearing, ...) 3
3x3 x
1
1x3 1x1
perspective h
transformation overall scaling
18
1/3/2023
Homogeneous Coordinates
• This mapping has the following properties:
– The space w = 0 is not in the domain of this mapping. Clearly if we consider the point
(x, y, z, 0), the line through this point and the origin does not intersect the space w = 1.
– The mapping is many-to-one, in that any point (xw, yw, zw, w) also maps to the point
(x, y, z) for w # 0.
– Points (x, y, z, w) with w < 0 are in the domain of this mapping, as the line through this
point and the origin does intersect the space w = 1.
• The correspondence between 3-dimensional space and 4-dimensional
homogeneous space is frequently utilized to apply 4-dimensional functions
that define operators on 3-dimensional points. If we are given a coordinate
(x, y, z) in 3-dimensional space, we apply a 4 × 4 matrix to the coordinate
by multiplying
Homogeneous Coordinates
⋯
𝑥 𝑦 𝑧 1 ⋮ 4x4 ⋮ = 𝑥 𝑖 𝑦 𝑖 𝑧 𝑖 𝑤
⋯
• The point (x , y , z , w ) in homogeneous space is then
t t t t
projects to the space w = 1 by dividing by the fourth
coordinate
𝑥𝑖 𝑦𝑖 𝑧𝑖
, , ,1
𝑤 𝑤 𝑤
𝑥𝑖 𝑦𝑖 𝑧 𝑖
• and is then identified with the coordinate ( , , ) in 3-
𝑤 𝑤 𝑤
dimensional space, which is considered to be the result of the
transformation.
January 3, 2023 DOI, Kurukshetra University 38
19