Greiner–Hormann Clipping Algorithm
   HOME

TheInfoList



OR:

The Greiner-Hormann algorithm is used in computer graphics for polygon
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 ...
. It performs better than the
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 ...
, but cannot handle degeneracies. It can process both self-intersecting and non-convex polygons. It can be trivially generalized to compute other
Boolean operations on polygons Boolean operations on polygons are a set of Boolean operations (AND, OR, NOT, XOR, ...) operating on one or more sets of polygons in computer graphics. These sets of operations are widely used in computer graphics, CAD, and in EDA (in integrated ...
, such as union and difference. The algorithm is based on the definition of the "inside" of a polygon based on the
winding number In mathematics, the winding number or winding index of a closed curve in the plane (mathematics), plane around a given point (mathematics), point is an integer representing the total number of times that the curve travels counterclockwise aroun ...
. It considers regions with odd winding number to be inside the polygon; this is known as the
even–odd rule The even–odd rule is an algorithm implemented in vector-based graphic software, like the PostScript language and Scalable Vector Graphics (SVG), which determines how a graphical shape with more than one closed outline will be filled. Unlike the ...
. It takes two lists of polygons as input. 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, which allows you to know whether the first vertex is inside or outside the other polygon. Then, following 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 starts again 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
parametric curve In mathematics, a parametric equation expresses several quantities, such as the coordinates of a point (mathematics), point, as Function (mathematics), functions of one or several variable (mathematics), variables called parameters. In the case ...
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.


See also

*
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 ...
* Sutherland–Hodgman clipping algorithm *
Weiler–Atherton clipping algorithm The Weiler–Atherton is a polygon-clipping algorithm. It is used in areas like computer graphics and games development where clipping of polygons is needed. It allows clipping of a ''subject or candidate polygon'' by an arbitrarily shaped ''clippi ...
*
Boolean operations on polygons Boolean operations on polygons are a set of Boolean operations (AND, OR, NOT, XOR, ...) operating on one or more sets of polygons in computer graphics. These sets of operations are widely used in computer graphics, CAD, and in EDA (in integrated ...


References


External links


Geographic Clipping
Describes the clipping algorithms in
D3.js D3.js (also known as D3, short for Data-Driven Documents) is a JavaScript library for producing dynamic, interactive data visualizations in web browsers. It makes use of Scalable Vector Graphics (SVG), HTML5, and Cascading Style Sheets (CSS) stan ...
. * https://github.com/helderco/univ-polyclip An implementation in Python and Java. * https://github.com/w8r/GreinerHormann An implementation in JavaScript
JTS Topological Suite
A topological suite with a Java implementation Polygon clipping algorithms {{compu-graphics-stub