Services & Resources / Wolfram Forums
MathGroup Archive
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2001

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

Search the Archive

Re: Urgent

  • To: mathgroup at
  • Subject: [mg27279] Re: Urgent
  • From: "Allan Hayes" <hay at>
  • Date: Fri, 16 Feb 2001 03:58:31 -0500 (EST)
  • References: <9686u0$>
  • Sender: owner-wri-mathgroup at

Here are two possibilites for 2D polygons
Both will give the angles in the correct quadrant.
angles2c will give the angles in the range  (-Pi ,2Pi] and
angles2r will give them in the range (-2Pi,2Pi). To convert them to the
range (-Pi ,2Pi]  we could use Mod[ . , 2Pi, -Pi] but this will slow the
computation down markedly.



The following will work for any dimensions, but it will give answers in the
range [0,Pi] and so leaves it ambiguous in 2D whether the true answer is for
example Pi/2 or -Pi/2.

angles[verts_] :=
  MapThread[ArcCos[(#1 .#2)/Sqrt[(#1.#1)(#2.#2)]] &,
    {RotateLeft[#], #} &[{1, -1}.({ RotateLeft[#], #} &[verts])]]

Here are some timings

verts = Table[Random[Real, {-1, 1}], {100000}, {2}];


        {10.22 Second,Null}


        {8.08 Second,Null}


        {62.01 Second,Null}

Allan Hayes
Mathematica Training and Consulting
Leicester UK
hay at
Voice: +44 (0)116 271 4198
Fax: +44 (0)870 164 0565

"oda" <adj at> wrote in message news:9686u0$3qi at
> Hi , all
> I'm currently use Mathematica 4.0 and I need to compute
> fastly the angle between  the vertices of a polygon.
> The statement of the problem is :
> Let be (P) a polygon with n vertices point, I want to calulate
> the angle (T) between all consecutif edge.
> (P) = {P1, P2, P3,.............,Pn}
> P1 is a 2 or 3 dimension point.
> angles between (PiPi+1, Pi+1Pi+2) i = 1, n-2;
> I have about (100000 points in polygon)
> Thanks in advance

  • Prev by Date: Combination Algorithm without brut force - Combine 4's into least 6's
  • Next by Date: Re: String to Number
  • Previous by thread: Re: Urgent
  • Next by thread: Bigger array taking less memory than smaller array