Segment Clipping Simple algorithm. For each segment compute the intersection with the four sides of the rectangle, and then determine which sub-segment is within the clipping rectangle.
Cohen-Sutherland Line Clipping.1 The algorithm starts by extending the four edge of the clipping rectangle to define nine regions which are different outcodes First Bit : y > ymax Second Bit: y < ymin Third Bit : x > xmax Fourth Bit : x < xmin 1001 1000 1010 0001 0000 0010 0101 0100 0110
Cohen-Sutherland Line Clipping.2 We use the assigned outcode to determine whether the line segment lies completely inside the clip rectangle or outside half plane of an edge. Let Si and Ei be the start and end code of segment i then. 0000 1000 0010 0001 0100 0101 0110 1001 1010 If ( Si | Ei == 0 ) then trivially accept segment i If ( Si & Ei != 0 ) then trivially reject segment I Otherwise compute an intersection point of the segment i with the clip rectangle which split the segment into two new segments which are assigned new code and processed recursively
Cohen-Sutherland Line Clipping.3 Segment may go over several intersection computation 1001 1000 1010 0001 0000 0010 0101 0100 0110
Cohen-Sutherland Line Clipping Optimization There are three possible cases for the start point of a segment (any other case could be generated from these cases by symmetry). Each case divide the space into different region which dictate the possible intersection based on the end point of the segment (Ei). Si Si Si
Polygon Clipping Clipping a general polygon with respect to a given clip rectangle. The operation is often required to be performed efficiently.
Sutherland-Hodgman Polygon Clipping Algorithm The algorithm clips the polygon against a single infinite clip edge at a time. Input
Boundary Walk&Clip Algorithm The algorithm traverse the polygon and keeps track on the inside, outside, and the intersection with the polygon edges. The resulting polygon may not be simple polygon Input Final