Path: news.mathworks.com!not-for-mail
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$1@fred.mathworks.com>
References: <ef5ce9c.-1@webcrossing.raydaftYaTP> <fjj9nj$fia$1@fred.mathworks.com> <fjk0tg$jli$1@fred.mathworks.com> <fjlrpl$gii$1@fred.mathworks.com> <grt6s5$2hh$1@fred.mathworks.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: webapp-05-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1239564901 24917 172.30.248.35 (12 Apr 2009 19:35:01 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Sun, 12 Apr 2009 19:35:01 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1187260
Xref: news.mathworks.com comp.soft-sys.matlab:532184

"Uzair Siddiqui" <uzair@meragsm.com> wrote in message <grt6s5$2hh$1@fred.mathworks.com>...
> 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