From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Angle between two vectors
Date: Fri, 18 Jun 2010 04:38:03 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 28
Message-ID: <hvet7b$b6c$>
References: <ef5ce9c.-1@webcrossing.raydaftYaTP> <> <> <hvbni8$s0h$> <hvbra7$lcp$> <hvbs37$a30$> <hvc2qe$59b$> <hvejah$ab6$>
Reply-To: <HIDDEN>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: 1276835883 11468 (18 Jun 2010 04:38:03 GMT)
NNTP-Posting-Date: Fri, 18 Jun 2010 04:38:03 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1187260
Xref: comp.soft-sys.matlab:646024

"Beho nashed" <> wrote in message <hvejah$ab6$>...
> Hello Roger,
> I keep selecting points for an angle bigger than 90 degree, but the program is giving me an angle less than 90 deg!!!
> .......

  There must be something amiss, either with the way you are selecting your points or the way their coordinates are being collected.  I have done a copy and paste on the three different forms of the formulas we have discussed and after supplying a missing left bracket in the last one, (sorry about that) they all give the same answer which can be anywhere between zero and pi radians, or in degrees, anywhere between 0 and 180 degrees.  I illustrate with one example here which yields the correct answer of 135 degrees (after multiplying by 180/pi to transform from radians to degrees) for all three formulas.

P1 =  [2,1];
P2 =  [6,3];
P3 = [-7,4];
x = [P1(1);P2(1);P3(1)];
y = [P1(2);P2(2);P3(2)];
x1 = x(1); y1 = y(1);
x2 = x(2); y2 = y(2);
x3 = x(3); y3 = y(3);
ang1 = atan2(abs(det([x1,x2,x3;y1,y2,y3;1,1,1])), ...
ang2 = atan2(abs(det([x(1),x(2),x(3);y(1),y(2),y(3);1,1,1])), ...
ang3 = atan2(abs(det([P2-P1;P3-P1])),dot(P2-P1,P3-P1));

180/pi*[ang1;ang2;ang3] =


Roger Stafford