Reference
[1] http://www.cs.rit.edu /~ Icss571/filling/alt_parity.html
[2] http://cs.hust.edu.cn/webroot/courses/csgraphics/jiaocai.php? Bookpage = 5_c_c
[3] http://en.wikipedia.org/wiki/Nonzero-rule
In Graphics, you can determine whether a point is within a polygon. If the polygon is not self-Intersecting, you can simply determine whether the point is inside or outside the polygon. If the polygon is self-Intersecting, therefore, it must be determined based on the non-zero round robin rule and the odd-even rule.
Determines whether a polygon is self-intersecting. A polygon has other common points in the plane except the vertices.
Internal-External test
Non-self-crossing polygon: the polygon is connected only at the vertex, but there are no other common points in the plane. In this case, you can directly divide the inner-outer part.
Self-Intersecting polygon: a polygon has other common points in addition to vertices in the plane. In this case, the internal and external parts must be divided using the following methods.
(1) odd-even rule (odd-even rule): an odd number indicates inside the polygon, and an even number indicates outside the polygon.
P is a ray from any position. If the number of polygon edges that intersect the ray is odd, p is the internal point of the polygon; otherwise, it is the external point.
(2) nonzero winding number rule: if the number of loops is 0, it indicates that the circle is inside the polygon, and non-zero indicates that the circle is outside the polygon.
First, convert the edges of a polygon to vectors. Initialize the number of loops to zero. Then P is taken as a ray from any position. When moving from point P along the ray direction, the side passing through the ray in each direction is counted. Every time the side of the polygon passes through the ray from right to left, the circle is incremented by 1, from left to right, the number of loops is reduced by 1. After processing all the related edges of a polygon, if the number of loops is non-zero, p is the internal vertex. Otherwise, p is the external vertex.
The example in [1] is as follows,
Determine whether point P is inside the polygon and generates a Ray from point P (in any direction). When the side of the polygon goes through the ray from left to right, the number of loops decreases by 1, when the side of a polygon goes through a Ray from the right to the left, the number of rings is increased by 1, and the number of rings is not 0, which indicates the interior of the polygon.
Of course, the non-zero round number rule and the parity rule will determine the conflict, as shown in, the left side indicates that the number of round loops is determined by the parity rule as 2, indicating that the number is outside the polygon, so it is not filled. The right-side graph uses a non-zero ring rule to determine that the number of loops is 2, and non-0 indicates that the number is inside the polygon, so it is filled.
Another example is as follows:
Non-zero round robin rules and odd-even rules (non-zero winding number rule & odd-even rule) are applied in iPhone
1. cgcontextclip uses a non-zero loop number rule to determine the intersection of the current path and the cropping path.
2. cgcontexteoclip uses the parity loop rule to determine the intersection of the current path and the cropping path.