Picture standing at a fixed point while a friend walks the entire boundary of a polygon once, all the way around, back to where they started. As they walk, look at the direction from you to them. That direction rotates. When they finish the lap, how many full turns did that direction make?
That count is the winding number. If your friend's loop never enclosed you, the direction wobbles back and forth but ends up net zero turns — you are outside. If the loop wraps around you once, the direction completes exactly one full turn — you are inside.
It sounds like a roundabout way to ask a simple question, but this "count the turns" idea turns out to be sturdier than the classic ray-casting trick the moment a polygon gets messy: self-crossing edges, overlapping loops, or shapes traced in different directions. The winding number does not just say inside or outside — it says how many times wrapped, and that extra information is exactly what rescues the ambiguous cases.
Comments
Loading comments...