From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Angle between two vectors
Date: Sun, 12 Apr 2009 19:35:01 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 17
Message-ID: <grtfp5$oal$>
References: <ef5ce9c.-1@webcrossing.raydaftYaTP> <fjj9nj$fia$> <fjk0tg$jli$> <fjlrpl$gii$> <grt6s5$2hh$>
Reply-To: <HIDDEN>
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: 1239564901 24917 (12 Apr 2009 19:35:01 GMT)
NNTP-Posting-Date: Sun, 12 Apr 2009 19:35:01 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1187260
Xref: comp.soft-sys.matlab:532184

"Uzair Siddiqui" <> wrote in message <grt6s5$2hh$>...
> I am just stuck in calculating angle between two points in Flash.
> I am using this
> angle =Math.abs(Math.atan2(x-x2,y-y2) * 180/Math.PI) ;
> But I am getting the angles between 0-180 instead of 0-360.

  When you say "angle between two points", I assume here you mean the angle measured counterclockwise from the positive x-axis around to the vector pointing from point P2 = (x2,y2) to point P = (x,y), creating an angle anywhere from 0 to 2*pi radians or 360 degrees.  Is that what you mean?

  If so, it can be obtained in degrees with matlab by

 angle = 180/pi*mod(atan2(y-y2,x-x2),2*pi);

which lies between 0 and 360 degrees.  (I presume this formula remains valid in Flash.)

  In your formula the arguments x-x2 and y-y2 are interchanged from this and the answer would lie between -180 and +180 without the 'mod' operation.

Roger Stafford