Polygon clipping

5,850 views

Published on

Published in: Technology, Art & Photos
  • Be the first to comment

Polygon clipping

  1. 1. Clipping Polygons <ul><li>Clipping polygons is more complex than clipping the individual lines </li></ul><ul><ul><li>Input: polygon </li></ul></ul><ul><ul><li>Output: original polygon, new polygon, or nothing </li></ul></ul><ul><li>The biggest optimizer we had was trivial accept or reject… </li></ul><ul><li>When can we trivially accept/reject a polygon as opposed to the line segments that make up the polygon? </li></ul>
  2. 2. <ul><li>What happens to a triangle during clipping? </li></ul><ul><li>Possible outcomes : </li></ul>Why Is Clipping Hard? triangle  triangle triangle  quad triangle  5-gon How many sides can a clipped triangle have?
  3. 3. How many sides? <ul><li>Seven… </li></ul>
  4. 4. <ul><li>A really tough case: </li></ul>Why Is Clipping Hard?
  5. 5. <ul><li>A really tough case: </li></ul>Why Is Clipping Hard? concave polygon  multiple polygons
  6. 6. Sutherland-Hodgman Clipping <ul><li>Basic idea: </li></ul><ul><ul><li>Consider each edge of the view window individually </li></ul></ul><ul><ul><li>Clip the polygon against the view window edge’s equation </li></ul></ul>
  7. 7. Sutherland-Hodgman Clipping <ul><li>Basic idea: </li></ul><ul><ul><li>Consider each edge of the viewport individually </li></ul></ul><ul><ul><li>Clip the polygon against the edge equation </li></ul></ul>
  8. 8. Sutherland-Hodgman Clipping <ul><li>Basic idea: </li></ul><ul><ul><li>Consider each edge of the viewport individually </li></ul></ul><ul><ul><li>Clip the polygon against the edge equation </li></ul></ul>
  9. 9. Sutherland-Hodgman Clipping <ul><li>Basic idea: </li></ul><ul><ul><li>Consider each edge of the viewport individually </li></ul></ul><ul><ul><li>Clip the polygon against the edge equation </li></ul></ul>
  10. 10. Sutherland-Hodgman Clipping <ul><li>Basic idea: </li></ul><ul><ul><li>Consider each edge of the viewport individually </li></ul></ul><ul><ul><li>Clip the polygon against the edge equation </li></ul></ul>
  11. 11. Sutherland-Hodgman Clipping <ul><li>Basic idea: </li></ul><ul><ul><li>Consider each edge of the viewport individually </li></ul></ul><ul><ul><li>Clip the polygon against the edge equation </li></ul></ul>
  12. 12. Sutherland-Hodgman Clipping <ul><li>Basic idea: </li></ul><ul><ul><li>Consider each edge of the viewport individually </li></ul></ul><ul><ul><li>Clip the polygon against the edge equation </li></ul></ul>
  13. 13. Sutherland-Hodgman Clipping <ul><li>Basic idea: </li></ul><ul><ul><li>Consider each edge of the viewport individually </li></ul></ul><ul><ul><li>Clip the polygon against the edge equation </li></ul></ul>
  14. 14. Sutherland-Hodgman Clipping <ul><li>Basic idea: </li></ul><ul><ul><li>Consider each edge of the viewport individually </li></ul></ul><ul><ul><li>Clip the polygon against the edge equation </li></ul></ul>
  15. 15. Sutherland-Hodgman Clipping <ul><li>Basic idea: </li></ul><ul><ul><li>Consider each edge of the viewport individually </li></ul></ul><ul><ul><li>Clip the polygon against the edge equation </li></ul></ul><ul><ul><li>After doing all edges, the polygon is fully clipped </li></ul></ul>
  16. 16. Sutherland-Hodgman Clipping <ul><li>Input/output for algorithm: </li></ul><ul><ul><li>Input: list of polygon vertices in order </li></ul></ul><ul><ul><li>Output: list of clipped polygon vertices consisting of old vertices (maybe) and new vertices (maybe) </li></ul></ul><ul><li>Note: this is exactly what we expect from the clipping operation against each edge </li></ul>
  17. 17. Sutherland-Hodgman Clipping <ul><li>Sutherland-Hodgman basic routine: </li></ul><ul><ul><li>Go around polygon one vertex at a time </li></ul></ul><ul><ul><li>Current vertex has position p </li></ul></ul><ul><ul><li>Previous vertex had position s , and it has been added to the output if appropriate </li></ul></ul>
  18. 18. Sutherland-Hodgman Clipping <ul><li>Edge from s to p takes one of four cases: </li></ul><ul><ul><li>(Orange line can be a line or a plane) </li></ul></ul>inside outside s p p output inside outside s p no output inside outside s p i output inside outside s p i output p output
  19. 19. Sutherland-Hodgman Clipping <ul><li>Four cases: </li></ul><ul><ul><li>s inside plane and p inside plane </li></ul></ul><ul><ul><ul><li>Add p to output </li></ul></ul></ul><ul><ul><ul><li>Note: s has already been added </li></ul></ul></ul><ul><ul><li>s inside plane and p outside plane </li></ul></ul><ul><ul><ul><li>Find intersection point i </li></ul></ul></ul><ul><ul><ul><li>Add i to output </li></ul></ul></ul><ul><ul><li>s outside plane and p outside plane </li></ul></ul><ul><ul><ul><li>Add nothing </li></ul></ul></ul><ul><ul><li>s outside plane and p inside plane </li></ul></ul><ul><ul><ul><li>Find intersection point i </li></ul></ul></ul><ul><ul><ul><li>Add i to output, followed by p </li></ul></ul></ul>

×