Re: Urgent

*To*: mathgroup at smc.vnet.net*Subject*: [mg27244] Re: [mg27216] Urgent*From*: Tomas Garza <tgarza01 at prodigy.net.mx>*Date*: Tue, 13 Feb 2001 03:35:49 -0500 (EST)*References*: <200102120820.DAA03811@smc.vnet.net>*Sender*: owner-wri-mathgroup at wolfram.com

For the two dimensional case In[1]:= long[p_] := Sqrt[Dot[p, p]] In[2]:= p = Table[{Random[], Random[]}, {100000}]; In[3]:= lines = Rest[p] - Drop[p, -1]; In[4]:= angs = Table[ ArcCos[lines[[i]].lines[[i + 1]]/(long[lines[[i]]]* long[lines[[i + 1]]])], {i, 1, Length[lines] - 1}]; // Timing Out[4]= {8.3 Second, Null} Is this fast enough? In[5]:= Take[angs, 10] Out[5]= {2.95821, 2.94399, 1.76204, 1.37954, 3.02416, 2.75279, 1.95, 2.43478, \ 2.50759, 1.16486} (in radians, of course). You could compile the normalization of the vectors and get a reduction in time by a factor of 2: In[6]:= vcom = Compile[{{x, _Real, 1}}, Module[{t}, x/Sqrt[x.x]]]; In[7]:= angscom = Table[ArcCos[vcom[lines[[i]]].vcom[lines[[i + 1]]]], {i, 1, Length[lines] - 1}]; // Timing Out[37]= {4.89 Second, Null} Tomas Garza Mexico City ----- Original Message ----- From: "oda" <adj at ensm-douai.fr> To: mathgroup at smc.vnet.net Subject: [mg27244] [mg27216] Urgent > 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 >

**References**:**Urgent***From:*oda <adj@ensm-douai.fr>