Polygon Clipping
- We will consider clipping convex polygons first.
- These present much less challenge than concave polygons.
- Sutherland-Hodgman Polygon Clipping.
- We will clip against a rectangle,
- But it can be used to clip against an arbitrary convex clipping polygon.
- And it can be done as a pipeline operation.
- And it is what opengl uses (I think)
- Send successive pairs of line endpoints through a four stage pipeline
- Each stage clips the point against one of the sides of the clip window.
- Or in the case of a n-sided clip polygon, each side is against one of the sides.
- For any pair of vertexes against any side
- If the first vertex is outside and the second is inside, pass along the intersection point and the second vertex are passed along to the next stage
- If both vertexes are inside, only the second vertex is passed along.
- If the first vertex is inside and the second is outside, pass the edge intersection along
- If both are outside, no vertexes are passed along.
- Consider
-
- Step 1, clip against the left.
- Input {1,2} {2,3} {3,1}
- Line {1,2} does not need clipped so send 2 on
- Line {2,3} goes from inside to outside, so pass 2' along.
- Line {3,1} goes from the outside to the inside, so pass along 3' and 1
-
- Step two, clip against the right side.
- Input {2,2'} {2',3'} {3',1} {1,2}
- Line {2,2'} does not need clipped so send 2' on
- Line {2',3'} does not need clipped so send 3' on
- Line {3',1} does not need clipped so send 1 on
- Line {1,2} does not need clipped so send 2 on
-
- Step 3, clip against the bottom plane.
- Input {2',3'} {3', 1} {1,2} {2,2'}
- Line {2',3'} Goes from in to out so pass along 2"
- Line {3',1} goes from out to out so pass along nothing
- Line {1,2} goes from out to in, so pass along 1',2
- Line {2,2'} goes from in to in so pass along 2'
-
- Step 4, clip against the top plane
- Input {2", 1'} {1',2} {2,2'} {2',2"}
- There is no clipping at this stage
- Each clip goes from in to in, so pass along the endpoint.
- The output would be {1',2} {2,2'} {2', 2"} {2",1}
-
- A modification of this algorithm can work with concave polygons