In two-dimensional
computer graphics
Computer graphics deals with generating images and art with the aid of computers. Computer graphics is a core technology in digital photography, film, video games, digital art, cell phone and computer displays, and many specialized applications. ...
, 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, it relies on knowing the direction of stroke for each part of the curve.
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.
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 ...
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.
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:
The
SVG computer graphics vector standard uses the non-zero rule by default when drawing polygons.
w3c.org, retrieved 2019 03 28
See also
* Even-odd rule
* Complex polygon
* Tessellation
* Polygon triangulation
* TrueType
References
External links
Definition of fill rules in SVG
Computer graphics algorithms
{{compu-prog-stub