Content deleted Content added
m Standard headings &/or gen fixes. using AWB |
Added book publication date |
||
(109 intermediate revisions by 76 users not shown) | |||
Line 1:
{{Short description|Algorithm for clipping polygons}}
The '''Sutherland
==Description==
[[image:Sutherland-Hodgman clipping sample.svg|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.▼
▲The [[Weiler
==Pseudocode==
Given a specific clip plane and an array containing the vertices of a single polygon, the following procedure clips the polygon against the plane.▼
▲Given a
{▼
Output( P )▼
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[i];
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);
outputList.add(current_point);
'''else if''' (prev_point inside clipEdge) '''then'''
outputList.add(Intersecting_point);
'''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]].
==Implementations==
A Python implementation of the Sutherland-Hodgman can be found [https://github.com/mdabdk/sutherland-hodgman here].
==See also==
*[[Weiler–Atherton clipping algorithm]]
*[[Vatti clipping algorithm]]
On the subject of clipping:
*[[Clipping (computer graphics)]]
*[[Rasterisation#Clipping|Clipping (in rasterisation)]]
*[[Line clipping|Line clipping algorithms]]
== References==
* Mel Slater, Anthony Steed, Yiorgos Chrysanthou: ''Computer Graphics and Virtual Environments: From Realism to Real-Time.'' Addison Wesley, 2002. {{ISBN|0-201-62420-6}}.
* [[Ivan Sutherland]], Gary W. Hodgman: ''Reentrant Polygon Clipping.'' [[Communications of the ACM]], vol. 17, pp. 32–42, 1974
==External links==
* [http://www.cs.drexel.edu/~david/Classes/CS430/Lectures/L-05_Polygons.6.pdf Polygon clipping and filling] Describes the algorithm using images that are easy to understand.
* [https://rosettacode.org/wiki/Sutherland-Hodgman_polygon_clipping Rosetta Code example]
{{DEFAULTSORT:Sutherland-Hodgman algorithm}}
[[Category:Polygon clipping algorithms]]
|