Sutherland–Hodgman algorithm: Difference between revisions

Content deleted Content added
m Disambiguate List to List (computing) using popups
No edit summary
Line 1:
The '''Sutherland-–Hodgman algorithm''' is used for [[Clipping (computer graphics)|clipping]] [[polygon]]s. It works by extending each line of the ''clip polygon'' in turn and selecting only vertices from the ''subject polygon'' that are on the visible side.
 
==Description==
The algorithm begins with an input [[List (computing)|list]] of all vertices in the subject polygon. Next, one side of the clip polygon is extended infinitely in both directions, and the path of the subject polygon is traversed. Vertices from the input list are inserted into an output list if they lie on the visible side of the extended clip polygon line, and new vertices are added to the output list where the subject polygon path crosses the extended clip polygon line.
 
This process is repeated iteratively for each clip polygon side, using the output list from one stage as the input list for the next. Once all sides of the clip polygon have been processed, the final generated list of vertices defines a new single polygon that is entirely visible. Note that if the subject polygon was [[concave polygon|concave]] at vertices outside the clipping polygon, the new polygon may have coincident (i.e. overlapping) edges -– this is acceptable for rendering, but not for other applications such as computing shadows.
 
[[image:Sutherland-Hodgman_clipping_sample.svg|center|frame|All steps of clipping concave polygon 'W' by 5-sided convex polygon]]
 
The [[Weiler-–Atherton]] algorithm overcomes this by returning a set of divided polygons, but is more complex and computationally more expensive, so Sutherland-–Hodgman is used for many rendering applications. Sutherland-–Hodgman can also be extended into 3D space by clipping the polygon paths based on the boundaries of planes defined by the viewing space.
 
==Pseudo Code==
Line 37:
 
==See also==
*[[Weiler-–Atherton clipping algorithm]]
*[[Rasterisation#Clipping|Clipping (in rasterisation)]]