Polygon Clipping
Clipping Polygons
• Clipping polygons is more complex than
clipping the individual lines
– Input: polygon
– Output: original polygon, new polygon, or
nothing
• When can we trivially accept/reject a
polygon as opposed to the line segments
that make up the polygon?
Why Is Clipping Hard?
• What happens to a triangle during
clipping?
• Possible outcomes:
Nihar Ranjan Roy 3
triangle triangle triangle
quad triangle
5-gonHow many sides?
• Seven…
Why Is Clipping Hard?
• A really tough case:
Why Is Clipping Hard?
• A really tough case:
Nihar Ranjan Roy 6
Sutherland-Hodgeman Clipping
• Basic idea:
– Consider each edge of the viewport individually
– Clip the polygon against the viewport edge’s
equation
Sutherland-Hodgeman Clipping
• Basic idea:
– Consider each edge of the viewport individually – Clip the polygon against the edge equation
– After doing all edges, the polygon is fully clipped
Sutherland-Hodgeman Clipping
• Basic idea:
– Consider each edge of the viewport individually – Clip the polygon against the edge equation
– After doing all edges, the polygon is fully clipped
Sutherland-Hodgeman Clipping
• Basic idea:
– Consider each edge of the viewport individually – Clip the polygon against the edge equation
– After doing all edges, the polygon is fully clipped
Sutherland-Hodgeman Clipping
• Basic idea:
– Consider each edge of the viewport individually – Clip the polygon against the edge equation
– After doing all edges, the polygon is fully clipped
Sutherland-Hodgeman Clipping
• Basic idea:
– Consider each edge of the viewport individually – Clip the polygon against the edge equation
– After doing all edges, the polygon is fully clipped
Sutherland-Hodgeman Clipping
• Basic idea:
– Consider each edge of the viewport individually – Clip the polygon against the edge equation
– After doing all edges, the polygon is fully clipped
Sutherland-Hodgeman Clipping
• Basic idea:
– Consider each edge of the viewport individually – Clip the polygon against the edge equation
– After doing all edges, the polygon is fully clipped
Sutherland-Hodgeman Clipping
• Basic idea:
– Consider each edge of the viewport individually – Clip the polygon against the edge equation
– After doing all edges, the polygon is fully clipped
Sutherland-Hodgeman Clipping:
• Basic idea:
– Consider each edge of the viewport individually – Clip the polygon against the edge equation
– After doing all edges, the polygon is fully clipped
Sutherland-Hodgeman Clipping
• Input/output for algorithm:
– Input: list of polygon vertices in order
– Output: list of clipped poygon vertices
consisting of old vertices (maybe) and new
vertices (maybe)
• Note: this is exactly what we expect from
the clipping operation against each edge
Sutherland-Hodgeman Clipping
• Sutherland-Hodgman basic routine:
– Go around polygon one vertex at a time
– Current vertex has position
p
– Previous vertex had position
s
, and it has been
added to the output if appropriate
Sutherland-Hodgeman Clipping
• Edge from s to p takes one of four cases:
(Yellow line can be a line or a plane)
Nihar Ranjan Roy 19
Sutherland-Hodgeman Clipping
Nihar Ranjan Roy 20
1
3
6
4
2
Sutherland-Hodgeman Clipping
Nihar Ranjan Roy 21
1
3
6
4
2
Sutherland-Hodgeman Clipping
Nihar Ranjan Roy 22
1
3
6
4
2
Sutherland-Hodgeman Clipping
Nihar Ranjan Roy 23
Sutherland-Hodgeman Clipping
Nihar Ranjan Roy 24
1`
2`
3`
Weiler Atherton polygon clipping Rule
Nihar Ranjan Roy 25
•Walk around the Polygon/window Boundary
(it depends on the direction of traversing)
Weiler Atherton polygon clipping Rule
Nihar Ranjan Roy 26
Weiler Atherton polygon clipping Rule
Walking rules
Out to inside
Store the clipped point
Follow the polygon boundary (CCW)
Inside to outside
Store the clipped point
Follow the window boundary
Weiler Atherton polygon clipping Rule
Walking rules
Out to inside
Store the clipped point
Follow the polygon boundary (CCW)
Inside to outside
Store the clipped point
Follow the window boundary
Weiler Atherton polygon clipping Rule
Walking rules
Out to inside
Store the clipped point
Follow the polygon boundary (CCW)
Inside to outside
Store the clipped point
Follow the window boundary
Weiler Atherton polygon clipping Rule
Walking rules
Out to inside
Store the clipped point
Follow the polygon boundary (CCW)
Inside to outside
Store the clipped point
Follow the window boundary
Weiler Atherton polygon clipping Rule
Walking rules Out to inside
Store the clipped point
Follow the polygon boundary (CCW)
Inside to outside
Store the clipped point
Follow the window boundary
Comparison of the two techniques
Comparison of the two techniques
Nihar Ranjan Roy 33
Sutherland Hodgeman
Comparison of the two techniques
Nihar Ranjan Roy 34
Comparison of the two techniques
Nihar Ranjan Roy 35