Path: news.mathworks.com!newsfeed-00.mathworks.com!news.kjsl.com!newsfeed.stanford.edu!headwall.stanford.edu!newshub.sdsu.edu!elnk-nf2-pas!newsfeed.earthlink.net!stamper.news.pas.earthlink.net!newsread3.news.pas.earthlink.net.POSTED!5f968bd6!not-for-mail
From: ellieandrogerxyzzy@mindspring.com.invalid (Roger Stafford)
Newsgroups: comp.soft-sys.matlab
Subject: Re: Angle between two vectors
Message-ID: <ellieandrogerxyzzy-1007070127090001@dialup-4.232.57.130.dial1.losangeles1.level3.net>
References: <ef5ce9c.-1@webcrossing.raydaftYaTP> <1184052626.324470.175540@n2g2000hse.googlegroups.com>
Organization: -
Lines: 41
Date: Tue, 10 Jul 2007 08:27:08 GMT
NNTP-Posting-Host: 4.232.57.130
X-Complaints-To: abuse@earthlink.net
X-Trace: newsread3.news.pas.earthlink.net 1184056028 4.232.57.130 (Tue, 10 Jul 2007 01:27:08 PDT)
NNTP-Posting-Date: Tue, 10 Jul 2007 01:27:08 PDT
Xref: news.mathworks.com comp.soft-sys.matlab:418160


In article <1184052626.324470.175540@n2g2000hse.googlegroups.com>, Greg
Heath <heath@alumni.brown.edu> wrote:

> On Jul 9, 5:16 pm, "y Mehta" <mehtayogesh@gmail.(DOT).com> wrote:
> > 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));
> 
> Invalid since it is possible that abs(dot(a,b)) > 1.
> 
> costheta = dot(a,b)/(norm(a)*norm(b));
> theta = acos(costheta);
> 
> will give you the anser in the interval [0,pi].
> 
> > However, how do I know whether the angle is
> > actually theta, or -theta or pi-theta or pi+theta??
> 
> Angles between vectors only lie in the interval [0,pi].
> 
> > Notice that the vectors are in three dimension (3d).
> 
> Dimensionality of the original space is irrelevant. As long as
> norm(a)*norm(b) > 0, the vectors uniquely define a 2-d space when
> dot(a,b) ~= 0 and a unique 1-d space otherwise.
> 
> Hope this helps.
> 
> Greg
---------------
  Greg, Y Mehta did specifically state that a and b are unit vectors, so
his formula is in fact correct as it stands, though subject to increasing
errors as its dot product approaches +1 or -1.  When a and b are nearly
parallel, the same kind of trouble occurs with the formula you have given
here.  In such cases there is a real need to combine the scalar dot
product with the vector cross product in order to make use of both the
sine and cosine in calculating the angle accurately, which is what the
'tan2' formula does.

Roger Stafford