Copyright Derek O'Reilly, Dundalk Institute of Technology (DkIT), Dundalk, Co. Louth, Ireland.
We can extend the Cohen-Sutherland clipping algorithm, so as to clip lines against a 3D view volume.
This is essentially similar to the 2D case, except now we need a six bit outcode.
The six bits are now:
Up to six iterations need to be performed for lines that are neither trivially accepted or rejected.
The Cohen-Sutherland only clips lines. It is more often the case that we need to clip a polygon (or, depending on our modelling method, some other region containing a 2D area or a 3D volume).
We shall examine an algorithm for clipping a polygon against a 3D view volume.
The Sutherland-Hodgeman algorithm clips an entire polygon against one of the bounding volume edges. The result of this clip is a new polygon, which in turn is clipped against a second edge of the bounding volume. In this way the polygon is clipped against each of the six bounding volume edges.
Starting at vertex A and travelling in an anti-clockwise direction:
This output polygon is cliped against the top edge, and so on until all six edges have been clipped against.
The Weiler-Atherton algorithm clips a polygon against a view volume by tracing around the border of the polygon in a clockwise direction until an intersection with the view volume is encountered.
If the polygon's edge is entering the view volume at the point of intersection, it continues along the polygon's edge.
If the polygon's edge is leaving the view volume at the point of intersection, it makes a clockwise turn and follows the line of intersection that the polygon makes with the view volume's clipping plane.
In either case the intersection is remembered and used to ensure that all paths are traced exactly once.
A clipped polygon may be broken into two or more smaller polygons, such as in the case above.
NOTE: The start point can be any vertex of the polygon.
Copyright Derek O' Reilly, Dundalk Institute of Technology (DkIT), Dundalk, Co. Louth, Ireland.