Difference between revisions of "Nonzero-rule"
Karl Jones (Talk | contribs) (→External links) |
Karl Jones (Talk | contribs) |
||
Line 1: | Line 1: | ||
− | In two-dimensional [[computer graphics]], the '''non-zero winding rule''' is a means of determining whether a given point falls within an enclosed curve. | + | In two-dimensional [[computer graphics]], the '''non-zero winding rule''' is a means of determining whether a given point falls within an enclosed [[curve]]. |
Unlike the similar [[even-odd rule]], the non-zero rule relies on knowing the direction of stroke for each part of the curve. | Unlike the similar [[even-odd rule]], the non-zero rule relies on knowing the direction of stroke for each part of the curve. |
Latest revision as of 19:34, 25 April 2016
In two-dimensional computer graphics, the non-zero winding rule is a means of determining whether a given point falls within an enclosed curve.
Unlike the similar even-odd rule, the non-zero rule relies on knowing the direction of stroke for each part of the curve.
Description
For a given curve C and a given point P: construct a ray (a straight line) heading out from P in any direction towards infinity.
Find all the intersections of C with this ray.
Score up the winding number as follows:
- For every clockwise intersection (the curve passing through the ray from left to right, as viewed from P) subtract 1
- For every counter-clockwise intersection (curve passing from right to left, as viewed from P) add 1
If the total winding number is zero, P is outside C; otherwise, it is inside.
Discussion
The winding number is effectively a count of how many full counter-clockwise revolutions ('windings') the curve makes around P without doubling back on itself.
If P were a nail and C were a looped piece of string, try pulling some part of the string sideways away from the nail: it will either come free, or it will be found to be wound some number of times around the nail.
Some implementations instead score up the number of clockwise revolutions, so that clockwise crossings are awarded +1, counter-clockwise crossings -1. The result is the same.
Formal definition
One formal definition of the winding number of point P with respect to curve C (where P does not lie on the curve) is as follows:
Consider a point Q that travels once around C. The endpoint of a vector from P to Q, after normalization, travels along the unit circle centered at P. If we imagine the track of this endpoint as a rubber band, and let the band contract, it will end up wrapped about the circle some number of times. The winding number is the number of wraps (for clockwise wraps, the winding number is negative).
The SVG computer graphics vector standard has a feature that allows the use of the non-zero rule when drawing polygons.
See also
External links
- Nonzero-rule @ Wikipedia