0% found this document useful (0 votes)
5 views7 pages

Unit-3 Polygon and TextClipping

The document discusses polygon and text clipping techniques in computer graphics, focusing on the Sutherland-Hodgman algorithm for polygon clipping. It outlines the algorithm's steps, visibility tests, and possible scenarios for edge processing, as well as its limitations and advantages. Additionally, it covers various methods for text clipping, including all or none string clipping and character clipping techniques.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views7 pages

Unit-3 Polygon and TextClipping

The document discusses polygon and text clipping techniques in computer graphics, focusing on the Sutherland-Hodgman algorithm for polygon clipping. It outlines the algorithm's steps, visibility tests, and possible scenarios for edge processing, as well as its limitations and advantages. Additionally, it covers various methods for text clipping, including all or none string clipping and character clipping techniques.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

Dr. Himadri B.G.S.

Bhuyan

Polygon & Text Clipping


Dr. Himadri B.G.S. 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}

Dr. Himadri B.G.S. Bhuyan


Dr. Himadri B.G.S. Bhuyan

• 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.

2.1 Visibility Test


The objective of this test is to find out whether a given polygon vertex V(X, Y) lies
• Right hand side (RHS) of the clipper, or RHS of the clipping edge
• Left hand side (LHS) of the clipper, or LHS of the clipping edge
• On the clipper or on the clipping edge
If the given polygon vertex V is (X, Y) and vertices of the clipper or clipping edge are (X1, Y1) and (X2, Y2),
then compute C. Here, we assume that X1 ≤ X2 and Y1 ≤ Y2.

C = (Y 2 − Y 1) ∗ (X − X1) − (X2 − X1) ∗ (Y − Y 1)

a) If C > 0 then the polygon vertex V is RHS of the clipper


b) If C = 0 then the polygon vertex V is on the clipper
c) If C < 0 then the polygon vertex V is LHS of the clipper

2.2 Algorithm Steps


// Input: Clipping window (XWmin , Y Wmin ) and (XWmax , Y Wmax ).
Polygon Vertices { (V1x,V1y), (V2x,V2y),....,(Vnx,Vny) } that is to be clipped.
// Output: Resultant Vertices of the clipped polygon.

• Step-1: Check if the polygon is completed outside of the clipping window

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.

Dr. Himadri B.G.S. Bhuyan


Dr. Himadri B.G.S. Bhuyan

• Step-2: Check if the polygon is completely inside the clipping window

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.

Answer: While solving the problem make a note that:


• We may traverse the polygon in an anti-clockwise (Preferable) or clockwise direction.
• We can start with any polygon edge.

• 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.

Dr. Himadri B.G.S. Bhuyan


Dr. Himadri B.G.S. Bhuyan

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

Dr. Himadri B.G.S. Bhuyan


Dr. Himadri B.G.S. Bhuyan

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

2.5 Limitation of Sutherland-Hodgman algorithm


Extraneous lines may be displayed when a concave polygon is clipped with the Sutherland-Hodgman algorithm. An
example of this effect is demonstrated in Figure below.

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.

2.5.1 Solution to the above issue


There are several things we can do to display clipped concave polygons correctly
a) We could split a concave polygon into two or more convex polygons and process each convex polygon separately
using the Sutherland-Hodgman algorithm.

Dr. Himadri B.G.S. Bhuyan


Dr. Himadri B.G.S. Bhuyan

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.

2.6 Advantages of Sutherland-Hodgman algorithm


The Sutherland-Hodgman algorithm has several advantages that make it preferable to other polygon clipping algo-
rithms.
• It is simple and straightforward to implement, and it can handle convex and concave polygons (with some extra
caution), as well as polygons with holes and self-intersections.
• it can clip polygons against any shape of boundary, not just rectangles or circles, while preserving the original
vertices and edges of the polygon unless they are outside the boundary.

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

• Clip the components of individual characters.

3.1 All or none string clipping


In all or none string clipping method, either we keep the entire string or we reject the entire string based on the
clipping window. As shown in the Figure below, STRING2 is entirely inside the clipping window, so we keep it, and
STRING1 is partially inside the window, so we reject it.

3.2 All or none character clipping


It is based on characters rather than the entire string. In this method, if the string is entirely inside the clipping
window, then we keep it. If it is partially outside the window, then
• Reject only the portion of the string being outside
• If the character is on the boundary of the clipping window, then we discard that entire character and keep the
rest of the string.

Example:

Dr. Himadri B.G.S. Bhuyan


Dr. Himadri B.G.S. Bhuyan

3.3 Clip the components of individual characters.


This clipping method is based on characters rather than the entire string. In this method, if the string is entirely
inside the clipping window, then we keep it. If it is partially outside the window, then

• Reject only the portion of the string being outside.


• If the character is on the boundary of the clipping window, then we discard only that portion of the character
that is outside of the clipping window.
Example:

Dr. Himadri B.G.S. Bhuyan

You might also like