You are on page 1of 19

1/3/2023

EI-OE-401 Open Elective IV


(Computer Graphics and CAD/CAM)
Module - 2
2D Transformations and Homogenous Matrix

Prof. Pardeep Kumar


Department of Instrumentation,
Kurukshetra University, Kurukshetra-136119
pardeepk@kuk.ac.in

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

January 3, 2023 DOI, Kurukshetra University 2

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.

• How the matrix representations can be reformulated so


that transformation sequences can be efficiently
processed?

January 3, 2023 DOI, Kurukshetra University 4

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: 𝐏 ′ = 𝐌𝟏 ⋅ 𝐏 + 𝐌𝟐

January 3, 2023 DOI, Kurukshetra University 5

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.

January 3, 2023 DOI, Kurukshetra University 6

3
1/3/2023

Matrix Representations
𝐏 ′ = 𝐌𝟏 ⋅ 𝐏 + 𝐌𝟐
• To produce a sequence of transformations, we must
calculate the transformed coordinates one step at a
time.

• We need to eliminate the matrix addition associated


with the translation terms in M2.

January 3, 2023 DOI, Kurukshetra University 7

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.

January 3, 2023 DOI, Kurukshetra University 8

4
1/3/2023

Matrix Representations and


Homogeneous Coordinate
• Homogeneous Coordinate: To express any 2D transformation
as a matrix multiplication, we represent each Cartesian
coordinate position (x, y) with the homogeneous Coordinate
triple (xh, yh, h):
𝒙𝒉 𝒚𝒉
such that: 𝒙= , 𝒚=
𝒉 𝒉
for simply: h = 1

January 3, 2023 DOI, Kurukshetra University 9

Matrix Representations and


Homogeneous Coordinate
Physical meaning:
h

(X,Y,h)

January 3, 2023 DOI, Kurukshetra University 10

5
1/3/2023

Matrix Representations and


Homogeneous Coordinate
Expressing position in homogeneous Coordinates,
(x, y, 1) allows us to represent all geometric
transformation as matrix multiplication

January 3, 2023 DOI, Kurukshetra University 11

Matrix Representations and


Homogeneous Coordinate
𝑥′ 1 0 𝑡𝑥 𝑥
• Translation: 𝑦 ′ = 0 1 𝑡
𝑦 𝑦
1 0 0 1 1
𝑥′ cos 𝜃 −sin 𝜃 0 𝑥
• Rotation: 𝑦 ′ = sin 𝜃 cos 𝜃 0 𝑦
1 0 0 1 1
𝑥′ 𝑆𝑥 0 0 𝑥
• Scaling: 𝑦 ′ = 0 𝑆𝑦 0 𝑦
1 0 0 1 1

January 3, 2023 DOI, Kurukshetra University 12

6
1/3/2023

Composite
Transformation

January 3, 2023 DOI, Kurukshetra University 13

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 𝑤

𝐩′ = 𝐓 𝑡𝑥 , 𝑡𝑦 ⋅ 𝐑 𝜃 ⋅ 𝐒 𝑠𝑥 , 𝑠𝑦 ⋅ 𝐩

Efficiency with pre-multiplication:


𝐩′ = 𝐓 x 𝐑 x 𝐒 x 𝐩 ⇒ 𝐩′ = 𝐓 𝐱 𝐑 𝐱 𝐒 𝐱 𝐩
January 3, 2023 DOI, Kurukshetra University 14

7
1/3/2023

General
Pivot Point
Rotation

General Pivot Point Rotation

(xr,yr) (xr,yr) (xr,yr) (xr,yr)

Translation Rotation Translation

T( x , y )  R ( )  T(− x ,− y ) = R ( x , y ,  )
r r r r r r

1 0 xr  cos  − sin  0 1 0 − xr  cos  − sin  xr (1 − cos  ) + yr sin  


0 1 y    sin  cos  0  0 1 − y  =  sin  cos  y (1 − cos  ) − x sin  
 r    r  r r 
0 0 1   0 0 1 0 0 1   0 0 1 

January 3, 2023 DOI, Kurukshetra University 16

8
1/3/2023

General
Fixed Point
Scaling

General Fixed Point Scaling

(xr,yr) (xr,yr) (xr,yr) (xr,yr)

Translation Scaling Translation

T(xr , yr )  S(s x , s y )  T(− xr ,− yr ) = S(xr , yr , s x , s y )

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

General Scaling Direction

 s1 cos 2  + s2 sin 2  ( s2 − s1 ) cos  sin  0


 
R −1 ( )  S( s1 , s2 )  R ( ) =  ( s2 − s1 ) cos  sin  s1 sin 2  + s2 cos 2  0
 0 0 1

January 3, 2023 DOI, Kurukshetra University 20

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

X Axis Y Axis Origin


January 3, 2023 DOI, Kurukshetra University 22

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

January 3, 2023 DOI, Kurukshetra University 24

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.

January 3, 2023 DOI, Kurukshetra University 26

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

– y-direction: x ' = x, y ' = y + h y  x


(1,3)

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

January 3, 2023 DOI, Kurukshetra University 27

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)

January 3, 2023 DOI, Kurukshetra University 28

14
1/3/2023

Shear
◼ y-direction shears relative to a reference line
x = xref
x' = x, y ' = y + hy  (x − xref )

hy= 0.5 (1,2)


1 
y y
0 0 x = -1 (0,1.5) (1,1)
h 1 − h y  xref 
(0,1)
(0,0)
(1,1)
(1,0)
ref
(0,0.5)
 y  x x
xref= –1
 0 0 1  xref= –1

January 3, 2023 DOI, Kurukshetra University 29

Any Question?

Thanks!

January 3, 2023 DOI, Kurukshetra University


30

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 

January 3, 2023 DOI, Kurukshetra University 31

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

𝑥,
Ԧ 𝑦, 𝑧Ԧ

January 3, 2023 DOI, Kurukshetra University 32

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

January 3, 2023 DOI, Kurukshetra University 34

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

January 3, 2023 DOI, Kurukshetra University 35

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

− there is no unique homogeneous coordinate representation!


h=0?
January 3, 2023 DOI, Kurukshetra University 36

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

January 3, 2023 DOI, Kurukshetra University 37

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

You might also like