Unit-3 Polygon and TextClipping
Unit-3 Polygon and TextClipping
Bhuyan
1 Polygon Clipping
Polygon clipping is the process of cutting off parts of a polygon that lie outside a given boundary (Clipping Window).
For example, if you have a triangle that extends beyond the edges of a window, polygon clipping is the operation
that trims the triangle to fit inside the window. Polygon clipping can be used for rendering, clipping masks, and
visibility tests.
The polygon clipping algorithms are Sutherland-Hodgman, Weiler-Atherton, and Vatti algorithms. Here, we will
discuss the Sutherland-Hodgman algorithm.
2 Sutherland-Hodgman algorithm
The Sutherland-Hodgman algorithm is one of the most widely used algorithms for polygon clipping. It was developed
by Ivan Sutherland and Gary Hodgman in 1974. The general strategy in this algorithm is to send the pair of endpoints
for each successive polygon line segment through the series of clippers (left, right, bottom, and top).
In this process, we need to traverse the polygon edges either in the clockwise or anti-clockwise direction. That
is, first, the polygon is clipped against the left edge of the polygon window (Left-Clipper) to get new vertices
of the polygon. These new vertices are passed to clip the polygon against the right edge (Right-Clipper), bottom
edge (Bottom-Clipper), and top edge(Top-Clipper), respectively of the clipping window as shown in the Figure
below.
Example:
Four possible cases need to be considered when processing a polygon edge E1 = (V1, V2), against one of the
clipping boundaries (Left, right, bottom, top). The possible cases are
• Out → In: The first endpoint (V1) is outside the clipping boundary, and the second endpoint (V2) is inside.
It is referred to as Out → In scenario. In this scenario, the input edge is E1 with the vertices (V1, V2) and the
output vertices = {V1’, V2}
• In → In: Both endpoints (V1 and V2) could be inside this clipping boundary. It is refereed as In → In this
scenario, the input edge is E1 with the vertices (V1, V2) and the output vertices = {V2}
• In → Out: The first endpoint (V1) is inside the clipping boundary and the second endpoint (V2) is outside.
It is referred as In → Out scenario. In this scenario, if the input edge is E1 with the vertices (V1, V2) then
the output vertices = {V1’}
• Out → Out: Both endpoints (V1 and V2) could be outside the clipping boundary. It is referred as Out →
Out scenario. In this scenario, if the input edge is E1 with the vertices (V1, V2), then the output vertices = {
}. That is, none of the vertices will be included.
In all these above possible cases, the O/P generated by one clipping edge or clipper is passed to the next clipper.
The four possible outputs generated by the left clipper, depending on the position of a pair of endpoints relative
to the left boundary of the clipping window, are shown in the figure below.
a) Find out VXmin = min (V1x, V2x,.....Vnx)and VYmin = min (V1y, V2y,.....Vny)
b) If VXmin and VYmin are not in the range of the XWmin , Y Wmin ) and (XWmax , Y Wmax ) then return
null. That is, there is no clipped polygon.
a) Find out VXmin = min (V1x, V2x,.....Vnx)and VYmin = min (V1y, V2y,.....Vny)
b) If XWmin ≤ V Xmin ≤ XWmax and Y Wmin ≤ V Y min ≤ Y Wmax then the Polygon is completed inside
the clipping window. So, return all the polygon vertices.
• Step-3: If Step-1 and 2 doesn’t satisfy, then the polygon is partially inside the clipping window. So, process
each of the edges of the polygon against the 4 edges of the clipping window (Left, Right, Bottom, Top) and
follow the below steps.
• Step-3 (i): Send a pair of endpoints for each successive polygon line segment through the series of clippers
and check Four possible cases:
a) Out → In scenario. If the input edge is E1 with the vertices (V1, V2) then the output vertices = {V1’,
V2}. Here, we need to apply the line clipping algorithm to get V1’, that is, the intersection point of edge
E1 with the clipper.
b) In → In scenario. If the input edge is E1 with the vertices (V1, V2) then the output vertices = {V2}
c) In → Out scenario. If the input edge is E1 with the vertices (V1, V2) then the output vertices = {V1’}.
Here, we need to apply the line clipping algorithm to get V1’, that is the intersection point of edge E1
with the clipper.
d) Out → Out scenario. If the input edge is E1 with the vertices (V1, V2), then the output vertices = { }.
That is, none of the vertices will be included.
• Step-3 (ii): The last clipper in this series generates a vertex list that describes the final clipped polygon.
• Step-3 (iii): Return the resultant clipped vertices.
2.3 Example
Question: Consider the following triangle and the clipping window. Find out the clipped triangle and resultant
vertices after applying the Sutherland-Hodgman algorithm.
• The notation of the resultant set of vertices (V’ or V”) may vary, deepening on the starting edge. However,
the shape of the clipped polygon never changes.
2.4 Assignments
Question-1: Consider the following polygon and the clipping window. Find out the clipped polygon and resultant
vertices after applying the Sutherland-Hodgman algorithm
Question-2: Consider the polygon in the figure below and the clipping window. Find out the clipped polygon
and resultant vertices after applying the Sutherland-Hodgman algorithm
Question-3 Consider the following concave polygon in the figure below and the clipping window. Find out the
clipped polygon and resultant vertices after applying the Sutherland-Hodgman algorithm
Question-4 Consider the following concave polygon in the figure below and the clipping window. Find out
the clipped polygon and resultant vertices after applying the Sutherland-Hodgman algorithm. During solving the
problem, start with the polygon edge AB and traverse the polygon in the anti-clockwise direction
This occurs when the clipped polygon should have two or more separate sections. But since there is only one
output vertex list, the last vertex in the list is always joined to the first vertex.
b) We can modify the Sutherland- Hodgman method to check the final vertex list for multiple intersection points
along any clipping-window boundary. If we find more than two vertex positions along any clipping boundary, we
can separate the list of vertices into two or more lists that correctly identify the separate sections of the clipped fill
area. This may require extensive analysis to determine whether some points along the clipping boundary should
be paired or whether they represent single vertex points that have been clipped
c) We can use a more general polygon clipper that has been designed to process concave polygons correctly.
3 Text Clipping
Various techniques are used to provide text clipping in computer graphics. It depends on the methods used to
generate characters and the requirements of a particular application. There are three methods for text clipping,
which are listed below
• All or none string clipping
• All or none character clipping
Example: