Download as pdf or txt
Download as pdf or txt
You are on page 1of 4

Sutherland-hodgeman polygon

clipping

Abstract:

The Sutherland–Hodgman algorithm is used for clipping polygons. It works by extending


each line of the convex clip polygon in turn and selecting only vertices from the subject
polygon that are on the visible side.

Background:

The Sutherland - Hodgman algorithm performs a clipping of a polygon against each window edge
in turn. It accepts an ordered sequence of verices v1, v2, v3, ..., vn and puts out a set of vertices
defining the clipped polygon.

This figure represents a polygon (the large, solid, upward pointing arrow) before clipping has
occurred.

The following figures show how this algorithm works at each edge, clipping the polygon.
a. Clipping against the left side of the clip window.


b. Clipping against the top side of the clip window.


c. Clipping against the right side of the clip window.


d. Clipping against the bottom side of the clip window.

Four Types of Edges

As the algorithm goes around the edges of the window, clipping the polygon, it encounters four
types of edges. All four edge types are illustrated by the polygon in the following figure. For each
edge type, zero, one, or two vertices are added to the output list of vertices that define the clipped
polygon.

The four types of edges are:


1. Edges that are totally inside the clip window. - add the second inside vertex point
2. Edges that are leaving the clip window. - add the intersection point as a vertex
3. Edges that are entirely outside the clip window. - add nothing to the vertex output list
4. Edges that are entering the clip window. - save the intersection and inside points as vertice.


Algorithms:

Sutherland-hodgeman polygon clipping algorithm:

void suthHodgClip(int poly_points[][2], int poly_size,


int clipper_points[][2], int clipper_size)
{
//i and k are two consecutive indexes
for (int i=0; i<clipper_size; i++)
{
int k = (i+1) % clipper_size;

// We pass the current array of vertices, it's size


// and the end points of the selected clipper line
clip(poly_points, poly_size, clipper_points[i][0],
clipper_points[i][1], clipper_points[k][0],
clipper_points[k][1]);
}

// Printing vertices of clipped polygon


for (int i=0; i < poly_size; i++)
cout << '(' << poly_points[i][0] <<
", " << poly_points[i][1] << ") ";
}

Conclusion:

In summary, the algorithm is efficient when outcode testing can be done cheaply (for
example, by doing bitwise operations in assembly language) and trivial acceptance or
rejection is applicable to the majority of line segments .(For example, large windows -
everything is inside , or small windows - everything is outside).

References:

• Computer Graphics: Principles and Practice, 3rd Edition (2nd is also highly regarded)
- this book is called The Bible of CG
• Computer Graphics, C Version,
• Fundamentals of Computer Graphics,
• Computer Graphics using OpenGL,
• Interactive Computer Graphics: A Top-Down Approach with WebGL,3D Computer
Graphics: A Mathematical Introduction with OpenGL†

You might also like