<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/151925</link>
    <title>MATLAB Central Newsreader - Angle between two vectors</title>
    <description>Feed for thread: Angle between two vectors</description>
    <language>en-us</language>
    <copyright>&amp;copy;1994-2008 by The MathWorks, Inc.</copyright>
    <webmaster>webmaster@mathworks.com</webmaster>
    <generator>MATLAB Central Newsreader</generator>
    <docs>http://blogs.law.harvard.edu/tech/rss</docs>
    <ttl>60</ttl>
    <image>
      <title>The MathWorks</title>
      <url>http://www.mathworks.com/images/membrane_icon.gif</url>
    </image>
    <item>
      <pubDate>Mon, 09 Jul 2007 17:16:29 -0400</pubDate>
      <title>Angle between two vectors</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/151925#381924</link>
      <author>y Mehta</author>
      <description>How do I find the angle between two unit vectors a and b? I know I&lt;br&gt;
can find cosine theta by the following formula:&lt;br&gt;
&lt;br&gt;
theta = acos(dot(a,b));&lt;br&gt;
&lt;br&gt;
However, how do I know whether the angle is actually theta, or -theta&lt;br&gt;
or pi-theta or pi+theta??&lt;br&gt;
&lt;br&gt;
Notice that the vectors are in three dimension (3d).&lt;br&gt;
&lt;br&gt;
Thanks,&lt;br&gt;
-YM&lt;br&gt;
</description>
    </item>
    <item>
      <pubDate>Tue, 10 Jul 2007 00:30:26 -0400</pubDate>
      <title>Re: Angle between two vectors</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/151925#381987</link>
      <author> Greg Heath</author>
      <description>On Jul 9, 5:16 pm, "y Mehta" &amp;lt;mehtayogesh@gmail.(DOT).com&amp;gt; wrote:&lt;br&gt;
&amp;gt; How do I find the angle between two unit vectors a and b? I know I&lt;br&gt;
&amp;gt; can find cosine theta by the following formula:&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; theta = acos(dot(a,b));&lt;br&gt;
&amp;gt;&lt;br&gt;
&lt;br&gt;
Invalid since it is possible that abs(dot(a,b)) &amp;gt; 1.&lt;br&gt;
&lt;br&gt;
costheta = dot(a,b)/(norm(a)*norm(b));&lt;br&gt;
theta = acos(costheta);&lt;br&gt;
&lt;br&gt;
will give you the anser in the interval [0,pi].&lt;br&gt;
&lt;br&gt;
&amp;gt; However, how do I know whether the angle is&lt;br&gt;
&amp;gt; actually theta, or -theta or pi-theta or pi+theta??&lt;br&gt;
&lt;br&gt;
Angles between vectors only lie in the interval [0,pi].&lt;br&gt;
&lt;br&gt;
&amp;gt; Notice that the vectors are in three dimension (3d).&lt;br&gt;
&lt;br&gt;
Dimensionality of the original space is irrelevant. As long as&lt;br&gt;
norm(a)*norm(b) &amp;gt; 0, the vectors uniquely define a 2-d space when&lt;br&gt;
dot(a,b) ~= 0 and a unique 1-d space otherwise.&lt;br&gt;
&lt;br&gt;
Hope this helps.&lt;br&gt;
&lt;br&gt;
Greg&lt;br&gt;
&lt;br&gt;
</description>
    </item>
    <item>
      <pubDate>Tue, 10 Jul 2007 02:57:36 -0400</pubDate>
      <title>Re: Angle between two vectors</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/151925#381952</link>
      <author>ellieandrogerxyzzy@mindspring.com.invalid (Roger Stafford)</author>
      <description>In article &amp;lt;ef5ce9c.-1@webcrossing.raydaftYaTP&amp;gt;, "y Mehta"&lt;br&gt;
&amp;lt;mehtayogesh@gmail.(DOT).com&amp;gt; wrote:&lt;br&gt;
&lt;br&gt;
&amp;gt; How do I find the angle between two unit vectors a and b? I know I&lt;br&gt;
&amp;gt; can find cosine theta by the following formula:&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; theta = acos(dot(a,b));&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; However, how do I know whether the angle is actually theta, or -theta&lt;br&gt;
&amp;gt; or pi-theta or pi+theta??&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Notice that the vectors are in three dimension (3d).&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Thanks,&lt;br&gt;
&amp;gt; -YM&lt;br&gt;
---------------------&lt;br&gt;
&amp;nbsp;&amp;nbsp;It is usually understood that the angle between two three-dimensional&lt;br&gt;
vectors is measured by the shortest great circle path between them, which&lt;br&gt;
means that it must lie between 0 and pi radians.  To get such an answer,&lt;br&gt;
the best method, in my opinion, is this:&lt;br&gt;
&lt;br&gt;
&amp;nbsp;angle = atan2(norm(cross(a,b)),dot(a,b));&lt;br&gt;
&lt;br&gt;
Since the first argument must be non-negative, the angle will lie&lt;br&gt;
somewhere in the two first quadrants, and thus be between 0 and pi.  This&lt;br&gt;
formula remains valid even if a and b are not unit vectors.&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;Your 'acos' formula gives the correct answer with unit vectors as it&lt;br&gt;
stands, but it encounters an accuracy problem for angles that are near 0&lt;br&gt;
or pi.  This is the main reason for my preference for the 'atan2' method.&lt;br&gt;
&lt;br&gt;
Roger Stafford&lt;br&gt;
</description>
    </item>
    <item>
      <pubDate>Tue, 10 Jul 2007 08:27:08 -0400</pubDate>
      <title>Re: Angle between two vectors</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/151925#381996</link>
      <author>ellieandrogerxyzzy@mindspring.com.invalid (Roger Stafford)</author>
      <description>In article &amp;lt;1184052626.324470.175540@n2g2000hse.googlegroups.com&amp;gt;, Greg&lt;br&gt;
Heath &amp;lt;heath@alumni.brown.edu&amp;gt; wrote:&lt;br&gt;
&lt;br&gt;
&amp;gt; On Jul 9, 5:16 pm, "y Mehta" &amp;lt;mehtayogesh@gmail.(DOT).com&amp;gt; wrote:&lt;br&gt;
&amp;gt; &amp;gt; How do I find the angle between two unit vectors a and b? I know I&lt;br&gt;
&amp;gt; &amp;gt; can find cosine theta by the following formula:&lt;br&gt;
&amp;gt; &amp;gt;&lt;br&gt;
&amp;gt; &amp;gt; theta = acos(dot(a,b));&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Invalid since it is possible that abs(dot(a,b)) &amp;gt; 1.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; costheta = dot(a,b)/(norm(a)*norm(b));&lt;br&gt;
&amp;gt; theta = acos(costheta);&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; will give you the anser in the interval [0,pi].&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; However, how do I know whether the angle is&lt;br&gt;
&amp;gt; &amp;gt; actually theta, or -theta or pi-theta or pi+theta??&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Angles between vectors only lie in the interval [0,pi].&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; Notice that the vectors are in three dimension (3d).&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Dimensionality of the original space is irrelevant. As long as&lt;br&gt;
&amp;gt; norm(a)*norm(b) &amp;gt; 0, the vectors uniquely define a 2-d space when&lt;br&gt;
&amp;gt; dot(a,b) ~= 0 and a unique 1-d space otherwise.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Hope this helps.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Greg&lt;br&gt;
---------------&lt;br&gt;
&amp;nbsp;&amp;nbsp;Greg, Y Mehta did specifically state that a and b are unit vectors, so&lt;br&gt;
his formula is in fact correct as it stands, though subject to increasing&lt;br&gt;
errors as its dot product approaches +1 or -1.  When a and b are nearly&lt;br&gt;
parallel, the same kind of trouble occurs with the formula you have given&lt;br&gt;
here.  In such cases there is a real need to combine the scalar dot&lt;br&gt;
product with the vector cross product in order to make use of both the&lt;br&gt;
sine and cosine in calculating the angle accurately, which is what the&lt;br&gt;
'tan2' formula does.&lt;br&gt;
&lt;br&gt;
Roger Stafford&lt;br&gt;
</description>
    </item>
    <item>
      <pubDate>Tue, 10 Jul 2007 14:55:26 -0400</pubDate>
      <title>Re: Angle between two vectors</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/151925#382190</link>
      <author> Greg Heath</author>
      <description>On Jul 10, 4:27 am, ellieandrogerxy...@mindspring.com.invalid (Roger&lt;br&gt;
Stafford) wrote:&lt;br&gt;
&amp;gt; In article &amp;lt;1184052626.324470.175...@n2g2000hse.googlegroups.com&amp;gt;, Greg&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; Heath &amp;lt;h...@alumni.brown.edu&amp;gt; wrote:&lt;br&gt;
&amp;gt; &amp;gt; On Jul 9, 5:16 pm, "y Mehta" &amp;lt;mehtayogesh@gmail.(DOT).com&amp;gt; wrote:&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; How do I find the angle between two unit vectors a and b? I know I&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; can find cosine theta by the following formula:&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; theta = acos(dot(a,b));&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; &amp;gt; Invalid since it is possible that abs(dot(a,b)) &amp;gt; 1.&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; &amp;gt; costheta = dot(a,b)/(norm(a)*norm(b));&lt;br&gt;
&amp;gt; &amp;gt; theta = acos(costheta);&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; &amp;gt; will give you the anser in the interval [0,pi].&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; However, how do I know whether the angle is&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; actually theta, or -theta or pi-theta or pi+theta??&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; &amp;gt; Angles between vectors only lie in the interval [0,pi].&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; Notice that the vectors are in three dimension (3d).&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; &amp;gt; Dimensionality of the original space is irrelevant. As long as&lt;br&gt;
&amp;gt; &amp;gt; norm(a)*norm(b) &amp;gt; 0, the vectors uniquely define a 2-d space when&lt;br&gt;
&amp;gt; &amp;gt; dot(a,b) ~= 0 and a unique 1-d space otherwise.&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; &amp;gt; Hope this helps.&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; &amp;gt; Greg&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; ---------------&lt;br&gt;
&amp;gt;   Greg, Y Mehta did specifically state that a and b are unit vectors, so&lt;br&gt;
&amp;gt; his formula is in fact correct as it stands, though subject to increasing&lt;br&gt;
&amp;gt; errors as its dot product approaches +1 or -1.  When a and b are nearly&lt;br&gt;
&amp;gt; parallel, the same kind of trouble occurs with the formula you have given&lt;br&gt;
&amp;gt; here.  In such cases there is a real need to combine the scalar dot&lt;br&gt;
&amp;gt; product with the vector cross product in order to make use of both the&lt;br&gt;
&amp;gt; sine and cosine in calculating the angle accurately, which is what the&lt;br&gt;
&amp;gt; 'tan2' formula does.&lt;br&gt;
&lt;br&gt;
Thanks.&lt;br&gt;
&lt;br&gt;
For some problem in the past (probably single precision?) I got better&lt;br&gt;
accuracy using&lt;br&gt;
&lt;br&gt;
sign(sintheta)*acos(costheta)&lt;br&gt;
&lt;br&gt;
instead of atan2.&lt;br&gt;
&lt;br&gt;
Hope this helps.&lt;br&gt;
&lt;br&gt;
Greg&lt;br&gt;
&lt;br&gt;
Hope this helps.&lt;br&gt;
&lt;br&gt;
</description>
    </item>
    <item>
      <pubDate>Tue, 10 Jul 2007 23:22:36 -0400</pubDate>
      <title>Re: Angle between two vectors</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/151925#382202</link>
      <author>ellieandrogerxyzzy@mindspring.com.invalid (Roger Stafford)</author>
      <description>In article &amp;lt;1184104526.774530.54800@n60g2000hse.googlegroups.com&amp;gt;, Greg&lt;br&gt;
Heath &amp;lt;heath@alumni.brown.edu&amp;gt; wrote:&lt;br&gt;
&lt;br&gt;
&amp;gt; For some problem in the past (probably single precision?) I got better&lt;br&gt;
&amp;gt; accuracy using&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; sign(sintheta)*acos(costheta)&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; instead of atan2.&lt;br&gt;
---------------&lt;br&gt;
&amp;nbsp;&amp;nbsp;I don't know why that would be better, Greg.  The acos(costheta) is&lt;br&gt;
subject to the same problem as before.  When costheta is very near 1, the&lt;br&gt;
accuracy is very much inferior to that of 'atan2'.  I would think this&lt;br&gt;
would be equally true in single precision.&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;Here's a concrete example of what I am referring to:&lt;br&gt;
&lt;br&gt;
&amp;nbsp;format long&lt;br&gt;
&amp;nbsp;a = pi*(1-1/10^8); % Choose an angle a little below pi&lt;br&gt;
&amp;nbsp;a2 = atan2(sin(a),cos(a)); % Use atan2&lt;br&gt;
&amp;nbsp;a3 = acos(cos(a));  % Use acos&lt;br&gt;
&amp;nbsp;[a;a2;a3;a-a2;a-a3] % Compare results&lt;br&gt;
&lt;br&gt;
&amp;nbsp;a = pi/2*1.123;  % Now select an angle near pi/2&lt;br&gt;
&amp;nbsp;a2 = atan2(sin(a),cos(a)); % atan2 again&lt;br&gt;
&amp;nbsp;a3 = acos(cos(a));  % Then acos&lt;br&gt;
&amp;nbsp;[a;a2;a3;a-a2;a-a3] % Make the same comparisons&lt;br&gt;
&lt;br&gt;
&amp;nbsp;ans =&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;3.14159262217387&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;3.14159262217387&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;3.14159262378747&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;0&lt;br&gt;
&amp;nbsp;&amp;nbsp;-0.00000000161360&lt;br&gt;
&lt;br&gt;
&amp;nbsp;ans =&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;1.76400427499067&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;1.76400427499067&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;1.76400427499067&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;0.00000000000000&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;0.00000000000000&lt;br&gt;
&lt;br&gt;
As you see, there is a very distinct loss of accuracy in 'acos' for angles&lt;br&gt;
near pi.  Some seven entire decimal places have been lost - that is,&lt;br&gt;
errors are several million times as large as normal.  On the other hand,&lt;br&gt;
the angle near pi/2 yields the customary 1 in 2^52 accuracy.&lt;br&gt;
&lt;br&gt;
Roger Stafford&lt;br&gt;
</description>
    </item>
    <item>
      <pubDate>Mon, 16 Jul 2007 01:46:40 -0400</pubDate>
      <title>Re: Angle between two vectors</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/151925#383085</link>
      <author>Yogesh Mehta</author>
      <description>Thanks Greg and Roger. Your inputs were very useful for me.&lt;br&gt;
</description>
    </item>
    <item>
      <pubDate>Mon, 10 Dec 2007 11:59:47 -0500</pubDate>
      <title>Re: Angle between two vectors</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/151925#405477</link>
      <author>salih tuna</author>
      <description>hello,&lt;br&gt;
how can i calculate the angles so that they are in the range&lt;br&gt;
0-360 degrees?&lt;br&gt;
thanks&lt;br&gt;
salih&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
"y Mehta" &amp;lt;mehtayogesh@gmail.(DOT).com&amp;gt; wrote in message&lt;br&gt;
&amp;lt;ef5ce9c.-1@webcrossing.raydaftYaTP&amp;gt;...&lt;br&gt;
&amp;gt; How do I find the angle between two unit vectors a and b?&lt;br&gt;
I know I&lt;br&gt;
&amp;gt; can find cosine theta by the following formula:&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; theta = acos(dot(a,b));&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; However, how do I know whether the angle is actually&lt;br&gt;
theta, or -theta&lt;br&gt;
&amp;gt; or pi-theta or pi+theta??&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Notice that the vectors are in three dimension (3d).&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Thanks,&lt;br&gt;
&amp;gt; -YM&lt;br&gt;
&lt;br&gt;
</description>
    </item>
    <item>
      <pubDate>Mon, 10 Dec 2007 12:00:24 -0500</pubDate>
      <title>Re: Angle between two vectors</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/151925#405479</link>
      <author>salih tuna</author>
      <description>hello,&lt;br&gt;
how can i calculate the angles so that they are in the range&lt;br&gt;
0-360 degrees?&lt;br&gt;
thanks&lt;br&gt;
salih&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
"y Mehta" &amp;lt;mehtayogesh@gmail.(DOT).com&amp;gt; wrote in message&lt;br&gt;
&amp;lt;ef5ce9c.-1@webcrossing.raydaftYaTP&amp;gt;...&lt;br&gt;
&amp;gt; How do I find the angle between two unit vectors a and b?&lt;br&gt;
I know I&lt;br&gt;
&amp;gt; can find cosine theta by the following formula:&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; theta = acos(dot(a,b));&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; However, how do I know whether the angle is actually&lt;br&gt;
theta, or -theta&lt;br&gt;
&amp;gt; or pi-theta or pi+theta??&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Notice that the vectors are in three dimension (3d).&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Thanks,&lt;br&gt;
&amp;gt; -YM&lt;br&gt;
&lt;br&gt;
</description>
    </item>
    <item>
      <pubDate>Mon, 10 Dec 2007 18:35:28 -0500</pubDate>
      <title>Re: Angle between two vectors</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/151925#405545</link>
      <author>Roger Stafford</author>
      <description>"salih tuna" &amp;lt;salihtuna@gmail.com&amp;gt; wrote in message &amp;lt;fjj9nj$fia&lt;br&gt;
$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; hello,&lt;br&gt;
&amp;gt; how can i calculate the angles so that they are in the range 0-360 degrees?&lt;br&gt;
&amp;gt; thanks&lt;br&gt;
&amp;gt; salih&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; "y Mehta" &amp;lt;mehtayogesh@gmail.(DOT).com&amp;gt; wrote in message&lt;br&gt;
&amp;gt; &amp;lt;ef5ce9c.-1@webcrossing.raydaftYaTP&amp;gt;...&lt;br&gt;
&amp;gt; &amp;gt; How do I find the angle between two unit vectors a and b?  I know I&lt;br&gt;
&amp;gt; &amp;gt; can find cosine theta by the following formula:&lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; theta = acos(dot(a,b));&lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; However, how do I know whether the angle is actually theta, or -theta&lt;br&gt;
&amp;gt; &amp;gt; or pi-theta or pi+theta??&lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; Notice that the vectors are in three dimension (3d).&lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; Thanks,&lt;br&gt;
&amp;gt; &amp;gt; -YM&lt;br&gt;
--------&lt;br&gt;
&amp;nbsp;&amp;nbsp;Y Mehta's question involved angles between vectors in three-dimensional &lt;br&gt;
space.  I can think of no reasonable definition for a canonical angle between &lt;br&gt;
such vectors which ranges from 0 to 360 degrees (0 to 2*pi radians.)&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;However, if you are in two-dimensional space, then you can speak of the &lt;br&gt;
non-negative angle measured counterclockwise from vector a to vector b, &lt;br&gt;
and this would give the range you have requested.  If a = [x1,y1] and b = &lt;br&gt;
[x2,y2], then such an angle is given in matlab by:&lt;br&gt;
&lt;br&gt;
&amp;nbsp;angle = mod(atan2(y2-y1,x2-x1),2*pi); % Range: 0 to 2*pi radians&lt;br&gt;
&lt;br&gt;
(Multiply this answer by 180/pi to get degrees.)&lt;br&gt;
&lt;br&gt;
Roger Stafford&lt;br&gt;
</description>
    </item>
    <item>
      <pubDate>Tue, 11 Dec 2007 11:20:21 -0500</pubDate>
      <title>Re: Angle between two vectors</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/151925#405662</link>
      <author>salih tuna</author>
      <description>Hi,&lt;br&gt;
thanks a lot for your reply. yes they are in 2d, sorry i&lt;br&gt;
forgot to mention.&lt;br&gt;
i tried to apply the formula but i am getting wrong result.&lt;br&gt;
for example i want to calculate the angle between a = [1 1]&lt;br&gt;
and b = [0 -1] which is 225 degrees. with this formulae i&lt;br&gt;
got 243.4. i couldn't see where i am doing the mistake.&lt;br&gt;
thanks a lot in advance&lt;br&gt;
salih&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
"Roger Stafford" &amp;lt;ellieandrogerxyzzy@mindspring.com.invalid&amp;gt;&lt;br&gt;
wrote in message &amp;lt;fjk0tg$jli$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; "salih tuna" &amp;lt;salihtuna@gmail.com&amp;gt; wrote in message&lt;br&gt;
&amp;lt;fjj9nj$fia&lt;br&gt;
&amp;gt; $1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; &amp;gt; hello,&lt;br&gt;
&amp;gt; &amp;gt; how can i calculate the angles so that they are in the&lt;br&gt;
range 0-360 degrees?&lt;br&gt;
&amp;gt; &amp;gt; thanks&lt;br&gt;
&amp;gt; &amp;gt; salih&lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; "y Mehta" &amp;lt;mehtayogesh@gmail.(DOT).com&amp;gt; wrote in message&lt;br&gt;
&amp;gt; &amp;gt; &amp;lt;ef5ce9c.-1@webcrossing.raydaftYaTP&amp;gt;...&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; How do I find the angle between two unit vectors a and&lt;br&gt;
b?  I know I&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; can find cosine theta by the following formula:&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; theta = acos(dot(a,b));&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; However, how do I know whether the angle is actually&lt;br&gt;
theta, or -theta&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; or pi-theta or pi+theta??&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; Notice that the vectors are in three dimension (3d).&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; Thanks,&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; -YM&lt;br&gt;
&amp;gt; --------&lt;br&gt;
&amp;gt;   Y Mehta's question involved angles between vectors in&lt;br&gt;
three-dimensional &lt;br&gt;
&amp;gt; space.  I can think of no reasonable definition for a&lt;br&gt;
canonical angle between &lt;br&gt;
&amp;gt; such vectors which ranges from 0 to 360 degrees (0 to 2*pi&lt;br&gt;
radians.)&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt;   However, if you are in two-dimensional space, then you&lt;br&gt;
can speak of the &lt;br&gt;
&amp;gt; non-negative angle measured counterclockwise from vector a&lt;br&gt;
to vector b, &lt;br&gt;
&amp;gt; and this would give the range you have requested.  If a =&lt;br&gt;
[x1,y1] and b = &lt;br&gt;
&amp;gt; [x2,y2], then such an angle is given in matlab by:&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt;  angle = mod(atan2(y2-y1,x2-x1),2*pi); % Range: 0 to 2*pi&lt;br&gt;
radians&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; (Multiply this answer by 180/pi to get degrees.)&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Roger Stafford&lt;br&gt;
&lt;br&gt;
</description>
    </item>
    <item>
      <pubDate>Tue, 11 Dec 2007 13:56:20 -0500</pubDate>
      <title>Re: Angle between two vectors</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/151925#405697</link>
      <author>Roger Stafford</author>
      <description>"salih tuna" &amp;lt;salihtuna@gmail.com&amp;gt; wrote in message &amp;lt;fjlrpl$gii&lt;br&gt;
$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; Hi,&lt;br&gt;
&amp;gt; thanks a lot for your reply. yes they are in 2d, sorry i&lt;br&gt;
&amp;gt; forgot to mention.&lt;br&gt;
&amp;gt; i tried to apply the formula but i am getting wrong result.&lt;br&gt;
&amp;gt; for example i want to calculate the angle between a = [1 1]&lt;br&gt;
&amp;gt; and b = [0 -1] which is 225 degrees. with this formulae i&lt;br&gt;
&amp;gt; got 243.4. i couldn't see where i am doing the mistake.&lt;br&gt;
&amp;gt; thanks a lot in advance&lt;br&gt;
&amp;gt; salih&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; "Roger Stafford" &amp;lt;ellieandrogerxyzzy@mindspring.com.invalid&amp;gt;&lt;br&gt;
&amp;gt; wrote in message &amp;lt;fjk0tg$jli$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; &amp;gt;  angle = mod(atan2(y2-y1,x2-x1),2*pi); % Range: 0 to 2*pi&lt;br&gt;
--------&lt;br&gt;
&amp;nbsp;&amp;nbsp;I certainly owe you an apology, Salih.  That formula I gave you is very, very &lt;br&gt;
wrong.  I can't imagine what I was thinking about when I wrote it.  Chalk it up &lt;br&gt;
to momentary insanity!  :-)  The correct computation should be as follows.&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;Assuming a = [x1,y1] and b = [x2,y2] are two vectors with their bases at the &lt;br&gt;
origin, the non-negative angle between them measured counterclockwise &lt;br&gt;
from a to b is given by&lt;br&gt;
&lt;br&gt;
&amp;nbsp;angle = mod(atan2(x1*y2-x2*y1,x1*x2+y1*y2),2*pi);&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;As you can see, this bears a close relationship to the three-dimensional &lt;br&gt;
formula I wrote last July 10.  The quantities, x1*y2-x2*y1 and x1*x2+y1*y2 &lt;br&gt;
are, respectively, the sine and cosine of the counterclockwise angle from &lt;br&gt;
vector a to vector b, multiplied by the product of their norms - that is, their &lt;br&gt;
cross product and the dot product restricted to two dimensions.  The 'atan2' &lt;br&gt;
function then gives the angle between them ranging from -pi to +pi, and the &lt;br&gt;
'mod' operation changes this so as to range from 0 to 2*pi, as you requested.&lt;br&gt;
&lt;br&gt;
Roger Stafford&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
</description>
    </item>
    <item>
      <pubDate>Tue, 11 Dec 2007 15:29:00 -0500</pubDate>
      <title>Re: Angle between two vectors</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/151925#405718</link>
      <author>salih tuna</author>
      <description>Roger hi,&lt;br&gt;
thanks a lot for your help but i am afraid something is&lt;br&gt;
still missing. i tried the formulae on the same example of &lt;br&gt;
a = [1 1]and b = [0 -1] (both passing through origin).&lt;br&gt;
the answer i got is 315 instead of 225.&lt;br&gt;
sorry i am taking a lot of your time :)&lt;br&gt;
thanks&lt;br&gt;
salih&lt;br&gt;
&lt;br&gt;
"Roger Stafford" &amp;lt;ellieandrogerxyzzy@mindspring.com.invalid&amp;gt;&lt;br&gt;
wrote in message &amp;lt;fjm4u4$i8o$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; "salih tuna" &amp;lt;salihtuna@gmail.com&amp;gt; wrote in message&lt;br&gt;
&amp;lt;fjlrpl$gii&lt;br&gt;
&amp;gt; $1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; &amp;gt; Hi,&lt;br&gt;
&amp;gt; &amp;gt; thanks a lot for your reply. yes they are in 2d, sorry i&lt;br&gt;
&amp;gt; &amp;gt; forgot to mention.&lt;br&gt;
&amp;gt; &amp;gt; i tried to apply the formula but i am getting wrong result.&lt;br&gt;
&amp;gt; &amp;gt; for example i want to calculate the angle between a = [1 1]&lt;br&gt;
&amp;gt; &amp;gt; and b = [0 -1] which is 225 degrees. with this formulae i&lt;br&gt;
&amp;gt; &amp;gt; got 243.4. i couldn't see where i am doing the mistake.&lt;br&gt;
&amp;gt; &amp;gt; thanks a lot in advance&lt;br&gt;
&amp;gt; &amp;gt; salih&lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; "Roger Stafford" &amp;lt;ellieandrogerxyzzy@mindspring.com.invalid&amp;gt;&lt;br&gt;
&amp;gt; &amp;gt; wrote in message &amp;lt;fjk0tg$jli$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt;  angle = mod(atan2(y2-y1,x2-x1),2*pi); % Range: 0 to 2*pi&lt;br&gt;
&amp;gt; --------&lt;br&gt;
&amp;gt;   I certainly owe you an apology, Salih.  That formula I&lt;br&gt;
gave you is very, very &lt;br&gt;
&amp;gt; wrong.  I can't imagine what I was thinking about when I&lt;br&gt;
wrote it.  Chalk it up &lt;br&gt;
&amp;gt; to momentary insanity!  :-)  The correct computation&lt;br&gt;
should be as follows.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt;   Assuming a = [x1,y1] and b = [x2,y2] are two vectors&lt;br&gt;
with their bases at the &lt;br&gt;
&amp;gt; origin, the non-negative angle between them measured&lt;br&gt;
counterclockwise &lt;br&gt;
&amp;gt; from a to b is given by&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt;  angle = mod(atan2(x1*y2-x2*y1,x1*x2+y1*y2),2*pi);&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt;   As you can see, this bears a close relationship to the&lt;br&gt;
three-dimensional &lt;br&gt;
&amp;gt; formula I wrote last July 10.  The quantities, x1*y2-x2*y1&lt;br&gt;
and x1*x2+y1*y2 &lt;br&gt;
&amp;gt; are, respectively, the sine and cosine of the&lt;br&gt;
counterclockwise angle from &lt;br&gt;
&amp;gt; vector a to vector b, multiplied by the product of their&lt;br&gt;
norms - that is, their &lt;br&gt;
&amp;gt; cross product and the dot product restricted to two&lt;br&gt;
dimensions.  The 'atan2' &lt;br&gt;
&amp;gt; function then gives the angle between them ranging from&lt;br&gt;
-pi to +pi, and the &lt;br&gt;
&amp;gt; 'mod' operation changes this so as to range from 0 to&lt;br&gt;
2*pi, as you requested.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Roger Stafford&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; &lt;br&gt;
&lt;br&gt;
</description>
    </item>
    <item>
      <pubDate>Tue, 11 Dec 2007 19:32:07 -0500</pubDate>
      <title>Re: Angle between two vectors</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/151925#405770</link>
      <author>Roger Stafford</author>
      <description>"salih tuna" &amp;lt;salihtuna@gmail.com&amp;gt; wrote in message &amp;lt;fjmabs$9fh&lt;br&gt;
$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; Roger hi,&lt;br&gt;
&amp;gt; thanks a lot for your help but i am afraid something is&lt;br&gt;
&amp;gt; still missing. i tried the formulae on the same example of &lt;br&gt;
&amp;gt; a = [1 1]and b = [0 -1] (both passing through origin).&lt;br&gt;
&amp;gt; the answer i got is 315 instead of 225.&lt;br&gt;
&amp;gt; sorry i am taking a lot of your time :)&lt;br&gt;
&amp;gt; thanks&lt;br&gt;
&amp;gt; salih&lt;br&gt;
-----&lt;br&gt;
Hi Salih.  I get 225 degrees for that example with a = [1,1] and b = [0,-1],  &lt;br&gt;
which is correct.  Are you sure you didn't have x2 and y1 interchanged by &lt;br&gt;
mistake?  That would get you an erroneous answer of 315.  You should have x1 &lt;br&gt;
= 1, y1 = 1, x2 = 0, and y2 = -1.&lt;br&gt;
&lt;br&gt;
Roger Stafford&lt;br&gt;
</description>
    </item>
    <item>
      <pubDate>Fri, 28 Dec 2007 16:11:38 -0500</pubDate>
      <title>Re: Angle between two vectors</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/151925#407415</link>
      <author>baris kazar</author>
      <description>"Roger Stafford" &lt;br&gt;
&amp;lt;ellieandrogerxyzzy@mindspring.com.invalid&amp;gt; wrote in &lt;br&gt;
message &amp;lt;fjk0tg$jli$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; "salih tuna" &amp;lt;salihtuna@gmail.com&amp;gt; wrote in message &lt;br&gt;
&amp;lt;fjj9nj$fia&lt;br&gt;
&amp;gt; $1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; &amp;gt; hello,&lt;br&gt;
&amp;gt; &amp;gt; how can i calculate the angles so that they are in the &lt;br&gt;
range 0-360 degrees?&lt;br&gt;
&amp;gt; &amp;gt; thanks&lt;br&gt;
&amp;gt; &amp;gt; salih&lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; "y Mehta" &amp;lt;mehtayogesh@gmail.(DOT).com&amp;gt; wrote in &lt;br&gt;
message&lt;br&gt;
&amp;gt; &amp;gt; &amp;lt;ef5ce9c.-1@webcrossing.raydaftYaTP&amp;gt;...&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; How do I find the angle between two unit vectors a &lt;br&gt;
and b?  I know I&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; can find cosine theta by the following formula:&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; theta = acos(dot(a,b));&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; However, how do I know whether the angle is actually &lt;br&gt;
theta, or -theta&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; or pi-theta or pi+theta??&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; Notice that the vectors are in three dimension (3d).&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; Thanks,&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; -YM&lt;br&gt;
&amp;gt; --------&lt;br&gt;
&amp;gt;   Y Mehta's question involved angles between vectors in &lt;br&gt;
three-dimensional &lt;br&gt;
&amp;gt; space.  I can think of no reasonable definition for a &lt;br&gt;
canonical angle between &lt;br&gt;
&amp;gt; such vectors which ranges from 0 to 360 degrees (0 to &lt;br&gt;
2*pi radians.)&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt;   However, if you are in two-dimensional space, then you &lt;br&gt;
can speak of the &lt;br&gt;
&amp;gt; non-negative angle measured counterclockwise from vector &lt;br&gt;
a to vector b, &lt;br&gt;
&amp;gt; and this would give the range you have requested.  If a &lt;br&gt;
= [x1,y1] and b = &lt;br&gt;
&amp;gt; [x2,y2], then such an angle is given in matlab by:&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt;  angle = mod(atan2(y2-y1,x2-x1),2*pi); % Range: 0 to &lt;br&gt;
2*pi radians&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; (Multiply this answer by 180/pi to get degrees.)&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Roger Stafford&lt;br&gt;
&lt;br&gt;
Hi,-&lt;br&gt;
&amp;nbsp;how can we generalize this to 3-D vectors? Think of a &lt;br&gt;
plane on 3-D space and you have vectors on this plane. I &lt;br&gt;
wanna know the angle between 2 vectors in the range 0-2pi.&lt;br&gt;
or at least -pi to pi. I have 3 vectors. One (First) &lt;br&gt;
vector is the same all the time. I wanna know the relative &lt;br&gt;
positions of the other two vector wrt the firsy one. Thus, &lt;br&gt;
i need angles in the range 0 to 2pi or -pi to pi.&lt;br&gt;
Thanks in advance&lt;br&gt;
</description>
    </item>
    <item>
      <pubDate>Fri, 28 Dec 2007 18:22:57 -0500</pubDate>
      <title>Re: Angle between two vectors</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/151925#407432</link>
      <author>Bruno Luong</author>
      <description>"baris kazar" &amp;lt;mbkazar.nospam@gmail.com&amp;gt; wrote in message&lt;br&gt;
&amp;lt;fl377q$4ip$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Hi,-&lt;br&gt;
&amp;gt;  how can we generalize this to 3-D vectors? Think of a &lt;br&gt;
&amp;gt; plane on 3-D space and you have vectors on this plane. I &lt;br&gt;
&amp;gt; wanna know the angle between 2 vectors in the range 0-2pi.&lt;br&gt;
&lt;br&gt;
The problem is depends on where you look (from above or from&lt;br&gt;
below the plane), you will see the angle between vectors on&lt;br&gt;
this plane reverse the sign (draw them on a transparent&lt;br&gt;
glass and try to look from both sides). In 3D there is&lt;br&gt;
nothing that could tell us whereas looking from one way or&lt;br&gt;
from another is more "correct".&lt;br&gt;
&lt;br&gt;
Think like a fish or a bird, not like a man.&lt;br&gt;
&lt;br&gt;
Bruno&lt;br&gt;
&lt;br&gt;
</description>
    </item>
  </channel>
</rss>
