Unit II
2D Transformation
Introduction to Polygon
● Polygon is a representation of the surface. It is primitive which is closed in nature. It is
formed using a collection of lines. It is also called as many-sided figure. The lines
combined to form polygon are called sides or edges. The lines are obtained by
combining two vertices.
2 Dept. of Computer Engineering, PCET’s PCCOE, Pune
Types of Polygon
1. Concave Polygon:
Line segment joining any two points within
polygon may not lie completely inside the
polygon
Example:
2. Convex Polygon:
Line segment joining any two points within
polygon lie completely inside the polygon
Example:
3 Dept. of Computer Engineering, PCET’s PCCOE, Pune
Polygon Representation
To draw polygon on screen it should
satisfy following conditions
1. To draw polygon required more
than 2 vertices / 2 edges
2. All edges should be present in
specific sequence.
3. End point of last edge should be
equal to start point of start edge
(to make close shape)
4 Dept. of Computer Engineering, PCET’s PCCOE, Pune
2D Transformation
● Transformation is a process of change in orientation of an object by mathematical
operations.
● Using transformation we can change size, location, angle, take mirror image of
an object.
5 Dept. of Computer Engineering, PCET’s PCCOE, Pune
Steps to Perform Transformation
● Design polygon by series of line segments
● These Line segments represented by its end pixels
● Perform mathematical operations on pixel coordinates to change orientation of an
object.
● For Various transformation different matrices are present.
● Formula for any types transformation
P2 = P1 * T
Where P2- resultant matrix, P1- input matrix & T- transformation matrix
6 Dept. of Computer Engineering, PCET’s PCCOE, Pune
Representation of Polygon in Matrix Format
● Use n × 2 matrix
● 1st column for X axis coordinates
● 2nd column for Y axis coordinates
● Rows represents edges of polygon
● n no of rows depends on number of
edges in polygon
7 Dept. of Computer Engineering, PCET’s PCCOE, Pune
Identity Matrix
● A square matrix in which all the main
diagonal elements are 1’s and all the
remaining elements are 0’s
● Identity Matrix is also called Unit Matrix or
Elementary Matrix.
● Identity Matrix is denoted with the letter
“In×n”, where n×n represents the order of
the matrix.
● The important properties of identity matrix
is: A×In×n = A, where A is any square
matrix of order n×n.
8 Dept. of Computer Engineering, PCET’s PCCOE, Pune
Homogeneous Coordinate System
● A coordinate system that algebraically
treats all points in the projective plane
(both Euclidean and ideal) equally.
● Homogeneous coordinates are so called
because they treat Euclidean and ideal
points in the same way.
● Homogeneous coordinates are widely
used in computer graphics because they
Example: standard homogeneous coordinates enable affine and projective
[p1,p2,p3] of a point P in the projective plane are of transformations to be described as matrix
the form [x,y,1] if P is a point in the Euclidean plane
z=1 whose Cartesian coordinates are (x,y,1), or are of
manipulations in a coherent way.
the form [a,b,0] if P is the ideal point – the point at
infinity – associated to all lines in the Euclidean plane
z=1 with direction numbers a,b,0.
9 Dept. of Computer Engineering, PCET’s PCCOE, Pune
Scaling Transformation
● A scaling transformation
alters size of an object.
● we either compress or
expand the dimension of
the object.
● Scaling operation can be
achieved by multiplying
each vertex coordinate (x,
y) of the polygon by
scaling factor sx and sy to
Sx – scale factor for X coordinate produce the transformed
Sy – scale factor for Y coordinate
coordinates as (x', y')
10 Dept. of Computer Engineering, PCET’s PCCOE, Pune
Problem Solving
Scale the polygon with coordinates A (2,5) B(7,10) and C (10,2) by 2
units in X direction and 2 units in Y direction.
Given:
Sx=2, Sy=2
Scaling Matrix P1 Matrix
Sx 0 0 2 5 1
0 Sy 0 7 10 1
0 0 1 10 2 1
11 Dept. of Computer Engineering, PCET’s PCCOE, Pune
Problem Solving
Formula for to perform transformation:
P2 = P1 * T
2 5 1 2 0 0
=
7 10 1 0 2 0
10 2 1
* 0 0 1
4 10 1
=
14 20 1
20 4 1
12 Dept. of Computer Engineering, PCET’s PCCOE, Pune
Translation
● Translation is process of changing the
position of an object from one location
to another location.
● We can translate 2D object by adding
translation distance tx & ty.
● But for transformation we use generalize
formula P2=P1*T
● To implement translation though
multiplication instead of addition we use
1 0 0 homogeneous coordinate system.
Tx= translation factor of X coordinate
0 1 0
Ty = translation factor of Y coordinate
Tx Ty 1
13 Dept. of Computer Engineering, PCET’s PCCOE, Pune
Problem Solving
Translate the polygon with coordinates A (2,5) B(7,10) and C (10,2)
by 3 units in X direction and 4 units in Y direction.
Given:
Tx=3, Ty=4
Matrix P1 Matrix
1 0 0 2 5 1
0 1 0 7 10 1
Tx Ty 1 10 2 1
14 Dept. of Computer Engineering, PCET’s PCCOE, Pune
Problem Solving
Formula for to perform transformation:
P2 = P1 * T
2 5 1 1 0 0
=
7 10 1 0 1 0
10 2 1
* 3 4 1
5 9 1
=
10 14 1
13 6 1
15 Dept. of Computer Engineering, PCET’s PCCOE, Pune
Rotation
● Rotation is repositioning an
object along a circular path in xy
plane.
● To perform rotation we specify
angle of rotation (Ɵ) and
position of rotation point about
which object will rotate.
● Object rotation in clockwise or in
anticlockwise direction
● Position of rotation point can be
with respect to origin or any
arbitrary point.
16 Dept. of Computer Engineering, PCET’s PCCOE, Pune
Rotation Transformation Matrix
Rotation in Clockwise Direction
Rotation in Anticlockwise Direction
17 Dept. of Computer Engineering, PCET’s PCCOE, Pune
Rotation Transformation Matrix
Rotation in Clockwise Direction
Rotation in Anticlockwise Direction
18 Dept. of Computer Engineering, PCET’s PCCOE, Pune
Rotation About Arbitrary point
● Formula for rotation with respective arbitrary point = Tt * Tr * T -1t
19 Dept. of Computer Engineering, PCET’s PCCOE, Pune
Problem Solving
Perform a 450 rotation of triangle A(0,0) B(1,1) C(5,2)
i. About the origin ii. About arbitrary point (-1, -1)
Given: Ɵ = 450
P1 Matrix Rotation Matrix
0 0 1 cosƟ -sinƟ 0 cos45 -sin45 0 1/√2 -1/√2 0
1 1 1 sinƟ cosƟ 0 1/√2 1/√2 0
sin45 cos45 0
5 2 1 0 0 1 0 0 1 0 0 1
20 Dept. of Computer Engineering, PCET’s PCCOE, Pune
Problem Solving
P2= P1 * T
0 0 1 1/√2 -1/√2 0
= *
1 1 1 1/√2 1/√2 0
5 2 1 0 0 1
0 0 1
= √2 0 1
7/√2 -3/√2 1
21 Dept. of Computer Engineering, PCET’s PCCOE, Pune
Rotation About arbitrary point (-1, -1)
Cos Ɵ Sin Ɵ 0
T=
- sin Ɵ Cos Ɵ 0
-xp cos Ɵ + yp sin Ɵ +xp -xp sin Ɵ - yp cos Ɵ +yp 1
Cos 45 Sin 45 0
= - sin 45 Cos Ɵ 0
-(-1) cos 45 + (-1)sin 45 +(-1) -(-1) sin 45- (-1) cos (-1) +(-1) 1
22 Dept. of Computer Engineering, PCET’s PCCOE, Pune
Problem Solving
P2= P1 * T
= 0 0 1 * 1/√2 -1/√2 0
1 1 1 1/√2 1/√2 0
5 2 1 0 0 1
Cos 45 Sin 45 0
0 0 1
= - sin 45 Cos Ɵ 0
√2 0 1
-(-1) cos 45 + (-1)sin 45 +(-1) -(-1) sin 45- (-1) cos (-1) +(-1) 1
7/√2 -3/√2 1
= √2 -1 -1 1
√2 + √2 -1 -1 1
9/√2 -1 -3/√2 -1 1
23 Dept. of Computer Engineering, PCET’s PCCOE, Pune
Reflection
● Reflection produces a mirror image of an
object with respective an axis of
reflection.
● Different types of reflection – about X
axis, Y axis, origin, line y=x or any
arbitrary axis.
24 Dept. of Computer Engineering, PCET’s PCCOE, Pune
Types of reflection
25 Dept. of Computer Engineering, PCET’s PCCOE, Pune
Shear ● Slant the shape of an object
● 2 types of shearing
transformation X shear, Y shear
● In X shear : changes X value
which results in vertical lines to
tilt right / left & unchanged y
coordinate
● In Y shear : changes Y value
which results in horizontal lines
to slope up / down & unchanged
x coordinate
26 Dept. of Computer Engineering, PCET’s PCCOE, Pune
Composite Transformation
● Perform 2 or more types of transformation together
● Composite transformation is easy with homogeneous coordinate system
● Example of composite transformation is rotation about arbitrary point.
● In rotation about arbitrary point we perform combination of translation then
rotation and again reverse translation.
27 Dept. of Computer Engineering, PCET’s PCCOE, Pune
Problem Statements on Composite Transformation
● Consider the square P (5, 5) Q (5, 15) R (15, 15) S (15, 5). Rotate the square about
fixed point R(15,15) by an angle of 60 (anticlockwise) followed by scaling by 2 units
in x direction and 2 units in Y directions
28 Dept. of Computer Engineering, PCET’s PCCOE, Pune
3D Transformation
o Coordinate system (RHS /
LHS)
o How to represent 3D object
in 2D plan
o Different types of
transformations
29 Dept. of Computer Engineering, PCET’s PCCOE, Pune
How to represent 3D object on 2D plane`
❖ Accept 3 coordinates of pixel
❖ Consider any 2 axis value at a time &
discard 1
❖ Plot 3 pixel in considered axis plan one by
one.
❖ Draw parallel lines to the discarded axis
and passing through plotted pixel
❖ Identify the point where these
perpendicular lines are meeting
❖ That pixel will be present somewhere in
air. It means pixel having 3 dimensions
30 Dept. of Computer Engineering, PCET’s PCCOE, Pune
Steps to Perform Transformation
● Accept coordinates to design 3D object
● Draw 3D object on 2D plane
● Design P1 (4 * 4) matrix with the help of provided coordinate
● Identify transformation matrix (4 * 4) matrix based on type of
transformation
● Apply P2 = P1* T
● P2 will provide coordinates of resultant object
31 Dept. of Computer Engineering, PCET’s PCCOE, Pune
Scaling
32 Dept. of Computer Engineering, PCET’s PCCOE, Pune
Translation
33 Dept. of Computer Engineering, PCET’s PCCOE, Pune
3D Rotation
Xnew = Xold Xnew = Zoldsinθ + Xold cosθ Xnew = Xoldcosθ – Yold sinθ
Ynew = Yold Ynew = Xoldsinθ + Yoldcosθ
Ynew = Yold cosθ – Zold sinθ
Znew = Yoldcosθ – Xoldsinθ Znew = Zold
Znew = Yold sinθ + Zold cosθ
34 Dept. of Computer Engineering, PCET’s PCCOE, Pune
Rotation About Z Axis
35 Dept. of Computer Engineering, PCET’s PCCOE, Pune
Rotation About Y Axis
36 Dept. of Computer Engineering, PCET’s PCCOE, Pune
Rotation About X Axis
37 Dept. of Computer Engineering, PCET’s PCCOE, Pune
3D Reflection Types
38 Dept. of Computer Engineering, PCET’s PCCOE, Pune
3D Shear
Dept. of Computer Engineering, PCET’s PCCOE, Pune
39
THANK YOU !!!!
40