Segment Clipping Simple algorithm For each segment compute

  • Slides: 8
Download presentation
Segment Clipping Simple algorithm. For each segment compute the intersection with the four sides

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

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 1001 1000 1010 0001 0000 0010 0101 0100 0110 First Bit : y > ymax Second Bit: y < ymin Third Bit : x > xmax Fourth Bit : x < xmin

Cohen-Sutherland Line Clipping. 2 We use the assigned outcode to determine whether the line

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. If ( Si | Ei == 0 ) then 1000 1010 1001 trivially accept segment i 0001 0000 0010 If ( Si & Ei != 0 ) then trivially reject segment I Otherwise compute an intersection point 0100 0110 0101 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

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

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 a general polygon with respect to a given clip rectangle. The operation

Polygon 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

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,

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