Greiner–Hormann clipping algorithm: Difference between revisions

Content deleted Content added
No edit summary
OAbot (talk | contribs)
m Open access bot: doi added to citation with #oabot.
 
(12 intermediate revisions by 10 users not shown)
Line 7:
|author2=Kai Hormann
| title = Efficient clipping of arbitrary polygons
| journal = ACM Transactions on Graphics (TOG)
| accessdate = 2014-05-17
| year = 1998
| urldoi = http://dl10.acm.org1145/citation274363.cfm?id=274364
| doi-access = free
}}</ref> It isperforms more performantbetter than the [[Vatti clipping algorithm]], but cannot handle [[Degeneracy (mathematics)|degeneracies]].<ref name="foster">{{Cite journalweb
| last = Foster
| first = Erich L.
|author2=James R. Overfelt
| title = Clipping of Arbitrary Polygons with Degeneracies
| journal = arXiv preprint arXiv:1211.3376
| accessdate = 2014-05-17
| year = 2012
| url = http://arxiv.org/abs/1211.3376
}}</ref><ref>{{Cite web
| title = Efficient Clipping of Arbitrary Polygons
| author = Ionel Daniel Stroe
Line 27 ⟶ 18:
}}</ref> It can process both self-intersecting and non-convex polygons. It can be trivially generalized to compute other [[Boolean operations on polygons]], such as union and difference.
 
The algorithm is based on the definition of the "inside" of a polygon based on the [[winding number]]. It considers regions with odd winding number to be inside the polygon; this is known as the [[even–odd rule]]. It takes two lists of polygons as input. Each polygon is represented as a linked list of vertices.
 
In its original form, the algorithm is divided into three phases:
* In the first phase, pairwise intersections between edges of the polygons are computed. Additional vertices are inserted into both polygons at the points of intersection; an intersection vertex holds a pointer to its counterpart in the other polygon.
* In the second phase, each intersection is marked as either an ''entry intersection'' or an ''exit intersection''. This is accomplished by evaluating the even–odd rule at the first vertex, andwhich thenallows traversingyou to know whether the first vertex is inside or outside the other polygon. andThen, markingfollowing the polygon's borders, the intersections are marked with alternating flags (the next intersection after an entry intersection must be an exit intersection).
* In the third phase, the result is generated. The algorithm starts at an unprocessed intersection and picks the direction of traversal based on the entry/exit flag: for an entry intersection it traverses forward, and for an exit intersection it traverses in reverse. Vertices are added to the result until the next intersection is found; the algorithm then switches to the corresponding intersection vertex in the other polygon and picks the traversal direction again using the same rule. If the next intersection has already been processed, the algorithm finishes the current component of the output and movesstarts toagain from an unprocessed intersection. The output is complete when there are no more unprocessed intersections.
 
The algorithm is not restricted to polygons and can handle arbitrary [[planeparametric curve]]s as segments, as long as there is a suitable pairwise intersection procedure.
 
A major shortcoming of the original Greiner–Hormann algorithm is the fact that it cannot handle degeneracies, such as common edges or intersections exactly at a vertex. The original paper suggests perturbing the vertices to remove them. Several modifications to handle degeneracy have been proposed in the literature.<ref name="foster"/>
 
==See also==
Line 50 ⟶ 41:
* [http://www.jasondavies.com/maps/clip/ Geographic Clipping] Describes the clipping algorithms in [[D3.js]].
* https://github.com/helderco/univ-polyclip An implementation in Python and Java.
* https://github.com/sjkellyw8r/PolygonClipping.jlGreinerHormann An implementation in [[Julia_(programming_language) | Julia]]JavaScript
* [http://tsusiatsoftware.net/jts/main.html JTS Topological Suite] A topological suite with a Java implementation
 
{{DEFAULTSORT:Greiner-Hormann clipping algorithm}}
[[Category:ClippingPolygon (computerclipping graphics)|*algorithms]]
[[Category:Computer graphics]]
 
 
{{compu-graphics-stub}}