Thread Subject: Find angles between two vectors

Subject: Find angles between two vectors

From: Justin Morehouse

Date: 23 Jan, 2008 13:13:01

Message: 1 of 11

Hi there, I have a two vectors (3,5) and (5,6) and I was
wondering how do I get the angle between them in matlab.

on paper I would multiply both vectors to get (15+30) to =
45 and then square both (3,5) and (5,6) to get (9+25) and
(25+36). Then I would get the square root of both (34) and
(61) and multiply them together and then divide 45 by that.

Afterwhich I would then use a trusty calc to do cos theta
of that, but how can math lab do that?

Thanks!

Subject: Find angles between two vectors

From: tpl@eng.cam.ac.uk (Tim Love)

Date: 23 Jan, 2008 13:34:44

Message: 2 of 11

"Justin Morehouse" <norman_batez@MSN.com> writes:

>Hi there, I have a two vectors (3,5) and (5,6) and I was
>wondering how do I get the angle between them in matlab.

There's a cart2pol function. Or you could use
angle(complex(5,6)-complex(3,5))

Subject: Find angles between two vectors

From: us

Date: 23 Jan, 2008 13:53:02

Message: 3 of 11

"Justin Morehouse":
<SNIP many many words...

> Hi there, I have a two vectors (3,5) and (5,6) and I was
> wondering how do I get the angle between them in matlab.
> on paper I would multiply both vectors to get (15+30) to
=
> 45 and then square both (3,5) and (5,6) to get (9+25) and
> (25+36). Then I would get the square root of both (34)
and
> (61) and multiply them together and then divide 45 by
that.
> Afterwhich I would then use a trusty calc to do cos
theta
> of that, but how can math lab do that...

ML obeys your words... (as one of the solutions...)

     v1=[3,5];
     v2=[5,6];
     a=acosd(dot(v1,v2)/(norm(v1)*norm(v2)))

us

Subject: Find angles between two vectors

From: Anh Huy Phan

Date: 23 Jan, 2008 14:08:02

Message: 4 of 11

"us " <us@neurol.unizh.ch> wrote in message
<fn7gru$7jd$1@fred.mathworks.com>...
> "Justin Morehouse":
> <SNIP many many words...
>
> > Hi there, I have a two vectors (3,5) and (5,6) and I
was
> > wondering how do I get the angle between them in matlab.
> > on paper I would multiply both vectors to get (15+30) to
> =
> > 45 and then square both (3,5) and (5,6) to get (9+25)
and
> > (25+36). Then I would get the square root of both (34)
> and
> > (61) and multiply them together and then divide 45 by
> that.
> > Afterwhich I would then use a trusty calc to do cos
> theta
> > of that, but how can math lab do that...
>
> ML obeys your words... (as one of the solutions...)
>
> v1=[3,5];
> v2=[5,6];
> a=acosd(dot(v1,v2)/(norm(v1)*norm(v2)))
>
> us

The same question was posted and available at the following
address

http://www.mathworks.com/matlabcentral/newsreader/
view_thread/151925

It is better that you search your topic before posting a
question about it.

Anh Huy Phan
RIKEN - BSI

Subject: Find angles between two vectors

From: Roger Stafford

Date: 23 Jan, 2008 21:16:03

Message: 5 of 11

"Justin Morehouse" <norman_batez@MSN.com> wrote in message <fn7egt
$447$1@fred.mathworks.com>...
> Hi there, I have a two vectors (3,5) and (5,6) and I was
> wondering how do I get the angle between them in matlab.
>
> on paper I would multiply both vectors to get (15+30) to =
> 45 and then square both (3,5) and (5,6) to get (9+25) and
> (25+36). Then I would get the square root of both (34) and
> (61) and multiply them together and then divide 45 by that.
>
> Afterwhich I would then use a trusty calc to do cos theta
> of that, but how can math lab do that?
>
> Thanks!
------------
  Another possible solution:

 x1 = 3; y1 = 5;
 x2 = 5; y2 = 6;
 ang = atan2(abs(x1*y2-y1*x2),x1*x2+y1*y2);

where ang is measured in radians. (Multiply by 180/pi to get degrees.)

  This method has a slight advantage over the arccosine method. The acos
function suffers an inherent loss of accuracy near angles 0 and pi, whereas
the atan2 function maintains full accuracy for such cases. (Make a plot of the
acos curve from -1 to +1 to see why.)

  It is important to distinguish between two possible definitions of an angle
between vectors in the x-y plane. Above, the angle is considered as a non-
negative quantity lying between 0 and pi. It can also be defined as the angle
measured counterclockwise from the first vector to the second one, which in
general would be an angle ranging from 0 to 2*pi, or else from -pi to +pi
with clockwise being considered negative. For this latter meaning one would
remove the 'abs' in the above expression.

Roger Stafford

Subject: Find angles between two vectors

From: Justin Morehouse

Date: 23 Jan, 2008 23:25:04

Message: 6 of 11

"Justin Morehouse" <norman_batez@MSN.com> wrote in message
<fn7egt$447$1@fred.mathworks.com>...

Wow, matlab is pretty neat, thanks for your help guys!

Subject: Find angles between two vectors

From: raymond

Date: 6 May, 2009 05:38:01

Message: 7 of 11

what I did is the following:

% I used "atand" b/c I want it in DEG, but you can remove the "d" to have RAD.
theta = atand((y(2)-y(1))/(x(2)-x(1)));

%This gives me correct values for x(2)>x(1), but for x(2)<x(1), I included the
% following "if" statement:
angle = theta+(x(2)<x(1))*180

This gave me what I wanted, which is the angle between between two vectors.

Subject: Find angles between two vectors

From: James

Date: 14 May, 2009 12:35:02

Message: 8 of 11

copy this text to your matlab, the two lines c and d are my vectors,

clear all;
a%0*cos(20*(180/pi));
b%0*sin(20*(180/pi));
pax=[0 a];
pay=[0 0];
paz=[0 b];
c=line(pax,pay,paz);
sx=[a -30];
sy=[0 80];
sz=[b 135];
d=line(sx,sy,sz);

how do i find the angle between the lines c and d, my vectors are 3D so i'm unsure what to do

Subject: Find angles between two vectors

From: Lina

Date: 19 Feb, 2010 15:05:21

Message: 9 of 11

Hello,

Could you help me with this?

I want to calculate the angle between 2 vectors but when their origin is not the (0,0).

for instance in the x-y plane:

Vector V1 has start point P1(x1,y1) and end point P2(x2,y2)
Vector V2 has start point P2(x2,y2) and end point P3(x3,y3)

What is the angle between V1 and V2?

thank you!
Lina

"Roger Stafford" <ellieandrogerxyzzy@mindspring.com.invalid> wrote in message <fn8aqj$88o$1@fred.mathworks.com>...
> "Justin Morehouse" <norman_batez@MSN.com> wrote in message <fn7egt
> $447$1@fred.mathworks.com>...
> > Hi there, I have a two vectors (3,5) and (5,6) and I was
> > wondering how do I get the angle between them in matlab.
> >
> > on paper I would multiply both vectors to get (15+30) to =
> > 45 and then square both (3,5) and (5,6) to get (9+25) and
> > (25+36). Then I would get the square root of both (34) and
> > (61) and multiply them together and then divide 45 by that.
> >
> > Afterwhich I would then use a trusty calc to do cos theta
> > of that, but how can math lab do that?
> >
> > Thanks!
> ------------
> Another possible solution:
>
> x1 = 3; y1 = 5;
> x2 = 5; y2 = 6;
> ang = atan2(abs(x1*y2-y1*x2),x1*x2+y1*y2);
>
> where ang is measured in radians. (Multiply by 180/pi to get degrees.)
>
> This method has a slight advantage over the arccosine method. The acos
> function suffers an inherent loss of accuracy near angles 0 and pi, whereas
> the atan2 function maintains full accuracy for such cases. (Make a plot of the
> acos curve from -1 to +1 to see why.)
>
> It is important to distinguish between two possible definitions of an angle
> between vectors in the x-y plane. Above, the angle is considered as a non-
> negative quantity lying between 0 and pi. It can also be defined as the angle
> measured counterclockwise from the first vector to the second one, which in
> general would be an angle ranging from 0 to 2*pi, or else from -pi to +pi
> with clockwise being considered negative. For this latter meaning one would
> remove the 'abs' in the above expression.
>
> Roger Stafford
>

Subject: Find angles between two vectors

From: Rune Allnor

Date: 19 Feb, 2010 15:31:24

Message: 10 of 11

On 19 Feb, 16:05, "Lina " <linaaposto...@hotmail.com> wrote:
> Hello,
>
> Could you help me with this?
>
> I want to calculate the angle between 2 vectors but when their origin is not the (0,0).
>
> for instance in the x-y plane:
>
> Vector V1 has start point P1(x1,y1) and end point P2(x2,y2)
> Vector V2 has start point P2(x2,y2) and end point P3(x3,y3)
>
> What is the angle between V1 and V2?

This is not the place to ask for help with homework.
At least not without first having made an honest
attempt yourself.

Rune

Subject: Find angles between two vectors

From: James Allison

Date: 19 Feb, 2010 15:59:04

Message: 11 of 11

Perform an affine transformation first.

Lina wrote:
> Hello,
> Could you help me with this?
>
> I want to calculate the angle between 2 vectors but when their origin is
> not the (0,0).
>
> for instance in the x-y plane:
>
> Vector V1 has start point P1(x1,y1) and end point P2(x2,y2) Vector V2
> has start point P2(x2,y2) and end point P3(x3,y3)
> What is the angle between V1 and V2?
>
> thank you!
> Lina
>
> "Roger Stafford" <ellieandrogerxyzzy@mindspring.com.invalid> wrote in
> message <fn8aqj$88o$1@fred.mathworks.com>...
>> "Justin Morehouse" <norman_batez@MSN.com> wrote in message <fn7egt
>> $447$1@fred.mathworks.com>...
>> > Hi there, I have a two vectors (3,5) and (5,6) and I was > wondering
>> how do I get the angle between them in matlab.
>> > > on paper I would multiply both vectors to get (15+30) to = > 45
>> and then square both (3,5) and (5,6) to get (9+25) and > (25+36). Then
>> I would get the square root of both (34) and > (61) and multiply them
>> together and then divide 45 by that.
>> > > Afterwhich I would then use a trusty calc to do cos theta > of
>> that, but how can math lab do that?
>> > > Thanks!
>> ------------
>> Another possible solution:
>>
>> x1 = 3; y1 = 5;
>> x2 = 5; y2 = 6;
>> ang = atan2(abs(x1*y2-y1*x2),x1*x2+y1*y2);
>>
>> where ang is measured in radians. (Multiply by 180/pi to get degrees.)
>>
>> This method has a slight advantage over the arccosine method. The
>> acos function suffers an inherent loss of accuracy near angles 0 and
>> pi, whereas the atan2 function maintains full accuracy for such
>> cases. (Make a plot of the acos curve from -1 to +1 to see why.)
>>
>> It is important to distinguish between two possible definitions of
>> an angle between vectors in the x-y plane. Above, the angle is
>> considered as a non-
>> negative quantity lying between 0 and pi. It can also be defined as
>> the angle measured counterclockwise from the first vector to the
>> second one, which in general would be an angle ranging from 0 to 2*pi,
>> or else from -pi to +pi with clockwise being considered negative. For
>> this latter meaning one would remove the 'abs' in the above expression.
>>
>> Roger Stafford
>>

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Tag Activity for This Thread
Tag Applied By Date/Time
vectors Lina 19 Feb, 2010 10:09:08
angle Lina 19 Feb, 2010 10:09:07
vectors James 14 May, 2009 08:39:03
lines James 14 May, 2009 08:39:03
angle James 14 May, 2009 08:39:03
between James 14 May, 2009 08:39:03
3d James 14 May, 2009 08:39:03
two James 14 May, 2009 08:39:03
atan2 Roger Stafford 23 Jan, 2008 16:27:39
norm us 23 Jan, 2008 08:55:09
dot us 23 Jan, 2008 08:55:08
code us 23 Jan, 2008 08:55:08
rssFeed for this Thread

Contact us at files@mathworks.com