Chapter Six
Chapter Six
Geometrical Transformations
Introduction
The term Transformation is generally referred to as converting a graphic into another graphic by
applying some rules or algorithms. Sometimes an image or picture can be a combination of lines,
rectangle, circle, and triangle. If we draw the basic and combination of pictures, then there should
be a need to transform these images. Now we can perform the following actions to transform the
images-
We can change the position of an image.
We can increase or decrease the size of an image.
We can change the angle of the image.
By using the above actions, we will find a new image; this process is called Transformation. We
can use some algorithms to produce new pictures.
The object transformation includes two important points
Geometric Transformation: When we are moving the picture, and the background is
fixed, then it is a Geometric Transformation.
Coordinate Transformation: When we are moving the background, and the picture is
fixed, then it is Coordinate Transformation.
Types of Transformation
1|Page
There are two basic kinds of Translation.
1. Two-Dimensional (2D) Transformation:
When we translate, rotate, and scale object in the two-dimensional plane, then it is called a Two-
Dimensional Transformation. A two-dimensional plane consists of the x and y-axis.
The Two-Dimensional Transformation includes:-
2D Translation: Translation is a mechanism used to move the object from one position to
another position on the screen.
2D Rotation: Rotation is a process used to rotate the object from origin to a particular
angle.
2D Scaling: Scaling is a process or technique used to resize the object in two-dimensional
plane.
2D Reflection: Reflection is a mechanism or process in which we can rotate the object at
the angle of 180°.
2D Shearing: Shearing is a process that is used to perform slanting on the object. It is also
called “Skewing.”
2. Three-Dimensional Transformation:
When we translate, rotate, and scale object in the three-dimensional plane then, it is called Three-
Dimensional (3D) Transformation. A three–dimensional plane consists of x, y, and z-axis.
The Three-Dimensional Transformation includes
3D Translation: Translation is a mechanism used to move the object from one position to
another position on the three-dimensional plane.
3D Rotation: Rotation is a process used to rotate the object from origin to a particular
angle in three-dimensional plane.
3D Scaling: Scaling is a process or technique used to resize the object in three-dimensional
plane.
3D Reflection: Reflection is a mechanism or process in which we can rotate the object at
the angle of 180° in three-dimensional plane.
3D Shearing: Shearing is a process that is used to perform slanting on the object. It is also
called “Skewing”. It also includes z-axis.
2D Translation in Computer Graphics:
We can move any object from one to another place without changing the shape of the object.
2|Page
For Example:- Translation of a Point: If we want to translate a point from P (x0, y0) to Q (x1,
y1), then we have to add Translation coordinates (Tx, Ty) with original coordinates.
Here, Translation coordinates (Tx, Ty) are also called “Translation or Shift Vector.”
Example– Given a Point with coordinates (2, 4). Apply the translation with distance 4 towards x-
axis and 2 towards the y-axis. Find the new coordinates without changing the radius?
Solution: P = (x0, y0) = (2,4)
3|Page
Shift Vector = (Tx, Ty) = (4, 2)
Let us assume the new coordinates of P = (x1, y1)
Now we are going to add translation vector and given coordinates, then
x1 = x0 + Tx = (2 + 4) = 6
y1 = y0 + Ty = (4 + 2) = 6
Thus, the new coordinates = (6,6)
4|Page
Straight Lines
Curved Lines
Polygon
Circle
For Example:-
Rotation of a Point: If we want to Rotate a point A (P0, Q0) that has a Rotation angle with θ
distance r from origin to A (P1, Q1) that has a Rotation angle β. Then, we can rotate by following
Rotation equation-
P1 = P0 x cosθ – Q0 x sinθ
Q1 = P0 x sinθ + Q0 x cosθ
We can represent the coordinates of point A (P0, Q0) by using standard trigonometry-
P0 = r cosθ………… (1)
Q0 = r sinθ………… (2)
We can also define point A (P1, Q1) in the same way-
P1 = r cos (θ+β) = r cosθcosβ – r sinθsinβ …………. (3)
Q1 = r sin (θ+β) = r cosθsinβ + r sinθcosβ …………. (4)
By using equation (1) (2) (3) (4), we will get-
P1= P0 cosθ – P0 sinθ
Q1= P0 sinθ + P0 cosθ
We can also represent the Rotation in the form of matrix as:-
5|Page
Homogeneous Coordinates Representation: The Rotation can also be represented in the form of
3 x 3 Rotation matrix as:-
Example– A line segment with the starting point (0, 0) and ending points (5, 5). Apply 30-degree
rotation anticlockwise direction on the line. Find the new coordinates of the line?
Solution– We can rotate the straight line by its endpoints with the same angle.
We have,
(P0, Q0) = (0, 0)
Rotation Angle (θ) = 30°
Let the new coordinates of line = (P1, Q1)
We can apply the rotation matrix, then,
P1= P0 x cosθ – Q0 x sinθ
= 5 x cos30 – 5 x sin30
= 5 x( √3/2) – 5 x (1/2)
= 4.33 – 2.5
= 1.83
Q1= P0 x sinθ + Q0 x cosθ
= 5 x sin30 + 5 x cos30
= 5 x (1/2) + 5 x( √3/2)
= 2.5 + 4.33 = 6.83
6|Page
Figure 5: Point rotation example
Thus, the new endpoint coordinates of the line are = (P1, Q1) = (1.83, 6.83)
Computer Graphics 2D Scaling:
In scaling, we can expend or compress the size of any object. We can apply scaling on the object
by multiplying the original coordinates with scaling factors.
The term scaling factor is used to define whether the size of an object is increased or decreased.
We can represent the scaling factor by ‘Sx’ for the x- axis and ‘Sy’ for the y-axis.
For Example– If we want to scale an object that has R (P0, Q0) coordinate and the new coordinates
of an object are R` (P1, Q1) then the equation will be-
P1 = P0. Sx
Q1 = Q0. Sy
7|Page
Homogeneous Coordinates Representation: The scaling is also represented in the form of 3 x 3
matrix-
Example: A Square object with the coordinate points P (1, 4), Q (4, 4), R (4, 1), T (1,1). Apply
the scaling factor 3 on the X-axis and 4 on the Y-axis. Find out the new coordinates of the square?
Solution: We have coordinates Points for Square = P (1, 4), Q (4, 4), R (4, 1), S (1, 1)
Scaling factor along with X axis (Sx) = 3
Scaling factor along with Y axis (Sy)= 4
Applying the equation to find the new coordinates-
For Coordinate P (1, 4)–
Let the new Coordinate for P = (P1, Q1)
P1 = P0. Sx = 1 x 3 = 3
Q1 = Q0. Sy = 4 x 4 = 16
The new Coordinates = (3, 16)
For Coordinate Q (4, 4)–
Let the new Coordinate for Q = (P,1 Q1)
P1 = P0. Sx = 4 x 3 = 12
Q1 = Q0. Sy = 4 x 4 = 16
The new Coordinates = (12, 16)
For Coordinate R (4, 1)–
Let the new Coordinate for R = (P1, Q1)
P1 = P0. Sx = 4 x 3 = 12
Q1 = Q0. Sy = 1 x 4 = 4
8|Page
The new Coordinates = (12, 4)
For Coordinate S (1, 1)–
Let the new Coordinate for S = (P1, Q1)
P1 = P0. Sx = 1 x 3 = 3
Q1 = Q0. Sy = 1 x 4 = 4
The new Coordinates = (3, 4)
Thus, the new coordinates for square after scaling = P (3, 16), Q (12, 16), R (12, 4), S (3, 4).
2D Reflection Computer Graphics:
The Reflection is a mirror image of the original object. In the Reflection process, the size of the
object does not change.
We can represent Reflection by using four ways:-
9|Page
1. Reflection along X-axis: In this kind of Reflection, the value of X is positive, and the value
of Y is negative.
We can represent the Reflection along x-axis by following equation-
X1 = X0
Y1 = –Y0
We can also represent Reflection in the form of matrix:
Homogeneous Coordinate Representation: We can also represent the Reflection along x-axis in
the form of 3 x 3 matrix-
2. Reflection along Y-axis: In this kind of Reflection, the value of X is negative, and the value of
Y is positive.
We can represent the Reflection along y-axis by following equation-
10 | P a g e
X1 = –X0
Y1 = Y0
We can also represent Reflection in the form of matrix:
Homogeneous Coordinate Representation: We can also represent the Reflection along x-axis in
the form of 3 x 3 matrix-
3. Reflection perpendicular to XY plane: In this kind of Reflection, the value of both X and Y
is negative.
We can represent the Reflection along y-axis by following equation-
X1 = –X0
Y1 = –Y0
11 | P a g e
We can also represent Reflection in the form of matrix:
Homogeneous Coordinate Representation: We can also represent the Reflection along with x-
axis in the form of 3 x 3 matrix-
4. Reflection along with the line: In this kind of Reflection, the value of X is equal to the value
of Y.
We can represent the Reflection along y-axis by following equation-
Y=X, then the points are (Y, X)
Y= –X, then the points are (–Y, –X)
We can also represent Reflection in the form of matrix:
12 | P a g e
Homogeneous Coordinate Representation: We can also represent the Reflection along with x-
axis in the form of 3 x 3 matrix-
13 | P a g e
Figure 12: Object shearing
2. Shearing along y-axis: In this, we can store the x coordinate and only change the y coordinate.
It is also called “Vertical Shearing.”
We can represent Vertical Shearing by the following equation-
X1 = X0
Y1 = Y0 + SHy. X0
We can represent Vertical Shearing in the form of matrix:-
Homogeneous Coordinate Representation: The 3×3 matrix for Vertical Shearing is given
below-
14 | P a g e
Figure 13: Object shearing example
Example: A Triangle with (2, 2), (0, 0) and (2, 0). Apply Shearing factor 2 on X-axis and 2 on Y-
axis. Find out the new coordinates of the triangle?
Solution: We have,
The coordinates of triangle = P (2, 2), Q (0, 0), R (2, 0)
Shearing Factor for X-axis = 2
Shearing Factor for Y-axis = 2
Now, apply the equation to find the new coordinates.
Shearing for X-axis:
For Coordinate P (2, 2)-
Let the new coordinate for P = (X1, Y1)
X1 = X0 + SHx. Y0 = 2 + 2 x 2 = 6
Y1 = Y0 = 2
The New Coordinates = (6, 2)
For Coordinate Q (0, 0)-
Let the new coordinate for Q = (X1, Y1)
X1 = X0 + SHx. Y0 = 0 + 2 x 0 = 0
Y1 = Y0 = 0
The New Coordinates = (0, 0)
For Coordinate R (2, 0)-
15 | P a g e
Let the new coordinate for R = (X1, Y1)
X1 = X0 + SHx. Y0 = 2 + 2 x 0 = 2
Y1 = Y0 = 0
The New Coordinates = (2, 0)
The New coordinates of triangle for x-axis = (6, 2), (0, 0), (2, 0)
16 | P a g e
The New Coordinates = (0, 0)
For Coordinate R (2, 0)-
Let the new coordinate for R = (X1, Y1)
X1 = X0 = 2
Y1 = Y0 + Shy. X0 = 0 +2 x 2 = 4
The New Coordinates = (2, 4)
The New coordinates of triangle for y-axis = (2, 6), (0, 0), (2, 4)
3D Translation:
A 3DTranslation process contains the x-axis, y-axis, and z-axis. We can move any object from one
place to another without changing the shape of the object.
For Example-
Translation of a Point: If we want to translate a point from P (x0, y0, z0) to Q (x1, y1, z1), then we
have to add Translation coordinates (Tx, Ty, Tz) with original coordinates.
17 | P a g e
We can also represent the 3D Translation in matrix form:-
Here Translation coordinates (Tx, Ty, Tz) are also called “Translation or Shift Vector.”
Example: A Point has coordinates P (1, 2, 3) in x, y, z-direction. Apply the translation with a
distance of 2 towards x-axis, 3 towards y-axis, and 4 towards the z-axis. Find the new coordinates
of the point?
Solution: We have,
Point P = (x0, y0, z0) = (1,2,3)
Shift Vector = (Tx, Ty, Tz)
Let us assume the new coordinates of P = (x1, y1, z1)
Now we are going to add translation vector and given coordinates, then
X1 = x0 + Tx = (1 + 2) = 3
Y1 = y0 + Ty = (2 + 3) = 5
Z1 = z0 + Tz = (3 + 4) = 7
Thus, the new coordinates are = (3, 5, 7)
3D Rotation in Computer Graphics:
18 | P a g e
The 3D rotation is different from 2D rotation. In 3D Rotation we also have to define the angle of
Rotation with the axis of Rotation.
For Example-Let us assume,
The initial coordinates of an object = (x0, y0, z0)
The Initial angle from origin = β
The Rotation angle = θ
The new coordinates after Rotation = (x1, y1, z1)
In Three-dimensional plane we can define Rotation by following three ways–
1. X-axis Rotation: We can rotate the object along x-axis. We can rotate an object by using
following equation-
X1 = x0
Y1 = y0 cosθ– z0 x sinθ
Z1 = y0 x sinθ+ z0 x cosθ
We can represent 3D rotation in the form of matrix-
19 | P a g e
Figure 17: Rotation along with x-axis
2. Y-axis Rotation: We can rotate the object along y-axis. We can rotate an object by using
following equation-
x1 = z0 x sinθ + x0 x cosθ
y1 = y0
z1 = y0 x cosθ– x0 x sinθ
We can represent 3D rotation in the form of matrix–
20 | P a g e
Figure 18: Rotation along with y-axis
3. Z-axis Rotation: We can rotate the object along z-axis. We can rotate an object by using
following equation-
x1 = x0 x cosθ– y0 x sinθ
y1 = x0 x sinθ + y0 x cosθ
z1 = z0
We can represent 3D rotation in the form of matrix–
21 | P a g e
Figure 19: Rotation along with z-axis
Example: A Point has coordinates P (2, 3, 4) in x, y, z-direction. The Rotation angle is 90 degrees.
Apply the rotation in x, y, z direction, and find out the new coordinates of the point?
Solution: The initial coordinates of point = P (x0, y0, z0) = (2, 3, 4)
Rotation angle (θ) = 90°
For x-axis
Let the new coordinates = (x1, y1, z1) then,
x1= x0 = 2
y1= y0 x cosθ – z0 x sinθ = 3 x cos90°– 4 x sin90° = 3 x 0 – 4 x 1 = -4
z1= y0 x sinθ + z0 x cosθ = 3 x sin90°+ 4 x cos90° = 3 x 1 + 4 x 0 = 3
The new coordinates of point = (2, -4, 3)
For y-axis
Let the new coordinates = (x1, y1, z1) then,
X1= z0 x sinθ + x0 x cosθ = 4 x sin90° + 2 x cos90° = 4 x 1 + 2 x 0 = 4
y1= y0 = 3
z1= y0 x cos&θ – x0 x sinθ = 3 x cos90°– 2 x sin90° = 3 x 0 – 4 x 0 = 0
22 | P a g e
z1= z0 =4
The New Coordinates of points = (3, 2, 4)
3D Scaling:
The 2D and 3D scaling are similar, but the key difference is that the 3D plane also includes the z-
axis along with the x and y-axis.
In scaling, we can expend or compress the size of any object. We can apply scaling on the object
by multiplying the original coordinates with scaling factors.
The term scaling factor is used to define whether the size of the object is increased or decreased.
We can represent the scaling factor by ‘Sx’ for the x-axis, ‘Sy’ for the y-axis, and ‘Sz’ for the z-
axis.
The increment and decrement of an object is depends on two conditions. They are,
If scaling factor (Sx, Sy, Sz) > 1, then the size of the object increased.
If scaling factor (Sx, Sy, Sz) < 1, then the size of the object decreased.
For Example: Let us assume,
The initial coordinates of object = P (x0, y0, z0)
Scaling factor for x-axis = Sx
Scaling factor for y-axis = Sy
Scaling factor for z-axis = Sz
The coordinates after Scaling = Q (x1, y1, z1)
We can represent the 3D Scaling in the form of equation:
X1 = x0. Sx
Y1 = y0. Sy
Z1 = z0. Sz
23 | P a g e
Figure 20: 3D scaling
Example: A 3D object that have coordinates points P(1, 4, 4), Q(4, 4, 6), R(4, 1, 2), T(1, 1, 1) and
the scaling parameters are 3 along with x-axis, 4 along with y-axis and 4 along with z-axis. Apply
scaling to find the new coordinates of the object?
Solution: we have,
The initial coordinates of object = P (1, 4, 4), Q (4, 4, 6), R (4, 1, 2), S (1, 1, 1)
Scaling factor along with x-axis (Sx) = 3
Scaling factor along with y-axis (Sy) = 4
Scaling factor along with z-axis (Sz) = 4
Let the new coordinates after scaling = (x1, y1, z1)
For coordinate P-
x1 = x0 x Sx = 1 x 3 = 3
y1 = y0 x Sy = 4 x 4 = 16
z1 = z0 x Sz = 4 x 4 = 16
The new coordinates = (3, 16, 16)
24 | P a g e
For coordinate Q
x1 = x0 x Sx = 4 x 3 = 12
y1 = y0 x Sy = 4 x 4 = 16
z1 = z0 x Sz = 6 x 4 = 24
The new coordinates = (12, 16, 24)
For coordinate R
x1 = x0 x Sx = 4 x 3 = 12
y1 = y0 x Sy = 1 x 4 = 4
z1 = z0 x Sz = 2 x 4 = 8
The new coordinates = (12, 4, 8)
For coordinate S
x1 = x0 x Sx = 1 x 3 = 3
y1 = y0 x Sy = 1 x 4 = 4
z1 = z0 x Sz = 1 x 4 = 4
The new coordinates = (3, 4, 4)
Thus, the new coordinates after scaling = P (3, 16, 16), Q (12, 16, 24), R (12, 4, 8), S (3, 4, 4).
3D Reflection:
The Reflection is a mirror image of the original object. We can differentiate 2D and 3D reflection
by adding Z-axis. The Z-axis shows the depth of the surface. In the Reflection process, the size of
the object does not change.
We can represent Reflection by using the following three ways:
1. Reflection along with xy Plane: In the xy plane reflection, the value of z is negative.
x1 = x0
y1 = y0
z1 = –z0
25 | P a g e
Matrix of 3D Reflection:
2. Reflection along with xz Plane: In the xz plane reflection the value of y is negative.
x1 = x0
y1 = -y0
z1 = z0
Matrix of 3D Reflection:
3. Reflection along with yz Plane: In the yz plane reflection the value of x is negative.
x1 = -x0
y1 = y0
z1 = z0
26 | P a g e
Figure 23: Reflection along with yz plane
Matrix of 3D Reflection:
Example: A 3D triangle with coordinates points P (4, 5, 2), Q (7, 5, 3), R (6, 7, 4). Apply reflection
on xy plane and find the new coordinates of triangle?
Solution: We have,
The initial coordinates of triangle = P (4, 5, 2), Q (7, 5, 3), R (6, 7, 4)
Reflection Plane = xy
Let the new coordinates of triangle = (x1, y1, z)
For Coordinate P (4, 5, 2)
X1 = x0 = 4
y1 = y0 = 5
z1 = -z0= -2
The new coordinates = (4, 5, -2)
For Coordinate Q (7, 5, 3)
X1 = x0 = 7
Y1 = y0 = 5
Z1 = -z0= -3
The new coordinates = (7, 5, -3)
27 | P a g e
For Coordinate P (6, 7, 4)
X1 = x0 = 6
y1 = y0 = 7
z1 = -z0= -4
The new coordinates = (6, 7, 4)
3D Shearing in Computer Graphics:
We can denote shearing with ‘SHx,’ ‘SHy,’ and ‘SHz.’ These ‘SHx,’ ‘SHy,’ ‘SHz’ are
called “Shearing factor.”
The basic difference between 2D and 3D Shearing is that the 3D plane also includes the z-axis.
28 | P a g e
x1 = x0
y1 = y0 + SHy. x0
z1 = z0 + SHz. x0
3D Shearing Matrix:
2. Shearing along the y-axis: In this, we can store the y coordinate and only change the x and z
coordinate.
We can represent shearing along with y-axis by the following equation-
x1 = x0 + SHx. y0
y1 = y0
z1 = z0 + SHz. y0
3D Shearing Matrix:
3. Shearing along with z-axis: In this, we can store the z coordinate and only change the x and y
coordinate.
We can represent shearing along with z-axis by the following equation-
x1 = x0 + SHx. z0
y1 = y0 + SHy. Z0
z1 = z0
3D Shearing Matrix:
29 | P a g e
30 | P a g e