Sutherland–Hodgman Algorithm
   HOME

TheInfoList



OR:

The Sutherland–Hodgman algorithm is an
algorithm In mathematics and computer science, an algorithm () is a finite sequence of Rigour#Mathematics, mathematically rigorous instructions, typically used to solve a class of specific Computational problem, problems or to perform a computation. Algo ...
used for
clipping Clipping may refer to: Words * Clipping (morphology), the formation of a new word by shortening it, e.g. "ad" from "advertisement" * Clipping (phonetics), shortening the articulation of a speech sound, usually a vowel * Clipping (publications ...
polygon In geometry, a polygon () is a plane figure made up of line segments connected to form a closed polygonal chain. The segments of a closed polygonal chain are called its '' edges'' or ''sides''. The points where two edges meet are the polygon ...
s. It works by extending each line of the
convex Convex or convexity may refer to: Science and technology * Convex lens, in optics Mathematics * Convex set, containing the whole line segment that joins points ** Convex polygon, a polygon which encloses a convex set of points ** Convex polytop ...
''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 A list is a Set (mathematics), set of discrete items of information collected and set forth in some format for utility, entertainment, or other purposes. A list may be memorialized in any number of ways, including existing only in the mind of t ...
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 Concave or concavity may refer to: Science and technology * Concave lens * Concave mirror Mathematics * Concave function, the negative of a convex function * Concave polygon A simple polygon that is not convex is called concave, non-convex or ...
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. center, frame, All steps for clipping concave polygon 'W' with a 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.


Pseudocode

Given a list of edges in a clip polygon, and a list of vertices in a subject polygon, the following procedure clips the subject polygon against the clip polygon. List outputList = subjectPolygon; for (Edge clipEdge in clipPolygon) do List inputList = outputList; outputList.clear(); for (int i = 0; i < inputList.count; i += 1) do Point current_point = inputList Point prev_point = inputList i − 1) % inputList.count Point Intersecting_point = ComputeIntersection(prev_point, current_point, clipEdge) if (current_point inside clipEdge) then if (prev_point not inside clipEdge) then outputList.add(Intersecting_point); end if outputList.add(current_point); else if (prev_point inside clipEdge) then outputList.add(Intersecting_point); end if done done The vertices of the clipped polygon are to be found in ''outputList'' when the algorithm terminates. Note that a point is defined as being ''inside'' an edge if it lies on the same side of the edge as the remainder of the polygon. If the vertices of the clip polygon are consistently listed in a counter-clockwise direction, then this is equivalent to testing whether the point lies to the left of the line (left means ''inside'', while right means ''outside''), and can be implemented simply by using a
cross product In mathematics, the cross product or vector product (occasionally directed area product, to emphasize its geometric significance) is a binary operation on two vectors in a three-dimensional oriented Euclidean vector space (named here E), and ...
. ''ComputeIntersection'' is a function, omitted here for clarity, which returns the intersection of a line segment and an infinite edge. Note that the intersecting point is only added to the output list when the intersection is known to exist, therefore both lines can always be treated as being infinitely long.


Implementations

A Python implementation of the Sutherland-Hodgman can be foun
here


See also

Other polygon clipping algorithms: * Weiler–Atherton clipping algorithm *
Vatti clipping algorithm The Vatti clipping algorithmBala R. Vatti"A generic solution to polygon clipping" Communications of the ACM, Vol 35, Issue 7 (July 1992) pp. 56–63. is used in computer graphics. It allows clipping of any number of arbitrarily shaped ''subject poly ...
On the subject of clipping: *
Clipping (computer graphics) Clipping, in the context of computer graphics, is a method to selectively enable or disable rendering (computer graphics), rendering operations within a defined region of interest. Mathematically, clipping can be described using the terminology o ...
* Clipping (in rasterisation) * Line clipping algorithms


References

* Mel Slater, Anthony Steed, Yiorgos Chrysanthou: ''Computer Graphics and Virtual Environments: From Realism to Real-Time.'' Addison Wesley, 2002. . *
Ivan Sutherland Ivan Edward Sutherland (born May 16, 1938) is an American computer scientist and Internet pioneer, widely regarded as a pioneer of computer graphics. His early work in computer graphics as well as his teaching with David C. Evans in that subje ...
, Gary W. Hodgman: ''Reentrant Polygon Clipping.''
Communications of the ACM ''Communications of the ACM'' (''CACM'') is the monthly journal of the Association for Computing Machinery (ACM). History It was established in 1958, with Saul Rosen as its first managing editor. It is sent to all ACM members. Articles are i ...
, vol. 17, pp. 32–42, 1974


External links


Polygon clipping and filling
Describes the algorithm using images that are easy to understand.
Rosetta Code example
{{DEFAULTSORT:Sutherland-Hodgman algorithm Polygon clipping algorithms