Department of
Computer Science and Engineering
UNIT 2
School of Computing
Vel Tech Rangarajan Dr. Sagunthala R&D Institute of
Science and Technology
Transformation is a process of modifying and re-positioning the existing graphics.
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.
28-09-2021 Department of Computer Science and Engineering 2
Transformation Techniques-
In computer graphics, various transformation techniques are-
28-09-2021 Department of Computer Science and Engineering 3
2D Translation in Computer Graphics-
2D Translation is a process of moving an object from one position
to another in a two dimensional plane.
Consider a point object O has to be moved from one position to
another in a 2D plane.
Let-
•Initial coordinates of the object O = (Xold, Yold)
•New coordinates of the object O after translation = (Xnew, Ynew)
•Translation vector or Shift vector = (T x, Ty)
Given a Translation vector (Tx, Ty)-
•Tx defines the distance the Xold coordinate has to be moved.
•Ty defines the distance the Yold coordinate has to be moved.
28-09-2021 Department of Computer Science and Engineering 4
This translation is achieved by adding the translation coordinates to
the old coordinates of the object as-
•Xnew = Xold + Tx (This denotes translation towards X axis)
•Ynew = Yold + Ty (This denotes translation towards Y axis)
28-09-2021 Department of Computer Science and Engineering 5
In Matrix form, the above translation equations may be represented as-
28-09-2021 Department of Computer Science and Engineering 6
•The homogeneous coordinates representation of (X, Y) is (X, Y, 1).
•Through this representation, all the transformations can be performed using matrix / vector multiplications.
The above translation matrix may be represented as a 3 x 3 matrix as-
28-09-2021 Department of Computer Science and Engineering 7
Given a circle C with radius 10 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.
Solution-
Given-
Old center coordinates of C = (Xold, Yold) = (1, 4)
Translation vector = (T x, Ty) = (5, 1)
Let the new center coordinates of C = (Xnew, Ynew).
Applying the translation equations, we have-
Xnew = Xold + Tx = 1 + 5 = 6
Ynew = Yold + Ty = 4 + 1 = 5
Thus, New center coordinates of C = (6, 5).
28-09-2021 Department of Computer Science and Engineering 8
Alternatively,
In matrix form, the new center coordinates of C after
translation may be obtained as-
Thus, New center coordinates of C =
28-09-2021(6, 5). Department of Computer Science and Engineering 9
28-09-2021 Department of Computer Science and Engineering 10
Given a square with coordinate points A(0, 3), B(3, 3), C(3, 0), D(0, 0).
Apply the translation with distance 1 towards X axis and 1 towards Y
axis. Obtain the new coordinates of the square.
Solution-
Given-
•Old coordinates of the square = A (0, 3), B(3, 3), C(3, 0), D(0, 0)
•Translation vector = (Tx, Ty) = (1, 1)
For Coordinates A(0, 3)
Let the new coordinates of corner A = (Xnew, Ynew).
Applying the translation equations, we have-
•Xnew = Xold + Tx = 0 + 1 = 1
•Ynew = Yold + Ty = 3 + 1 = 4
Thus, New coordinates of corner A = (1, 4).
28-09-2021 Department of Computer Science and Engineering 11
For Coordinates B(3, 3)
Let the new coordinates of corner B = (Xnew, Ynew).
Applying the translation equations, we have-
•Xnew = Xold + Tx = 3 + 1 = 4
•Ynew = Yold + Ty = 3 + 1 = 4
Thus, New coordinates of corner B = (4, 4).
For Coordinates C(3, 0)
Let the new coordinates of corner C = (Xnew, Ynew).
Applying the translation equations, we have-
•Xnew = Xold + Tx = 3 + 1 = 4
•Ynew = Yold + Ty = 0 + 1 = 1
Thus, New coordinates of corner C = (4, 1).
28-09-2021 Department of Computer Science and Engineering 12
For Coordinates D(0, 0)
Let the new coordinates of corner D = (Xnew, Ynew).
Applying the translation equations, we have-
•Xnew = Xold + Tx = 0 + 1 = 1
•Ynew = Yold + Ty = 0 + 1 = 1
Thus, New coordinates of corner D = (1, 1).
Thus, New coordinates of the square = A (1, 4), B(4, 4), C(4, 1), D(1, 1).
28-09-2021 Department of Computer Science and Engineering 13
2D Rotation in Computer Graphics-
2D Rotation is a process of rotating an object with respect to an angle in a two
dimensional plane.
Consider a point object O has to be rotated from one angle to another in a 2D
plane.
Let-
•Initial coordinates of the object O = (Xold, Yold)
•Initial angle of the object O with respect to origin = Φ
•Rotation angle = θ
•New coordinates of the object O after rotation = (Xnew, Ynew)
28-09-2021 Department of Computer Science and Engineering 14
This rotation is achieved by using the following rotation
equations-
•Xnew = Xold x cosθ – Yold x sinθ
•Ynew = Xold x sinθ + Yold x cosθ
In Matrix form, the above rotation equations may be
represented as-
28-09-2021 Department of Computer Science and Engineering 15
• For homogeneous coordinates, the above
rotation matrix may be represented as a 3 x 3
matrix as-
•
28-09-2021 Department of Computer Science and Engineering 16
Given a line segment with starting point as (0, 0) and ending point as (4, 4). Apply 30 degree rotation
anticlockwise direction on the line segment and find out the new coordinates of the line.
Solution-
We rotate a straight line by its end points
with the same angle. Then, we re-draw a
line between the new end points.
Given-
•Old ending coordinates of the line = (Xold,
Yold) = (4, 4)
•Rotation angle = θ = 30º
Let new ending coordinates of the line after
rotation = (Xnew, Ynew).
28-09-2021 Department of Computer Science and Engineering 17
Applying the rotation equations, we have-
Xnew
= Xold x cosθ – Yold x sinθ
= 4 x cos30º – 4 x sin30º
= 4 x (√3 / 2) – 4 x (1 / 2)
= 2√3 – 2
= 2(√3 – 1)
= 2(1.73 – 1)
= 1.46
Ynew
= Xold x sinθ + Yold x cosθ
= 4 x sin30º + 4 x cos30º
= 4 x (1 / 2) + 4 x (√3 / 2)
= 2 + 2√3
= 2(1 + √3)
= 2(1 + 1.73)
= 5.46
Thus, New ending coordinates of the line after rotation =
28-09-2021 (1.46, 5.46). Department of Computer Science and Engineering 18
Alternatively,
In matrix form, the new ending coordinates of the line after rotation may be obtained as-
28-09-2021 Department of Computer Science and Engineering 19
Thus, New ending coordinates of the line after rotation = (1.46, 5.46).
28-09-2021 Department of Computer Science and Engineering 20
Given a triangle with corner coordinates (0, 0), (1, 0) and
(1, 1). Rotate the triangle by 90 degree anticlockwise
direction and find out the new coordinates.
Solution-
We rotate a polygon by rotating each vertex of it with the
same rotation angle.
Given-
•Old corner coordinates of the triangle = A (0, 0), B(1, 0),
C(1, 1)
•Rotation angle = θ = 90º
28-09-2021 Department of Computer Science and Engineering 21
For Coordinates A(0, 0)
Let the new coordinates of corner A
after rotation = (Xnew, Ynew).
Applying the rotation equations, we
have-
Xnew
= Xold x cosθ – Yold x sinθ
= 0 x cos90º – 0 x sin90º
=0
Ynew
= Xold x sinθ + Yold x cosθ
= 0 x sin90º + 0 x cos90º
=0
Thus, New coordinates of corner A
after rotation = (0, 0).
28-09-2021 Department of Computer Science and Engineering 22
For Coordinates B(1, 0)
Let the new coordinates of corner B after rotation
= (Xnew, Ynew).
Xnew
= Xold x cosθ – Yold x sinθ
= 1 x cos90º – 0 x sin90º
=0
Ynew
= Xold x sinθ + Yold x cosθ
= 1 x sin90º + 0 x cos90º
=1+0
=1
Thus, New coordinates of corner B after rotation
= (0, 1).
28-09-2021 Department of Computer Science and Engineering 23
For Coordinates C(1, 1)
Let the new coordinates of corner C after
rotation = (Xnew, Ynew).
Xnew
= Xold x cosθ – Yold x sinθ
= 1 x cos90º – 1 x sin90º
=0–1
= -1
Ynew
= Xold x sinθ + Yold x cosθ
= 1 x sin90º + 1 x cos90º
=1+0
=1
Thus, New coordinates of corner C after
rotation = (-1, 1).
28-09-2021 Department of Computer Science and Engineering 24
Thus, New coordinates of the triangle after rotation = A (0, 0), B(0, 1), C(-1, 1).
28-09-2021 Department of Computer Science and Engineering 25
2D Scaling in Computer Graphics-
In computer graphics, scaling is a process of modifying or altering the
size of objects.
•Scaling may be used to increase or reduce the size of object.
•Scaling subjects the coordinate points of the original object to change.
•Scaling factor determines whether the object size is to be increased or
reduced.
•If scaling factor > 1, then the object size is increased.
•If scaling factor < 1, then the object size is reduced.
28-09-2021 Department of Computer Science and Engineering 26
Let-
•Initial coordinates of the object O = (Xold, Yold)
•Scaling factor for X-axis = Sx
•Scaling factor for Y-axis = Sy
•New coordinates of the object O after scaling = (Xnew,
Ynew)
This scaling is achieved by using the following scaling
equations-
•Xnew = Xold x Sx
•Ynew = Yold x Sy
28-09-2021 Department of Computer Science and Engineering 27
In Matrix form, the above scaling equations may be represented
as-
28-09-2021 Department of Computer Science and Engineering 28
In Matrix form, the above scaling equations may be represented as-
28-09-2021 Department of Computer Science and Engineering 29
Given a square object with coordinate
points A(0, 3), B(3, 3), C(3, 0), D(0, 0).
Apply the scaling parameter 2 towards X
axis and 3 towards Y axis and obtain the
new coordinates of the object.
Solution-
Given-
•Old corner coordinates of the square = A
(0, 3), B(3, 3), C(3, 0), D(0, 0)
•Scaling factor along X axis = 2
•Scaling factor along Y axis = 3
28-09-2021 Department of Computer Science and Engineering 30
For Coordinates A(0, 3)
Let the new coordinates of corner A after scaling =
(Xnew, Ynew).
Applying the scaling equations, we have-
•Xnew = Xold x Sx = 0 x 2 = 0
•Ynew = Yold x Sy = 3 x 3 = 9
Thus, New coordinates of corner A after scaling = (0, 9).
28-09-2021 Department of Computer Science and Engineering 31
For Coordinates B(3, 3)
Let the new coordinates of corner B after scaling = (Xnew,
Ynew).
Applying the scaling equations, we have-
•Xnew = Xold x Sx = 3 x 2 = 6
•Ynew = Yold x Sy = 3 x 3 = 9
Thus, New coordinates of corner B after scaling = (6, 9).
28-09-2021 Department of Computer Science and Engineering 32
For Coordinates C(3, 0)
Let the new coordinates of corner C after
scaling = (Xnew, Ynew).
Applying the scaling equations, we have-
•Xnew = Xold x Sx = 3 x 2 = 6
•Ynew = Yold x Sy = 0 x 3 = 0
Thus, New coordinates of corner C after
scaling = (6, 0).
28-09-2021 Department of Computer Science and Engineering 33
For Coordinates D(0, 0)
Let the new coordinates of corner D after
scaling = (Xnew, Ynew).
Applying the scaling equations, we have-
•Xnew = Xold x Sx = 0 x 2 = 0
•Ynew = Yold x Sy = 0 x 3 = 0
Thus, New coordinates of corner D after
scaling = (0, 0).
28-09-2021 Department of Computer Science and Engineering 34
Thus, New coordinates of the square after scaling = A (0, 9), B(6, 9), C(6, 0), D(0, 0).
28-09-2021 Department of Computer Science and Engineering 35
2D Reflection in Computer Graphics-
•Reflection is a kind of rotation where the
angle of rotation is 180 degree.
•The reflected object is always formed on
the other side of mirror.
•The size of reflected object is same as the
size of original object.
28-09-2021 Department of Computer Science and Engineering 36
Consider a point object O has to be
reflected in a 2D plane.
Let-
•Initial coordinates of the object O = (Xold,
Yold)
•New coordinates of the reflected object O
after reflection = (Xnew, Ynew)
28-09-2021 Department of Computer Science and Engineering 37
• Reflection On X-Axis:
•
• This reflection is achieved by using the following
reflection equations-
• Xnew = Xold
In Matrix form, the above reflection equations may be represented as-
• Ynew = -Yold
28-09-2021 Department of Computer Science and Engineering 38
For homogeneous coordinates, the above reflection matrix may be represented as a 3 x 3 matrix as-
28-09-2021 Department of Computer Science and Engineering 39
Reflection On Y-Axis:
This reflection is achieved by using the following reflection equations-
•Xnew = -Xold
•Ynew = Yold
In Matrix form, the above reflection equations may be represented as-
28-09-2021 Department of Computer Science and Engineering 40
For homogeneous coordinates, the above reflection matrix may be represented as a 3 x 3 matrix as-
28-09-2021 Department of Computer Science and Engineering 41
Problem-01:
Given a triangle with coordinate points A(3,
4), B(6, 4), C(5, 6). Apply the reflection on
the X axis and obtain the new coordinates
of the object.
Solution-
Given-
•Old corner coordinates of the triangle = A
(3, 4), B(6, 4), C(5, 6)
•Reflection has to be taken on the X axis
28-09-2021 Department of Computer Science and Engineering 42
For Coordinates A(3, 4)
Let the new coordinates of corner A after reflection = (Xnew,
Ynew).
Applying the reflection equations, we have-
•Xnew = Xold = 3
•Ynew = -Yold = -4
Thus, New coordinates of corner A after reflection = (3, -4).
For Coordinates B(6, 4)
Let the new coordinates of corner B after reflection = (Xnew,
Ynew).
Applying the reflection equations, we have-
•Xnew = Xold = 6
•Ynew = -Yold = -4
28-09-2021 Department of of
Thus, New coordinates Computer
cornerScience
B afterand Engineering
reflection = (6, -4). 43
• For Coordinates C(5, 6)
•
• Let the new coordinates of corner C after reflection = (Xnew,
Ynew).
•
• Applying the reflection equations, we have-
• Xnew = Xold = 5
• Ynew = -Yold = -6
•
• Thus, New coordinates of corner C after reflection = (5, -6).
•
• Thus, New coordinates of the triangle after reflection = A (3, -
4), B(6, -4), C(5, -6).
•
28-09-2021 Department of Computer Science and Engineering 44
28-09-2021 Department of Computer Science and Engineering 45
In Computer graphics,
2D Shearing is an ideal technique to change the shape of
an
In a two existing
dimensional object
plane, insize
the object a can
twobe dimensional plane.
changed along X direction as well as Y direction.
So, there are two versions of shearing-
1.Shearing in X direction
2.Shearing in Y direction
28-09-2021 Department of Computer Science and Engineering 46
Consider a point object O has to be sheared in a 2D plane.
Let-
•Initial coordinates of the object O = (Xold, Yold)
•Shearing parameter towards X direction = Shx
•Shearing parameter towards Y direction = Sh y
•New coordinates of the object O after shearing = (Xnew, Ynew)
Shearing in X Axis-
Shearing in X axis is achieved by using the following shearing
equations-
•Xnew = Xold + Shx x Yold
•Ynew = Yold
28-09-2021 Department of Computer Science and Engineering 47
In Matrix form, the above shearing
equations may be represented as-
28-09-2021 Department of Computer Science and Engineering 48
For homogeneous coordinates, the above shearing matrix may be represented as a 3 x 3 matrix as-
28-09-2021 Department of Computer Science and Engineering 49
Shearing in Y Axis-
Shearing in Y axis is achieved by using the following shearing equations-
•Xnew = Xold
•Ynew = Yold + Shy x Xold
In Matrix form, the above shearing equations may be represented as-
28-09-2021 Department of Computer Science and Engineering 50
For homogeneous coordinates, the above shearing matrix may be represented as a 3 x 3 matrix as-
28-09-2021 Department of Computer Science and Engineering 51
Given a triangle with points (1, 1), (0, 0) and (1, 0). Apply shear parameter 2 on
X axis and 2 on Y axis and find out the new coordinates of the object.
Solution-
Given-
•Old corner coordinates of the triangle = A (1, 1), B(0, 0), C(1, 0)
•Shearing parameter towards X direction (Shx) = 2
•Shearing parameter towards Y direction (Shy) = 2
Shearing in X Axis-
For Coordinates A(1, 1)
Let the new coordinates of corner A after shearing = (Xnew, Ynew).
Applying the shearing equations, we have-
•Xnew = Xold + Shx x Yold = 1 + 2 x 1 = 3
•Ynew = Yold = 1
Thus, New coordinates of corner A after shearing = (3, 1).
28-09-2021 Department of Computer Science and Engineering 52
For Coordinates B(0, 0)
Let the new coordinates of corner B after shearing = (Xnew, Ynew).
Applying the shearing equations, we have-
•Xnew = Xold + Shx x Yold = 0 + 2 x 0 = 0
•Ynew = Yold = 0
Thus, New coordinates of corner B after shearing = (0, 0).
For Coordinates C(1, 0)
Let the new coordinates of corner C after shearing = (Xnew, Ynew).
Applying the shearing equations, we have-
•Xnew = Xold + Shx x Yold = 1 + 2 x 0 = 1
•Ynew = Yold = 0
Thus, New coordinates of corner C after shearing = (1, 0).
Thus, New coordinates of the triangle after shearing in X axis = A (3, 1), B(0, 0), C(1,
0). Department of Computer Science and Engineering
28-09-2021 53
Shearing in Y Axis-
For Coordinates A(1, 1)
Let the new coordinates of corner A after shearing = (Xnew, Ynew).
Applying the shearing equations, we have-
•Xnew = Xold = 1
•Ynew = Yold + Shy x Xold = 1 + 2 x 1 = 3
Thus, New coordinates of corner A after shearing = (1, 3).
For Coordinates B(0, 0)
Let the new coordinates of corner B after shearing = (Xnew, Ynew).
Applying the shearing equations, we have-
•Xnew = Xold = 0
•Ynew = Yold + Shy x Xold = 0 + 2 x 0 = 0
Thus, New coordinates of corner B after shearing = (0, 0).
28-09-2021 Department of Computer Science and Engineering 54
For Coordinates C(1, 0)
Let the new coordinates of corner C after shearing = (Xnew, Ynew).
Applying the shearing equations, we have-
•Xnew = Xold = 1
•Ynew = Yold + Shy x Xold = 0 + 2 x 1 = 2
Thus, New coordinates of corner C after shearing = (1, 2).
Thus, New coordinates of the triangle after shearing in Y axis = A (1, 3), B(0, 0), C(1, 2).
Shear along yaxis
28-09-2021
Shear alongDepartment of Computer Science and Engineering 55
xaxis
Window to Viewport Transformation in
Computer Graphics with
Implementation
Window to Viewport Transformation is the process of
transforming 2D world-coordinate objects to device
coordinates. Objects inside the world or clipping window are
mapped to the viewport which is the area on the screen where
world coordinates are mapped to be displayed.
28-09-2021 Department of Computer Science and Engineering 56
General Terms:
•World coordinate – It is the Cartesian coordinate w.r.t which we
define the diagram, like Xwmin, Xwmax, Ywmin, Ywmax
•Device Coordinate –It is the screen coordinate where the objects
are to be displayed, like Xvmin, Xvmax, Yvmin, Yvmax
•Window –It is the area on world coordinate selected for display.
•ViewPort –It is the area on the device coordinate where graphics
is to be displayed.
28-09-2021 Department of Computer Science and Engineering 57
Mathematical Calculation of Window to Viewport:
It may be possible that the size of the Viewport is much smaller or greater than the Window. In
these cases, we have to increase or decrease the size of the Window according to the Viewport
and for this, we need some mathematical calculations.
(xw, yw): A point on Window (xv, yv): Corresponding point on Viewport
•we have to calculate the point (xv, yv)
28-09-2021 Department of Computer Science and Engineering 58
•Now the relative position of the object in
Window and Viewport are same.
For xcoordinate
For y coordinate,
28-09-2021 Department of Computer Science and Engineering 59
•so, after calculating for x and y coordinate, we get
where sx is the scaling factor of x
coordinate and sy is the scaling factor of y
coordinate
28-09-2021 Department of Computer Science and Engineering 60
Example:
Lets assume,
•for window, Xwmin = 20, Xwmax = 80, Ywmin = 40, Ywmax = 80.
•for viewport, Xvmin = 30, Xvmax = 60, Yvmin = 40, Yvmax = 60.
•Now a point ( Xw, Yw ) be ( 30, 80 ) on the window. We have to calculate that point on the viewport
i.e ( Xv, Yv ).
•First of all, calculate the scaling factor of x coordinate Sx and the scaling factor of y coordinate Sy using the above-mentioned formula.
Sx = ( 60 - 30 ) / ( 80 - 20 ) = 30 / 60 Sy = ( 60 - 40 ) / ( 80 - 40 ) = 20 / 40
•So, now calculate the point on the viewport ( Xv, Yv ).
Xv = 30 + ( 30 - 20 ) * ( 30 / 60 ) = 35 Yv = 40 + ( 80 - 40 ) * ( 20 / 40 ) = 60
•So, the point on window ( Xw, Yw ) = ( 30, 80 ) will be ( Xv, Yv ) = ( 35, 60 ) on viewport.
28-09-2021 Department of Computer Science and Engineering 61
Clipping:
When we have to display a large portion of the picture, then not only
scaling & translation is necessary, the visible part of picture is also
identified. This process is not easy. Certain parts of the image are
inside, while others are partially inside. The lines or elements which are
partially visible will be omitted.
For deciding the visible and invisible portion, a particular process called
clipping is used. Clipping determines each element into the visible and
invisible portion. Visible portion is selected. An invisible portion is
discarded.
28-09-2021 Department of Computer Science and Engineering 62
Types of Lines:
Lines are of three types:
1.Visible: A line or lines entirely inside the window is considered
visible
2.Invisible: A line entirely outside the window is considered
invisible
3.Clipped: A line partially inside the window and partially outside
is clipped. For clipping point of intersection of a line with the
window is determined.
28-09-2021 Department of Computer Science and Engineering 63
28-09-2021 Department of Computer Science and Engineering 64
The window against which object is clipped called a clip window. It can be curved or rectangle in shape.
28-09-2021 Department of Computer Science and Engineering 65
Applications of clipping:
1.It will extract part we desire.
2.For identifying the visible and invisible
area in the 3D object.
3.For creating objects using solid
modeling.
4.For drawing operations.
5.Operations related to the pointing of an
object.
6.For deleting, copying, moving part of an
object.
Clipping can be applied to world co-
ordinates. The contents inside the window
will be mapped to device co-ordinates.
Another alternative is a complete world co-
ordinates picture is assigned to device co-
ordinates, and then clipping of viewport
boundaries is done.
28-09-2021 Department of Computer Science and Engineering 66
Types of Clipping:
1.Point Clipping
2.Line Clipping
3.Area Clipping (Polygon)
4.Curve Clipping
5.Text Clipping
6.Exterior Clipping
28-09-2021 Department of Computer Science and Engineering 67
Point Clipping:
Point Clipping is used to determining, whether the point
is inside the window or not. For this following conditions
are checked.
1.x ≤ xmax
2.x ≥ xmin
3.y ≤ ymax
4.y ≥ ymin
The (x, y) is coordinate of the point. If anyone from the above
inequalities is false, then the point will fall outside the window
and will not be considered to be visible.
28-09-2021 Department of Computer Science and Engineering 68
Line Clipping:
It is performed by using the line clipping
algorithm. The line clipping algorithms are:
1.Cohen Sutherland Line Clipping
Algorithm
2.Midpoint Subdivision Line Clipping
Algorithm
3.Liang-Barsky Line Clipping Algorithm
Department of Computer Science and Engineering 69
Cohen Sutherland Line Clipping Algorithm:
In the algorithm, first of all, it is detected whether line lies inside the screen or it i
outside the screen. All lines come under any one of the following categories:
1.Visible
2.Not Visible
3.Clipping Case
1. Visible: If a line lies within the window, i.e., both endpoints of the line lies within the
window. A line is visible and will be displayed as it is.
2. Not Visible: If a line lies outside the window it will be invisible and rejected. Such
lines will not display
3. Clipping Case: If the line is neither visible case nor invisible case. It is considered
to be clipped case. First of all, the category of a line is found based on nine regions
given below. All nine regions are assigned codes. Each code is of 4 bits. If both
endpoints of the line have end bits zero, then the line is considered to be visible.
Department of Computer Science and Engineering 70
The algorithm will work in the following steps:
•In this algorithm, we will divide the view pane into nine equal segments (as shown in the below figure)
that only serve the viewport.
•Now, we will represent the top, bottom, left, and right corner of the window with 4 bits. This 4bit can be
described with the following point that:
•If an object lies within any particular corner position, that corner value will be 1, else it will be 0.
•The allocation of bits depends on “TBRL” (Top, Bottom, Right, Left) rule.
•Suppose, if the point of a line appears in the top-left corner, then according to TBRL, the value is 1001.
We will allot the bits as-or the top corner, because the object is present at the top corner.
•For the bottom corner, because the object does not lie at the bottom.
•For the right corner, because the object does not lie at the right side.
•For the left corner, because the object lies at the top-left corner.
•In this way, we check TBRL for each segment and allot the bits accordingly.
Department of Computer Science and Engineering 71
Department of Computer Science and Engineering 72
Department of Computer Science and Engineering 73
Department of Computer Science and Engineering 74
Department of Computer Science and Engineering 75
Department of Computer Science and Engineering 76
Department of Computer Science and Engineering 77
Department of Computer Science and Engineering 78
Department of Computer Science and Engineering 79
Thank You
Department of Computer Science and Engineering