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$>
References: <gfejp2$od9$> <gfekjc$46l$> <gfelbm$cc9$>
Reply-To: <HIDDEN>
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: 1226512921 5591 (12 Nov 2008 18:02:01 GMT)
NNTP-Posting-Date: Wed, 12 Nov 2008 18:02:01 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1187260
Xref: comp.soft-sys.matlab:500451

"M K" <> wrote in message <gfelbm$cc9$>...
> 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