MathGroup Archive 2000

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: winding number

  • To: mathgroup at smc.vnet.net
  • Subject: [mg25449] Re: winding number
  • From: "Allan Hayes" <hay at haystack.demon.co.uk>
  • Date: Sun, 1 Oct 2000 02:44:31 -0400 (EDT)
  • References: <8qho3l$j8s@smc.vnet.net> <8r19jr$hun@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

 Will,
Here is complex number version of the angle adding method that you gave

(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]


(using complex numbers)
windingNumber2[point_, vList_] :=
  (Plus @@ Arg[RotateLeft[#]/# &[vList.{1, I} - point.{1, I}]])/(2Pi)

Timings:

vList = Table[Random[Real, {-1, 1}], {1000}, {2}];

windingNumber[{.1, -.2}, vList] // Timing

        {3.41 Second, 6.}

windingNumber2[{.1, -.2}, vList] // Timing

        {0.05 Second, 6.}


We could add a preliminary test, using a determinant, to deal with points on
the line.

Allan
---------------------
Allan Hayes
Mathematica Training and Consulting
Leicester UK
www.haystack.demon.co.uk
hay at haystack.demon.co.uk
Voice: +44 (0)116 271 4198
Fax: +44 (0)870 164 0565





  • Prev by Date: Re: LegendreP & Gauss quad bug
  • Next by Date: Re: StringQ?
  • Previous by thread: Re: Summary: List element manipulation
  • Next by thread: Re: Re: winding number