Computer Notes Clipping II
Computer Notes Clipping II
Computer Notes Clipping II
com)
Clipping-II
Introduction Polygon Clipping
A polygon is usually defined by a sequence of vertices and edges. If the polygons are
un-filled, line-clipping techniques are sufficient however, if the polygons are filled, the process in more complicated. A polygon may be fragmented into several polygons in the clipping process, and the original colour associated with each one. The SutherlandHodgeman clipping algorithm clips any polygon against a convex clip polygon. The
Weiler-Atherton clipping algorithm will clip any polygon against any clip polygon. The polygons may even have holes. An algorithm that clips a polygon must deal with many different cases. The case is particularly note worthy in that the concave polygon is clipped into two separate polygons. All in all, the task of clipping seems rather complex. Each edge of the polygon must be tested against each edge of the clip rectangle; new edges must be added, and
existing edges must be discarded, retained, or divided. Multiple polygons may result
from clipping a single polygon. We need an organized way to deal with all these cases. The following example illustrates a simple case of polygon clipping.
158
(ecomputernotes.com)
(ecomputernotes.com)
159
The clip boundary determines a visible and invisible region. The edges from vertex i to vertex i+1 can be one of four types:
Case 1 : Wholly inside visible region - save endpoint Case 2 : Exit visible region - save the intersection Case 3 : Wholly outside visible region - save nothing Case 4 : Enter visible region - save intersection and endpoint
Because clipping against one edge is independent of all others, it is possible to arrange the clipping stages in a pipeline. The input polygon is clipped against one edge and any points that are kept are passed on as input to the next stage of the pipeline. In this way four polygons can be at different stages of the clipping process simultaneously. This is often implemented in hardware.
Original polygon
161
(ecomputernotes.com)
Clip Left
Clip Right
(ecomputernotes.com)
162
Clip Bottom
Clip Top
Example No #2 Clipping a Rectangle If Clipping Rectangle is denoted by dashed lines and Line is defined by using points P1 and P2 Case i
163
(ecomputernotes.com)
For each boundary b in [ L(Left), R(Right), T(Top), B(Bottom) ] If P outside and P inside. Output: 1. intersection Point (P1) 2. Point P
1 2 2
Case ii
(ecomputernotes.com)
164
Case iii
For each boundary b in [ L(Left), R(Right), T(Top), B(Bottom) ] If P1 outside and P2 outside Do nothing
Case iv
165
(ecomputernotes.com)
Pipeline Clipping Approach An array, s records the most recent point that was clipped for each clip-window
boundary. The main routine passes each vertex p to the clipPoint routine for clipping
against the first window boundary. If the line defined by endpoints p and s (boundary) crosses this window boundary, the intersection is calculated and passed to the next clipping stage. If p is inside the window, it is passed to the next clipping stage. Any point that survives clipping against all window boundaries is then entered into the output array of points. The array firstPoint stores for each window boundary the first point flipped against that boundary. After all polygon vertices have been processed, a closing routine clips lines defined by the first and last points clipped against each boundary. Shortcoming of Sutherlands -Hodgeman Algorithm Convex polygons are correctly clipped by the Sutherland-Hodegeman algorithm, but concave polygons may be displayed with extraneous lines. This occurs when the clipped polygon should have two or more separate sections. But since there is only one output vertex list, the last vertex in the list is always joined to the first vertex. There are several things we could do to correct display concave polygons. For one, we could split the concave polygon into two or more convex polygons and process each convex polygon separately. Another approach to check the final vertex list for multiple vertex points along any clip window boundary and correctly join pairs of vertices. Finally, we could use a more general polygon clipper, such as wither the Weiler-Atherton algorithm or the Weiler algorithm described in the next section.
For an inside-to-outside pair of vertices, follow the window boundary in a clockwise direction
In following figure, the processing direction in the Wieler-Atherton algorithm and the
Inside
go up 1
5 8 go up 6
167
(ecomputernotes.com)