CG Unit 3 Notes
CG Unit 3 Notes
Unit – III
2D, 3D Transformations and Projections
1. 2–D transformations
1.1 Introduction
Transformation means changing some graphics into something else by applying rules. We can
have various types of transformations such as translation, scaling up or down, rotation,
shearing, etc. When a transformation takes place on a 2D plane, it is called 2D transformation.
Transformations play an important role in computer graphics to reposition the graphics on the
screen and change their size or orientation.
To shorten this process, we have to use 3×3 transformation matrix instead of 2×2
transformation matrix. To convert a 2×2 matrix to 3×3 matrix, we have to add an extra dummy
coordinate W.
In this way, we can represent the point by 3 numbers instead of 2 numbers, which is
called Homogenous Coordinate system. In this system, we can represent all the
transformation equations in matrix multiplication. Any Cartesian point P(X,Y) can be converted
to homogenous coordinates by P’(Xh, Yh, h).
1.3 Translation
A translation moves an object to a different position on the screen. You can translate a point in
2D by adding translation coordinate (tx, ty) to the original coordinate X,Y to get the new
coordinate X′,Y′.
2|Page
X’ = X + tx
Y’ = Y + ty
The pair (tx, ty) is called the translation vector or shift vector. The above equations can also be
represented using the column vectors.
[ ] [ ] [ ]
P= P’ = T=
[ ] [ ] [ ]
We can write it as −
P’ = P + T
The translation matrix moves a point by tx units in the x–direction and ty units in the y–
direction. This transformation is represented as:
1 0 0
T= 0 1 0
𝑡 𝑡 1
1.4 Scaling
To change the size of an object, scaling transformation is used. In the scaling process, you
either expand or compress the dimensions of the object. Scaling can be achieved by multiplying
the original coordinates of the object with the scaling factor to get the desired result.
Let us assume that the original coordinates are X, Y, the scaling factors are (Sx, Sy), and the
produced coordinates are X′,Y′. This can be mathematically represented as shown below −
The scaling factor SX, SY scales the object in X and Y direction respectively. The above equations
can also be represented in matrix form as below −
OR
P’ = P ⋅ S
Where S is the scaling matrix. The scaling process is shown in the following figures.
If we provide values less than 1 to the scaling factor S, then we can reduce the size of the object.
If we provide values greater than 1, then we can increase the size of the object.
The scaling matrix, where Sx is the scaling factor along the x–axis and Sy is the scaling factor
along the y–axis, is:
𝑆 0
S= 0 𝑆
1.5 Reflection
Reflection is the mirror image of original object. In other words, we can say that it is a rotation
operation with 180°. In reflection transformation, the size of the object does not change.
The following figures show reflections with respect to x and y axes, and about the origin
respectively.
4|Page
1 0 0
Rx = 0 –1 0
0 0 1
–1 0 0
Ry = 0 1 0
0 0 1
–1 0 0
Ro = 0 –1 0
0 0 1
0 1 0
Rl = 1 0 0
0 0 1
1.6 Shear
5|Page
A transformation that slants the shape of an object is called the shear transformation. There are
two shear transformations X–Shear and Y–Shear. One shifts X coordinates values and other
shifts Y coordinate values. However; in both the cases only one coordinate changes its
coordinates and other preserves its values. Shearing is also termed as Skewing.
X–Shear
The X–Shear preserves the y coordinate and changes are made to x coordinates, which causes
the vertical lines to tilt right or left as shown in below figure.
1 𝑠ℎ 0
Xsh = 0 1 0
0 0 1
X’ = X + shx ⋅ Y
Y’ = Y
Y–Shear
The Y–Shear preserves the x coordinates and changes the y coordinates which causes the
horizontal lines to transform into lines which slopes up or down as shown in the following
figure.
6|Page
1 0 0
Ysh = 𝑠ℎ 1 0
0 0 1
Y' = Y + shy ⋅ X
X’ = X
1.7 Rotation
In rotation, we rotate the object at particular angle θ from its origin. From the following figure,
we can see that the point P (X,Y) is located at angle φ from the horizontal x coordinate with
distance r from the origin.
Let us suppose you want to rotate it at the angle θ. After rotating it to a new location, you will
get a new point P’ (X′,Y′).
Using standard trigonometric the original coordinate of point P (X,Y) can be represented as −
X = r cosϕ …(1)
Y = r sinϕ …(2)
or P’ = P ⋅ R
For positive rotation angle (clockwise direction), we can use the above rotation matrix.
However, for negative angle rotation (anticlockwise direction), the matrix will change as shown
below:
If we want to rotate an object or point about an arbitrary point, first of all, we translate the point
about which we want to rotate to the origin. Then rotate point or object about the origin, and at
the end, we again translate it to the original place. We get rotation about an arbitrary point.
2. 3–D transformations
2.1 Introduction
Parallelism is preserved,
2.2 Translation
It is the movement of an object from one position to another position. Translation is done using
translation vectors. There are three vectors in 3D instead of two. These vectors are in X, Y, and
9|Page
If P, a point having co–ordinates in three directions P(X, Y, Z) is translated, then after translation
its coordinates will be P’(X’, Y’, Z’) after translation. Tx Ty Tz are translation vectors in x, y, and
z directions respectively.
X’= X + Tx
Y’= Y + Ty
Z’= Z + Tz
1 0 0 0
0 1 0 0
T[X, Y, Z] = 0 0 1 0
𝑇 𝑇 𝑇 1
Point shown in fig is (X, Y, Z). It becomes (X’, Y’, Z’) after translation. Tx Ty Tz are translation
vectors.
1 0 0 0
0 1 0 0
[X’ Y’ Z’ 1] = [X Y Z 1] 0 0 1 0
𝑇 𝑇 𝑇 1
2.3 Scaling
You can change the size of an object using scaling transformation. In the scaling process, you
either expand or compress the dimensions of the object. Scaling can be achieved by multiplying
the original coordinates of the object with the scaling factor to get the desired result.
In 3D scaling operation, three coordinates are used. Let us assume that the original coordinates
are X, Y, Z, scaling factors are (Sx, Sy, Sz) respectively, and the produced coordinates are X′, Y′,
Z′. This can be mathematically represented as shown below −
P’ = P ⋅ S
11 | P a g e
2.4 Reflection
Reflection in 3D space is quite similar to the reflection in 2D space, but there is a single
difference in 3D and that is we have to deal with three axes (x, y, z). Reflection is nothing but
a mirror image of an object.
2.5 Shear
A transformation that slants the shape of an object is called the shear transformation. Like in
2D shear, we can shear an object along the X–axis, Y–axis, or Z–axis in 3D.
As shown in the above figure, there is a coordinate P. You can shear it to get a new coordinate
P', which can be represented in 3D matrix form as below −
P’ = P · Sh
2.6 Rotation
To derive the 3D transformation matrices for rotation about the principal axes (x, y, and z
axes), we will use the right-hand rule convention. The general approach involves rotating a
point in 3D space by an angle θ around one of the coordinate axes.
When rotating around the x-axis, the y and z coordinates are transformed, while the x coordinate
remains unchanged.
Explanation:
When rotating around the y-axis, the x and z coordinates are transformed, while the y coordinate
remains unchanged.
Explanation:
When rotating around the z-axis, the x and y coordinates are transformed, while the z coordinate
remains unchanged.
Explanation:
When the object is rotated about an axis that is not parallel to any one of co-ordinate axis, i.e.,
x, y, z. Then additional transformations are required. First of all, alignment is needed, and then
the object is being back to the original position. Following steps are required
3. Projections
Projection is a kind of phenomena that is used in computer graphics to map the view of a 3D
object onto the projecting display panel where the viewing volume is specified by the world
coordinate and then map these world coordinate over the view port.
17 | P a g e
Parallel projection is a kind of projection where the projecting lines emerge parallelly from the
polygon surface and then incident parallelly on the plane. In parallel projection, the centre of
the projection lies at infinity. In parallel projection, the view of the object obtained at the plane
is less-realistic as there is no for-shortcoming and the relative dimension of the object remains
preserves.
It is a kind of parallel projection where the projecting lines emerge parallelly from the object
surface and incident perpendicularly at the projecting plane.
a. Top-View: In this projection, the rays that emerge from the top of the polygon surface are
observed.
b. Side-View: It is another type of projection orthographic projection where the side view of
the polygon surface is observed.
c. Front-View: In this orthographic projection front face view of the object is observed.
It is a kind of parallel projection where projecting rays emerges parallelly from the surface of
the polygon and incident at an angle other than 90 degrees on the plane. It is of two kinds:
1. Cavalier Projection: It is a kind of oblique projection where the projecting lines emerge
parallelly from the object surface and incident at 45° rather than 90° at the projecting plane. In
this projection, the length of the reading axis is larger than the cabinet projection.
20 | P a g e
2. Cabinet Projection: It is similar to the cavalier projection but here the length of reading
axes is half than the cavalier projection and the incident angle at the projecting plane is 63.4°
rather 45°.
In Perspective Projection the center of projection is at finite distance from projection plane.
This projection produces realistic views but does not preserve relative proportions of an object
dimensions. Projections of distant object are smaller than projections of objects of same size
that are closer to projection plane.
1. Center of Projection – It is a point where lines or projection that are not parallel to
projection plane appear to meet.
The perspective projection, on the other hand, produces realistic views but does not preserve
relative proportions.
In perspective projection, the lines of projection are not parallel. Instead, they all converge at
a single point called the center of projection or projection reference point.
21 | P a g e
The object positions are transformed to the view plane along these converged projection lines
and the projected view of an object is determined by calculating the intersection of the
converged projection lines with the view plane, as shown in the figure below:
One point perspective projection occurs when any of principal axes intersects with projection
plane or we can say when projection plane is perpendicular to principal axis.
In the above figure, z axis intersects projection plane whereas x and y axis remain parallel to
projection plane.
22 | P a g e
Two-point perspective projection occurs when projection plane intersects two of principal axis.
In the above figure, projection plane intersects x and y axis whereas z axis remains parallel to
projection plane.
Three-point perspective projection occurs when all three axis intersects with projection plane.
There isn’t any principal axis which is parallel to projection plane.
Numerical Problems:
Q1. Find transformation of a triangle A(1, 0) B(0, 1) C(1, 1) by performing translation by
one unit in x and y directions and then rotating 45° about the origin.
1 0 1
𝑃(𝑋, 𝑌) = 0 1 1
1 1 1
For translation of 1 unit in X and Y directions, the translation matrix will be:
24 | P a g e
1 0 0
𝑇 = 0 1 0
1 1 1
1 0 1 1 0 0 2 1 1
𝑃(𝑋′, 𝑌′) = 0 1 1 × 0 1 0 = 1 2 1
1 1 1 1 1 1 2 2 1
𝑐𝑜𝑠 𝜃 𝑠𝑖𝑛 𝜃 0
𝑅 = – 𝑠𝑖𝑛 𝜃 𝑐𝑜𝑠 𝜃 0
0 0 1
Therefore, the final coordinates are A(0.7, 2.1), B(–0.7, 2.1), C(0, 2.8).
Q2. Given a circle C with radius 5 and center coordinates (1, 4). Apply the translation
with distance 5 towards X axis and 1 towards Y axis. Obtain the new coordinates of C
without changing its radius.
Translation: 5 units towards the x-axis and 1 unit towards the y-axis
To find the new coordinates of the center, add the translation values to the current coordinates:
Where:
Q3. Given a line segment with starting point as (0, 0) and ending point as (4, 4). Apply 30°
rotation in the anticlockwise direction on the line segment and find out the new
coordinates of the line.
0.866 – 0.5
𝑅(30°) =
0.5 0.866
We will apply this rotation matrix to both points of the line segment.
The starting point (0,0) remains the same after the rotation because rotating the origin results
in no change.
𝑥′ 𝑥
= 𝑅(30°) 𝑦
𝑦′
26 | P a g e
0.866 – 0.5 4
=
0.5 0.866 4
1.464
=
5.464
Thus, the new coordinates of the line segment after a 30° anticlockwise rotation are (0,0) for
the starting point and approximately (1.464, 5.464) for the ending point.
Q4. Consider the square A (1, 0), B(0, 0), C(0, 1), D (1, 1). Rotate the square ABCD by 45º
anticlockwise about point A (1,0).
1 0 1
0 0 1
M=
0 1 1
1 1 1
1 0 1 0 0 1
1 0 0
0 0 1 −1 0 1
× 0 1 0 =
0 1 1 −1 1 1
−1 0 1
1 1 1 0 1 1
So, the square after translation has the vertices, A′ (0, 0), B′ (−1, 0), C′ (−1, 1), D′ (0, 1)
We will now rotate the translated square 45º anticlockwise using the 2D rotation matrix. The
rotation matrix for a 45º anticlockwise rotation is:
𝑐𝑜𝑠 𝜃 𝑠𝑖𝑛 𝜃 0
𝑅(𝜃) = – 𝑠𝑖𝑛 𝜃 𝑐𝑜𝑠 𝜃 0
0 0 1
0 0 1 0 0 1
0.707 0.707 0
−1 0 1 −0.707 −0.707 1
× – 0.707 0.707 0 =
−1 1 1 −1.414 0 1
0 0 1
0 1 1 −0.707 0.707 1
We will apply this rotation matrix to the new coordinates A′, B′, C′, D′.
The new coordinates are A′′ (0, 0), B′′ (–0.707, –0.707), C′′ (–1.414, 0), D′′ (–0.707, 0.707).
27 | P a g e
Now we translate the points back to their original positions with tx = 1 and ty = 0:
0 0 1 1 0 1
1 0 0
−0.707 −0.707 1 0.293 −0.707 1
× 0 1 0 =
−1.414 0 1 −0.414 0 1
1 0 1
−0.707 0.707 1 0.293 0.707 1
After rotating the square ABCD by 45º anticlockwise about point A(1,0)A(1, 0)A(1,0), the new
coordinates of the vertices are A (1,0), B (0.293,−0.707), C (−0.414,0), D (0.293,0.707).
𝟐 𝟒 𝟒
Q5. A triangle is defined by . Find transformed coordinates after the following
𝟐 𝟐 𝟒
transformation.
Solution:
Here, the first row represents the x-coordinates, and the second row represents the y-
coordinates of the three vertices of the triangle: (2,2), (4,2), and (4,4).
The transformation matrix for a 90º counterclockwise rotation about the origin is:
So, the new coordinates of the triangle after a 90º rotation are: (−2,2), (−2,4), (−4,4)
The transformation matrix for reflecting a point about the line X=Y is
−2 −2 −4 0 1 −2 −2 −4
New coordinates = RX=Y × = ×
2 4 4 1 0 2 4 4
2 4 4
=
−2 −2 −4
So, the new coordinates of the triangle after reflection about the line X=Y are (2, –2), (4, –2)
and (4, –4)
Q6. Perform 45° rotation of a triangle A(0, 0), B(1, 1) and C(5, 2). Find transformed
coordinates after rotation, (i) About origin, (ii) About P (–1, 1).
0 0 1
𝑃(𝑋, 𝑌) = 1 1 1
5 2 1
0 0 1 0.707 0.707 0 0 0 1
𝑃(𝑋′, 𝑌′) = 1 1 1 × – 0.707 0.707 0 = 0 1.414 1
5 2 1 0 0 1 2.121 4.949 1
So, the new coordinates are A(0, 0), B(0, 1.414), C(2.121, 4.95).
To rotate about a point other than the origin, we first translate the point P (−1,1) to the origin,
perform the rotation, and then translate back.
Therefore, tx = 1 and ty = −1
1 0 0
𝑇 = 0 1 0
−1 1 1
0 0 1 1 0 0 1 −1 1
𝑃(𝑋 , 𝑌 ) = 𝑃(𝑋, 𝑌) × 𝑇 = 1 1 1 × 0 1 0 = 2 0 1
5 2 1 1 −1 1 6 1 1
The new coordinates are A’(1, –1), B’(2, 0) and C’(6, 1).
The new coordinates are A’’(1.414, 0), B’’(1.414, 1.414) and C’’(3.535, 4.949).
Now we translate the rotated triangle back by adding the coordinates of point P(−1,1).
Therefore, tx = −1 and ty = 1
1.414 0 1 1 0 0 0.414 1 1
1.414 1.414 1 × 0 1 0 = 0.414 2.414 0
3.535 4.949 1 −1 1 1 2.535 5.949 1
The new coordinates are A(0.414, 1), B(0.414, 2.414) and C’’(2.535, 5.949).
Q7. Consider a polygon with 4 sides as follow P1(1, 1), P2(3, 1), P3(3, 3), P4(1, 3). Scale
this polygon to half of its size.
To scale the polygon with vertices P1(1,1), P2(3,1), P3(3,3) and P4(1,3) to half its size, we'll
apply a scaling transformation.
Sx and Sy are the scaling factors for the x and y axes, respectively.
In this case, since we want to scale the polygon to half its size, Sx = Sy = 0.5
1 1 1 0.5 0.5 1
0.5 0 0
3 1 1 1.5 0.5 1
× 0 0.5 0 =
3 3 1 1.5 1.5 1
0 0 1
1 3 1 0.5 1.5 1