<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/162503</link>
    <title>MATLAB Central Newsreader - Find angles between two vectors</title>
    <description>Feed for thread: Find angles between two vectors</description>
    <language>en-us</language>
    <copyright>&amp;copy;1994-2012 by 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>MathWorks</title>
      <url>http://www.mathworks.com/images/membrane_icon.gif</url>
    </image>
    <item>
      <pubDate>Wed, 23 Jan 2008 13:13:01 -0500</pubDate>
      <title>Find angles between two vectors</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/162503#410850</link>
      <author>Justin Morehouse</author>
      <description>Hi there, I have a two vectors (3,5) and (5,6) and I was &lt;br&gt;
wondering how do I get the angle between them in matlab.&lt;br&gt;
&lt;br&gt;
on paper I would multiply both vectors to get (15+30) to = &lt;br&gt;
45 and then square both (3,5) and (5,6) to get (9+25) and &lt;br&gt;
(25+36). Then I would get the square root of both (34) and &lt;br&gt;
(61) and multiply them together  and then divide 45 by that.&lt;br&gt;
&lt;br&gt;
Afterwhich  I would then use a trusty calc to do cos theta &lt;br&gt;
of that, but how can math lab do that?&lt;br&gt;
&lt;br&gt;
Thanks!</description>
    </item>
    <item>
      <pubDate>Wed, 23 Jan 2008 13:34:44 -0500</pubDate>
      <title>Re: Find angles between two vectors</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/162503#410854</link>
      <author>tpl@eng.cam.ac.uk (Tim Love)</author>
      <description>&quot;Justin Morehouse&quot; &amp;lt;norman_batez@MSN.com&amp;gt; writes:&lt;br&gt;
&lt;br&gt;
&amp;gt;Hi there, I have a two vectors (3,5) and (5,6) and I was &lt;br&gt;
&amp;gt;wondering how do I get the angle between them in matlab.&lt;br&gt;
&lt;br&gt;
There's a cart2pol function. Or you could use &lt;br&gt;
angle(complex(5,6)-complex(3,5))</description>
    </item>
    <item>
      <pubDate>Wed, 23 Jan 2008 13:53:02 -0500</pubDate>
      <title>Re: Find angles between two vectors</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/162503#410859</link>
      <author>us</author>
      <description>&quot;Justin Morehouse&quot;:&lt;br&gt;
&amp;lt;SNIP many many words...&lt;br&gt;
&lt;br&gt;
&amp;gt; Hi there, I have a two vectors (3,5) and (5,6) and I was &lt;br&gt;
&amp;gt; wondering how do I get the angle between them in matlab.&lt;br&gt;
&amp;gt; on paper I would multiply both vectors to get (15+30) to &lt;br&gt;
= &lt;br&gt;
&amp;gt; 45 and then square both (3,5) and (5,6) to get (9+25) and &lt;br&gt;
&amp;gt; (25+36). Then I would get the square root of both (34) &lt;br&gt;
and &lt;br&gt;
&amp;gt; (61) and multiply them together  and then divide 45 by &lt;br&gt;
that.&lt;br&gt;
&amp;gt; Afterwhich  I would then use a trusty calc to do cos &lt;br&gt;
theta &lt;br&gt;
&amp;gt; of that, but how can math lab do that...&lt;br&gt;
&lt;br&gt;
ML obeys your words... (as one of the solutions...)&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;v1=[3,5];&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;v2=[5,6];&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;a=acosd(dot(v1,v2)/(norm(v1)*norm(v2)))&lt;br&gt;
&lt;br&gt;
us</description>
    </item>
    <item>
      <pubDate>Wed, 23 Jan 2008 14:08:02 -0500</pubDate>
      <title>Re: Find angles between two vectors</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/162503#410866</link>
      <author>Anh Huy Phan</author>
      <description>&quot;us &quot; &amp;lt;us@neurol.unizh.ch&amp;gt; wrote in message &lt;br&gt;
&amp;lt;fn7gru$7jd$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; &quot;Justin Morehouse&quot;:&lt;br&gt;
&amp;gt; &amp;lt;SNIP many many words...&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; Hi there, I have a two vectors (3,5) and (5,6) and I &lt;br&gt;
was &lt;br&gt;
&amp;gt; &amp;gt; wondering how do I get the angle between them in matlab.&lt;br&gt;
&amp;gt; &amp;gt; on paper I would multiply both vectors to get (15+30) to &lt;br&gt;
&amp;gt; = &lt;br&gt;
&amp;gt; &amp;gt; 45 and then square both (3,5) and (5,6) to get (9+25) &lt;br&gt;
and &lt;br&gt;
&amp;gt; &amp;gt; (25+36). Then I would get the square root of both (34) &lt;br&gt;
&amp;gt; and &lt;br&gt;
&amp;gt; &amp;gt; (61) and multiply them together  and then divide 45 by &lt;br&gt;
&amp;gt; that.&lt;br&gt;
&amp;gt; &amp;gt; Afterwhich  I would then use a trusty calc to do cos &lt;br&gt;
&amp;gt; theta &lt;br&gt;
&amp;gt; &amp;gt; of that, but how can math lab do that...&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; ML obeys your words... (as one of the solutions...)&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt;      v1=[3,5];&lt;br&gt;
&amp;gt;      v2=[5,6];&lt;br&gt;
&amp;gt;      a=acosd(dot(v1,v2)/(norm(v1)*norm(v2)))&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; us&lt;br&gt;
&lt;br&gt;
The same question was posted and available at the following &lt;br&gt;
address&lt;br&gt;
&lt;br&gt;
&lt;a href=&quot;http://www.mathworks.com/matlabcentral/newsreader/&quot;&gt;http://www.mathworks.com/matlabcentral/newsreader/&lt;/a&gt;&lt;br&gt;
view_thread/151925&lt;br&gt;
&lt;br&gt;
It is better that you search your topic before posting a &lt;br&gt;
question about it.&lt;br&gt;
&lt;br&gt;
Anh Huy Phan&lt;br&gt;
RIKEN - BSI</description>
    </item>
    <item>
      <pubDate>Wed, 23 Jan 2008 21:16:03 -0500</pubDate>
      <title>Re: Find angles between two vectors</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/162503#410961</link>
      <author>Roger Stafford</author>
      <description>&quot;Justin Morehouse&quot; &amp;lt;norman_batez@MSN.com&amp;gt; wrote in message &amp;lt;fn7egt&lt;br&gt;
$447$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; Hi there, I have a two vectors (3,5) and (5,6) and I was &lt;br&gt;
&amp;gt; wondering how do I get the angle between them in matlab.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; on paper I would multiply both vectors to get (15+30) to = &lt;br&gt;
&amp;gt; 45 and then square both (3,5) and (5,6) to get (9+25) and &lt;br&gt;
&amp;gt; (25+36). Then I would get the square root of both (34) and &lt;br&gt;
&amp;gt; (61) and multiply them together  and then divide 45 by that.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Afterwhich  I would then use a trusty calc to do cos theta &lt;br&gt;
&amp;gt; of that, but how can math lab do that?&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Thanks!&lt;br&gt;
------------&lt;br&gt;
&amp;nbsp;&amp;nbsp;Another possible solution:&lt;br&gt;
&lt;br&gt;
&amp;nbsp;x1 = 3; y1 = 5;&lt;br&gt;
&amp;nbsp;x2 = 5; y2 = 6;&lt;br&gt;
&amp;nbsp;ang = atan2(abs(x1*y2-y1*x2),x1*x2+y1*y2);&lt;br&gt;
&lt;br&gt;
where ang is measured in radians.  (Multiply by 180/pi to get degrees.)&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;This method has a slight advantage over the arccosine method.  The acos &lt;br&gt;
function suffers an inherent loss of accuracy near angles 0 and pi, whereas &lt;br&gt;
the atan2 function maintains full accuracy for such cases.  (Make a plot of the &lt;br&gt;
acos curve from -1 to +1 to see why.)&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;It is important to distinguish between two possible definitions of an angle &lt;br&gt;
between vectors in the x-y plane.  Above, the angle is considered as a non-&lt;br&gt;
negative quantity lying between 0 and pi.  It can also be defined as the angle &lt;br&gt;
measured counterclockwise from the first vector to the second one, which in &lt;br&gt;
general would be an angle ranging from 0 to 2*pi, or else from -pi to +pi &lt;br&gt;
with clockwise being considered negative.  For this latter meaning one would &lt;br&gt;
remove the 'abs' in the above expression.&lt;br&gt;
&lt;br&gt;
Roger Stafford</description>
    </item>
    <item>
      <pubDate>Wed, 23 Jan 2008 23:25:04 -0500</pubDate>
      <title>Re: Find angles between two vectors</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/162503#410987</link>
      <author>Justin Morehouse</author>
      <description>&quot;Justin Morehouse&quot; &amp;lt;norman_batez@MSN.com&amp;gt; wrote in message &lt;br&gt;
&amp;lt;fn7egt$447$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&lt;br&gt;
Wow, matlab is pretty neat, thanks for your help guys!</description>
    </item>
    <item>
      <pubDate>Wed, 06 May 2009 05:38:01 -0400</pubDate>
      <title>Re: Find angles between two vectors</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/162503#647727</link>
      <author>raymond </author>
      <description>what I did is the following:&lt;br&gt;
&lt;br&gt;
% I used &quot;atand&quot; b/c I want it in DEG, but you can remove the &quot;d&quot; to have RAD.&lt;br&gt;
theta = atand((y(2)-y(1))/(x(2)-x(1)));&lt;br&gt;
&lt;br&gt;
%This gives me correct values for x(2)&amp;gt;x(1), but for x(2)&amp;lt;x(1), I included the &lt;br&gt;
% following &quot;if&quot; statement:&lt;br&gt;
angle = theta+(x(2)&amp;lt;x(1))*180&lt;br&gt;
&lt;br&gt;
This gave me what I wanted, which is the angle between between two vectors.</description>
    </item>
    <item>
      <pubDate>Thu, 14 May 2009 12:35:02 -0400</pubDate>
      <title>Re: Find angles between two vectors</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/162503#649813</link>
      <author>James </author>
      <description>copy this text to your matlab, the two lines c and d are my vectors,&lt;br&gt;
&lt;br&gt;
clear all;&lt;br&gt;
a%0*cos(20*(180/pi));&lt;br&gt;
b%0*sin(20*(180/pi));&lt;br&gt;
pax=[0 a];&lt;br&gt;
pay=[0 0];&lt;br&gt;
paz=[0 b];&lt;br&gt;
c=line(pax,pay,paz);&lt;br&gt;
sx=[a -30];&lt;br&gt;
sy=[0 80];&lt;br&gt;
sz=[b 135];&lt;br&gt;
d=line(sx,sy,sz);&lt;br&gt;
&lt;br&gt;
how do i find the angle between the lines c and d, my vectors are 3D so i'm unsure what to do</description>
    </item>
    <item>
      <pubDate>Fri, 19 Feb 2010 15:05:21 -0500</pubDate>
      <title>Re: Find angles between two vectors</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/162503#719305</link>
      <author>Lina </author>
      <description>Hello, &lt;br&gt;
&lt;br&gt;
Could you help me with this?&lt;br&gt;
&lt;br&gt;
I want to calculate the angle between 2 vectors but when their origin is not the (0,0).&lt;br&gt;
&lt;br&gt;
for instance in the x-y plane:&lt;br&gt;
&lt;br&gt;
Vector V1 has start point P1(x1,y1) and end point P2(x2,y2) &lt;br&gt;
Vector V2 has start point P2(x2,y2) and end point P3(x3,y3) &lt;br&gt;
&lt;br&gt;
What is the angle between V1 and V2?&lt;br&gt;
&lt;br&gt;
thank you!&lt;br&gt;
Lina&lt;br&gt;
&lt;br&gt;
&quot;Roger Stafford&quot; &amp;lt;ellieandrogerxyzzy@mindspring.com.invalid&amp;gt; wrote in message &amp;lt;fn8aqj$88o$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; &quot;Justin Morehouse&quot; &amp;lt;norman_batez@MSN.com&amp;gt; wrote in message &amp;lt;fn7egt&lt;br&gt;
&amp;gt; $447$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; &amp;gt; Hi there, I have a two vectors (3,5) and (5,6) and I was &lt;br&gt;
&amp;gt; &amp;gt; wondering how do I get the angle between them in matlab.&lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; on paper I would multiply both vectors to get (15+30) to = &lt;br&gt;
&amp;gt; &amp;gt; 45 and then square both (3,5) and (5,6) to get (9+25) and &lt;br&gt;
&amp;gt; &amp;gt; (25+36). Then I would get the square root of both (34) and &lt;br&gt;
&amp;gt; &amp;gt; (61) and multiply them together  and then divide 45 by that.&lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; Afterwhich  I would then use a trusty calc to do cos theta &lt;br&gt;
&amp;gt; &amp;gt; of that, but how can math lab do that?&lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; Thanks!&lt;br&gt;
&amp;gt; ------------&lt;br&gt;
&amp;gt;   Another possible solution:&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt;  x1 = 3; y1 = 5;&lt;br&gt;
&amp;gt;  x2 = 5; y2 = 6;&lt;br&gt;
&amp;gt;  ang = atan2(abs(x1*y2-y1*x2),x1*x2+y1*y2);&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; where ang is measured in radians.  (Multiply by 180/pi to get degrees.)&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt;   This method has a slight advantage over the arccosine method.  The acos &lt;br&gt;
&amp;gt; function suffers an inherent loss of accuracy near angles 0 and pi, whereas &lt;br&gt;
&amp;gt; the atan2 function maintains full accuracy for such cases.  (Make a plot of the &lt;br&gt;
&amp;gt; acos curve from -1 to +1 to see why.)&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt;   It is important to distinguish between two possible definitions of an angle &lt;br&gt;
&amp;gt; between vectors in the x-y plane.  Above, the angle is considered as a non-&lt;br&gt;
&amp;gt; negative quantity lying between 0 and pi.  It can also be defined as the angle &lt;br&gt;
&amp;gt; measured counterclockwise from the first vector to the second one, which in &lt;br&gt;
&amp;gt; general would be an angle ranging from 0 to 2*pi, or else from -pi to +pi &lt;br&gt;
&amp;gt; with clockwise being considered negative.  For this latter meaning one would &lt;br&gt;
&amp;gt; remove the 'abs' in the above expression.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Roger Stafford&lt;br&gt;
&amp;gt; </description>
    </item>
    <item>
      <pubDate>Fri, 19 Feb 2010 15:31:24 -0500</pubDate>
      <title>Re: Find angles between two vectors</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/162503#719315</link>
      <author>Rune Allnor</author>
      <description>On 19 Feb, 16:05, &quot;Lina &quot; &amp;lt;linaaposto...@hotmail.com&amp;gt; wrote:&lt;br&gt;
&amp;gt; Hello,&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; Could you help me with this?&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; I want to calculate the angle between 2 vectors but when their origin is not the (0,0).&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; for instance in the x-y plane:&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; Vector V1 has start point P1(x1,y1) and end point P2(x2,y2)&lt;br&gt;
&amp;gt; Vector V2 has start point P2(x2,y2) and end point P3(x3,y3)&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; What is the angle between V1 and V2?&lt;br&gt;
&lt;br&gt;
This is not the place to ask for help with homework.&lt;br&gt;
At least not without first having made an honest&lt;br&gt;
attempt yourself.&lt;br&gt;
&lt;br&gt;
Rune</description>
    </item>
    <item>
      <pubDate>Fri, 19 Feb 2010 15:59:04 -0500</pubDate>
      <title>Re: Find angles between two vectors</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/162503#719329</link>
      <author>James Allison</author>
      <description>Perform an affine transformation first.&lt;br&gt;
&lt;br&gt;
Lina wrote:&lt;br&gt;
&amp;gt; Hello,&lt;br&gt;
&amp;gt; Could you help me with this?&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; I want to calculate the angle between 2 vectors but when their origin is &lt;br&gt;
&amp;gt; not the (0,0).&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; for instance in the x-y plane:&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Vector V1 has start point P1(x1,y1) and end point P2(x2,y2) Vector V2 &lt;br&gt;
&amp;gt; has start point P2(x2,y2) and end point P3(x3,y3)&lt;br&gt;
&amp;gt; What is the angle between V1 and V2?&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; thank you!&lt;br&gt;
&amp;gt; Lina&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; &quot;Roger Stafford&quot; &amp;lt;ellieandrogerxyzzy@mindspring.com.invalid&amp;gt; wrote in &lt;br&gt;
&amp;gt; message &amp;lt;fn8aqj$88o$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt;&amp;gt; &quot;Justin Morehouse&quot; &amp;lt;norman_batez@MSN.com&amp;gt; wrote in message &amp;lt;fn7egt&lt;br&gt;
&amp;gt;&amp;gt; $447$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt;&amp;gt; &amp;gt; Hi there, I have a two vectors (3,5) and (5,6) and I was &amp;gt; wondering &lt;br&gt;
&amp;gt;&amp;gt; how do I get the angle between them in matlab.&lt;br&gt;
&amp;gt;&amp;gt; &amp;gt; &amp;gt; on paper I would multiply both vectors to get (15+30) to = &amp;gt; 45 &lt;br&gt;
&amp;gt;&amp;gt; and then square both (3,5) and (5,6) to get (9+25) and &amp;gt; (25+36). Then &lt;br&gt;
&amp;gt;&amp;gt; I would get the square root of both (34) and &amp;gt; (61) and multiply them &lt;br&gt;
&amp;gt;&amp;gt; together  and then divide 45 by that.&lt;br&gt;
&amp;gt;&amp;gt; &amp;gt; &amp;gt; Afterwhich  I would then use a trusty calc to do cos theta &amp;gt; of &lt;br&gt;
&amp;gt;&amp;gt; that, but how can math lab do that?&lt;br&gt;
&amp;gt;&amp;gt; &amp;gt; &amp;gt; Thanks!&lt;br&gt;
&amp;gt;&amp;gt; ------------&lt;br&gt;
&amp;gt;&amp;gt;   Another possible solution:&lt;br&gt;
&amp;gt;&amp;gt;&lt;br&gt;
&amp;gt;&amp;gt;  x1 = 3; y1 = 5;&lt;br&gt;
&amp;gt;&amp;gt;  x2 = 5; y2 = 6;&lt;br&gt;
&amp;gt;&amp;gt;  ang = atan2(abs(x1*y2-y1*x2),x1*x2+y1*y2);&lt;br&gt;
&amp;gt;&amp;gt;&lt;br&gt;
&amp;gt;&amp;gt; where ang is measured in radians.  (Multiply by 180/pi to get degrees.)&lt;br&gt;
&amp;gt;&amp;gt;&lt;br&gt;
&amp;gt;&amp;gt;   This method has a slight advantage over the arccosine method.  The &lt;br&gt;
&amp;gt;&amp;gt; acos function suffers an inherent loss of accuracy near angles 0 and &lt;br&gt;
&amp;gt;&amp;gt; pi, whereas the atan2 function maintains full accuracy for such &lt;br&gt;
&amp;gt;&amp;gt; cases.  (Make a plot of the acos curve from -1 to +1 to see why.)&lt;br&gt;
&amp;gt;&amp;gt;&lt;br&gt;
&amp;gt;&amp;gt;   It is important to distinguish between two possible definitions of &lt;br&gt;
&amp;gt;&amp;gt; an angle between vectors in the x-y plane.  Above, the angle is &lt;br&gt;
&amp;gt;&amp;gt; considered as a non-&lt;br&gt;
&amp;gt;&amp;gt; negative quantity lying between 0 and pi.  It can also be defined as &lt;br&gt;
&amp;gt;&amp;gt; the angle measured counterclockwise from the first vector to the &lt;br&gt;
&amp;gt;&amp;gt; second one, which in general would be an angle ranging from 0 to 2*pi, &lt;br&gt;
&amp;gt;&amp;gt; or else from -pi to +pi with clockwise being considered negative.  For &lt;br&gt;
&amp;gt;&amp;gt; this latter meaning one would remove the 'abs' in the above expression.&lt;br&gt;
&amp;gt;&amp;gt;&lt;br&gt;
&amp;gt;&amp;gt; Roger Stafford&lt;br&gt;
&amp;gt;&amp;gt;</description>
    </item>
  </channel>
</rss>

