Path: news.mathworks.com!not-for-mail
From: "Roger Stafford" <ellieandrogerxyzzy@mindspring.com.invalid>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Angle between two vectors
Date: Mon, 10 Dec 2007 18:35:28 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 36
Message-ID: <fjk0tg$jli$1@fred.mathworks.com>
References: <ef5ce9c.-1@webcrossing.raydaftYaTP> <fjj9nj$fia$1@fred.mathworks.com>
Reply-To: "Roger Stafford" <ellieandrogerxyzzy@mindspring.com.invalid>
NNTP-Posting-Host: webapp-02-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1197311728 20146 172.30.248.37 (10 Dec 2007 18:35:28 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Mon, 10 Dec 2007 18:35:28 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1187260
Xref: news.mathworks.com comp.soft-sys.matlab:441822


"salih tuna" <salihtuna@gmail.com> wrote in message <fjj9nj$fia
$1@fred.mathworks.com>...
> hello,
> how can i calculate the angles so that they are in the range 0-360 degrees?
> thanks
> salih
> 
> "y Mehta" <mehtayogesh@gmail.(DOT).com> wrote in message
> <ef5ce9c.-1@webcrossing.raydaftYaTP>...
> > How do I find the angle between two unit vectors a and b?  I know I
> > can find cosine theta by the following formula:
> > 
> > theta = acos(dot(a,b));
> > 
> > However, how do I know whether the angle is actually theta, or -theta
> > or pi-theta or pi+theta??
> > 
> > Notice that the vectors are in three dimension (3d).
> > 
> > Thanks,
> > -YM
--------
  Y Mehta's question involved angles between vectors in three-dimensional 
space.  I can think of no reasonable definition for a canonical angle between 
such vectors which ranges from 0 to 360 degrees (0 to 2*pi radians.)

  However, if you are in two-dimensional space, then you can speak of the 
non-negative angle measured counterclockwise from vector a to vector b, 
and this would give the range you have requested.  If a = [x1,y1] and b = 
[x2,y2], then such an angle is given in matlab by:

 angle = mod(atan2(y2-y1,x2-x1),2*pi); % Range: 0 to 2*pi radians

(Multiply this answer by 180/pi to get degrees.)

Roger Stafford