Sutherland Hodgeman Polygon Clipping
- For polygon clipping, we need to modify the line clipping procedure because in line clipping we need to consider about only line segment while in polygon clipping we need to consider the area and the new boundary of the polygon after clipping.
- For correctly clip a polygon we process the polygon boundary as a whole against each window edge.
- This is done by whole polygon vertices against each clip rectangle boundary one by one.
- Beginning with the initial set of polygon vertices we first clip against the left boundary. And produce the new sequence of vertices.
- Then that new set of vertices is clipped against the right boundary clipper, a bottom boundary clipper. And a top boundary clipper, as shown in the figure below.
There are four possible cases when processing vertices in sequence around the perimeter of a polygon.
Fig. Clipping a polygon against successive window boundaries.
As shown in Sutherland Hodgeman case 1: if both vertices are inside the window we add only second vertices to the output list.
In case 2: if first vertices inside the boundary and second vertices outside the boundary only the edge intersection with the window boundary added to the output vertex list.
Moreover, In case 3: if both vertices outside the window boundary nothing added to window boundary.
In case 4: the first vertex is outside and the second vertex is inside the boundary. Then adds both intersection point with window boundary and second vertex to the output list.
When polygon clipping done against one boundary then we clip against next window boundary.
We illustrate this method by simple example.
As shown in the Sutherland Hodgeman figure above we clip against left boundary vertices 1 and 2 found to on the outside of the boundary. Then we move to vertex 3, which inside. We calculate the intersection and add both intersection point and vertex 3 to the output list.
Then we move to vertex 4 in which vertex 3 and 4 both are inside. So we add vertex 4 to output list, similarly from 4 to 5 we add 5 to output list, then from 5 to 6 we move inside to outside. So we add intersection pint to the output list. And finally 6 to 1 both vertexes are outside the window so he does not add anything.
Convex polygons correctly clipped by the Sutherland-Hodgeman algorithm but concave polygons may display with extraneous lines.
For overcoming this problem we have one possible solution is to divide the polygon into numbers of the small convex polygon and then process one by one.