       winding number

• To: mathgroup at smc.vnet.net
• Subject: [mg25345] winding number
• From: Will Self <wself at msubillings.edu>
• Date: Sat, 23 Sep 2000 03:36:11 -0400 (EDT)
• Sender: owner-wri-mathgroup at wolfram.com

```There has been some discussion of finding out whether a point in the
plane is enclosed in a given polygon.  Here is some code that will
calculate the winding number of a polygonal closed curve about a given
point.  The curve should be given as a list of vertices (the first
vertex does not have to be repeated at the end of the list).  The list
of vertices is called vList in the code.  This is really from Cauchy's
theorem with the integration along segments already done.

Will Self

---------------------------------------------------

windingNumber[point_, vList_] := Module[
{g, angle},
g[t_] := Mod[t + Pi, 2Pi] - Pi;
angle[p_, a1_, a2_] := g[ArcTan @@ (a2 - p) - ArcTan @@ (a1 - p)];
(Plus @@ MapThread [ angle[point, #1, #2] & , {vList, RotateLeft[vList]}
])/2/Pi]

Sent via Deja.com http://www.deja.com/