Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Vectors
Date: Wed, 12 Nov 2008 18:02:01 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 17
Message-ID: <gff5mp$5en$1@fred.mathworks.com>
References: <gfejp2$od9$1@fred.mathworks.com> <gfekjc$46l$1@fred.mathworks.com> <gfelbm$cc9$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 1226512921 5591 172.30.248.35 (12 Nov 2008 18:02:01 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Wed, 12 Nov 2008 18:02:01 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1187260
Xref: news.mathworks.com comp.soft-sys.matlab:500451

"M K" <maha_k@mathworks.com> wrote in message <gfelbm$cc9$1@fred.mathworks.com>...
> Sorry I should re-phrase that. 
> 
> Calculating the aangle between two vectors. I did a search on this forum and found another thread which gave two ways of calculating it 
> 
> 1) the usual acos(dot(A,B)/(norm(A)*norm(B))
> 
> 2) angle = atan2(norm(cross(a,b)),dot(a,b));
> 
> I get different answers when I use these two ... Any help will be appreciated!
-----------
  I assume that you are dealing with three-element vectors in three-dimensional space, with the angle between vectors being regarded as lying somewhere between 0 and pi.  In theory the two formulas you mention should give exactly the same answers.  However, in terms of computational robustness the first formula suffers a loss of accuracy for angles that lie very near either 0 or pi.  The derivative of the 'acos' function approaches infinity at such values and this results in excessive computational errors.  The 'atan2' function avoids this difficulty for all angles in the range.  That might account for the differences you allude to.

  It would help if you could give a concrete example of the a and b vector values and the differences you are seeing between the two formulas' results.

Roger Stafford