0
$\begingroup$

Pretty much the title, given a closed curve in 2D, defined by a set of points, and a point. What's the algorithm to calculate the winding number of that curve, point pair?

$\endgroup$
0
$\begingroup$

Winding number as in https://en.wikipedia.org/wiki/Winding_number?

Unless I'm mistaken, one way is to fire, say, a horizontal 'ray' out from your point towards, say, $+\infty$. Each time you cross an edge, $(V_n V_{n+1})$ that is going up (i.e.$V_n[y] <V_{n+1}[y]$) , increment a counter, and decrement if the edge is going down.

The special cases of horizontal edges and vertices that lie on the ray are left as a (not too difficult) exercise for the reader.

If you want to do it quickly/approximately with a graphics API, you can use stencil buffers.

| improve this answer | |
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.