http://www.mathworks.com/matlabcentral/newsreader/view_thread/315841
MATLAB Central Newsreader  Angle between line and axis
Feed for thread: Angle between line and axis
enus
©19942015 by MathWorks, Inc.
webmaster@mathworks.com
MATLAB Central Newsreader
http://blogs.law.harvard.edu/tech/rss
60
MathWorks
http://www.mathworks.com/images/membrane_icon.gif

Tue, 10 Jan 2012 13:43:08 +0000
Angle between line and axis
http://www.mathworks.com/matlabcentral/newsreader/view_thread/315841#863353
Suzana
Hello!<br>
<br>
How I can calculate angle between line and x axis in Matlab.<br>
For instance, I have point P1 with coordinate x1 = 20; y1=35 and point P2 with coordinates x2=68 and y2= 25.<br>
<br>
I can draw line between these points and calculate it length, etc. But I don't know how I can calculate angle between THIS line and x  axis.....<br>
<br>
Thaks in advance....

Tue, 10 Jan 2012 14:45:27 +0000
Re: Angle between line and axis
http://www.mathworks.com/matlabcentral/newsreader/view_thread/315841#863364
eige
On Jan 10, 8:43 am, "Suzana " <suzana.petro...@mfkg.rs> wrote:<br>
> Hello!<br>
><br>
> How I can calculate angle between line and x axis in Matlab.<br>
> For instance, I have point P1 with coordinate x1 = 20; y1=35 and point P2 with coordinates x2=68 and y2= 25.<br>
><br>
> I can draw line between these points and calculate it length, etc. But I don't know how I can calculate angle between THIS line and x  axis.....<br>
><br>
> Thaks in advance....<br>
<br>
um, atan?

Tue, 10 Jan 2012 15:04:08 +0000
Re: Angle between line and axis
http://www.mathworks.com/matlabcentral/newsreader/view_thread/315841#863369
Suzana
eige <jeicke@gmail.com> wrote in message <d9d5fbf12532494391143b12d20e06bb@i6g2000vbk.googlegroups.com>...<br>
> On Jan 10, 8:43 am, "Suzana " <suzana.petro...@mfkg.rs> wrote:<br>
> > Hello!<br>
> ><br>
> > How I can calculate angle between line and x axis in Matlab.<br>
> > For instance, I have point P1 with coordinate x1 = 20; y1=35 and point P2 with coordinates x2=68 and y2= 25.<br>
> ><br>
> > I can draw line between these points and calculate it length, etc. But I don't know how I can calculate angle between THIS line and x  axis.....<br>
> ><br>
> > Thaks in advance....<br>
> <br>
> um, atan?<br>
<br>
If that function will help me to find an angle between line and xaxis and if you know how to implement that function, then I meant on that function...

Tue, 10 Jan 2012 15:37:07 +0000
Re: Angle between line and axis
http://www.mathworks.com/matlabcentral/newsreader/view_thread/315841#863375
Suzana
I hope so that I find the right angle. I try to use this<br>
<br>
angle=atan2(z2z1,y2y1)*180/pi;<br>
<br>
Am I on the right way with this?<br>
<br>
<br>
"Suzana" wrote in message <jehk18$2mu$1@newscl01ah.mathworks.com>...<br>
> eige <jeicke@gmail.com> wrote in message <d9d5fbf12532494391143b12d20e06bb@i6g2000vbk.googlegroups.com>...<br>
> > On Jan 10, 8:43 am, "Suzana " <suzana.petro...@mfkg.rs> wrote:<br>
> > > Hello!<br>
> > ><br>
> > > How I can calculate angle between line and x axis in Matlab.<br>
> > > For instance, I have point P1 with coordinate x1 = 20; y1=35 and point P2 with coordinates x2=68 and y2= 25.<br>
> > ><br>
> > > I can draw line between these points and calculate it length, etc. But I don't know how I can calculate angle between THIS line and x  axis.....<br>
> > ><br>
> > > Thaks in advance....<br>
> > <br>
> > um, atan?<br>
> <br>
> If that function will help me to find an angle between line and xaxis and if you know how to implement that function, then I meant on that function...

Tue, 10 Jan 2012 16:05:04 +0000
Re: Angle between line and axis
http://www.mathworks.com/matlabcentral/newsreader/view_thread/315841#863377
Rune Allnor
On 10 Jan, 16:37, "Suzana " <suzana.petro...@mfkg.rs> wrote:<br>
> I hope so that I find the right angle. I try to use this<br>
><br>
> angle=atan2(z2z1,y2y1)*180/pi;<br>
><br>
> Am I on the right way with this?<br>
<br>
No. You shouldn't believe everything you<br>
read on the internet. You might want to<br>
consult the odd textbook as well.<br>
<br>
For two vecors u and v, the angle theta<br>
between them is given by the inner product,<br>
<br>
<u,v> = u*v*cos(theta).<br>
<br>
Solve this expression for cos(theta), and<br>
plug in the vectors that describe the line<br>
and the axis, respectivley.<br>
<br>
Rune

Tue, 10 Jan 2012 16:43:07 +0000
Re: Angle between line and axis
http://www.mathworks.com/matlabcentral/newsreader/view_thread/315841#863381
Bruno Luong
Rune Allnor <allnor@tele.ntnu.no> wrote in message <09d3b07957024fe9803671369a6af095@dp8g2000vbb.googlegroups.com>...<br>
> On 10 Jan, 16:37, "Suzana " <suzana.petro...@mfkg.rs> wrote:<br>
> > I hope so that I find the right angle. I try to use this<br>
> ><br>
> > angle=atan2(z2z1,y2y1)*180/pi;<br>
> ><br>
> > Am I on the right way with this?<br>
> <br>
> No. You shouldn't believe everything you<br>
> read on the internet. You might want to<br>
> consult the odd textbook as well.<br>
<br>
Wait a minute. <br>
<br>
angle_in_radian=atan2(y2y1,x2x1);<br>
angle_in_deg=atan2(y2y1,x2x1)*180/pi;<br>
<br>
are absolutely correct ways to compute angle between xaxis and P1P2, where P1=(x1,y1) and P1=(x2,y2). It is more accurate than acos(.) (see Roger's many posts on the topic).<br>
<br>
Bruno

Tue, 10 Jan 2012 16:49:08 +0000
Re: Angle between line and axis
http://www.mathworks.com/matlabcentral/newsreader/view_thread/315841#863383
Suzana
Bruno, thank you very much. This is really helps me.<br>
<br>
<br>
"Bruno Luong" <b.luong@fogale.findmycountry> wrote in message <jehpqr$nmb$1@newscl01ah.mathworks.com>...<br>
> Rune Allnor <allnor@tele.ntnu.no> wrote in message <09d3b07957024fe9803671369a6af095@dp8g2000vbb.googlegroups.com>...<br>
> > On 10 Jan, 16:37, "Suzana " <suzana.petro...@mfkg.rs> wrote:<br>
> > > I hope so that I find the right angle. I try to use this<br>
> > ><br>
> > > angle=atan2(z2z1,y2y1)*180/pi;<br>
> > ><br>
> > > Am I on the right way with this?<br>
> > <br>
> > No. You shouldn't believe everything you<br>
> > read on the internet. You might want to<br>
> > consult the odd textbook as well.<br>
> <br>
> Wait a minute. <br>
> <br>
> angle_in_radian=atan2(y2y1,x2x1);<br>
> angle_in_deg=atan2(y2y1,x2x1)*180/pi;<br>
> <br>
> are absolutely correct ways to compute angle between xaxis and P1P2, where P1=(x1,y1) and P1=(x2,y2). It is more accurate than acos(.) (see Roger's many posts on the topic).<br>
> <br>
> Bruno

Tue, 10 Jan 2012 17:09:29 +0000
Re: Angle between line and axis
http://www.mathworks.com/matlabcentral/newsreader/view_thread/315841#863385
Rune Allnor
On 10 Jan, 17:43, "Bruno Luong" <b.lu...@fogale.findmycountry> wrote:<br>
> Rune Allnor <all...@tele.ntnu.no> wrote in message <09d3b07957024fe9803671369a6af...@dp8g2000vbb.googlegroups.com>...<br>
> > On 10 Jan, 16:37, "Suzana " <suzana.petro...@mfkg.rs> wrote:<br>
> > > I hope so that I find the right angle. I try to use this<br>
><br>
> > > angle=atan2(z2z1,y2y1)*180/pi;<br>
><br>
> > > Am I on the right way with this?<br>
><br>
> > No. You shouldn't believe everything you<br>
> > read on the internet. You might want to<br>
> > consult the odd textbook as well.<br>
><br>
> Wait a minute.<br>
><br>
> angle_in_radian=atan2(y2y1,x2x1);<br>
> angle_in_deg=atan2(y2y1,x2x1)*180/pi;<br>
><br>
> are absolutely correct ways to compute angle between xaxis and P1P2, where P1=(x1,y1) and P1=(x2,y2). It is more accurate than acos(.)<br>
<br>
Two comments:<br>
<br>
1) The inner product is the general method, while<br>
your suggestion only works with respct to one of<br>
the axes.<br>
<br>
2) Somebody who needs to ask the question at all<br>
is not concerned with numerical accuracies.<br>
<br>
Rune

Tue, 10 Jan 2012 17:30:09 +0000
Re: Angle between line and axis
http://www.mathworks.com/matlabcentral/newsreader/view_thread/315841#863388
Bruno Luong
Rune Allnor <allnor@tele.ntnu.no> wrote in message <859cce56847e4b0092aee68004ae82bf@z1g2000vbx.googlegroups.com>...<br>
<br>
> <br>
> Two comments:<br>
> <br>
> 1) The inner product is the general method, while<br>
> your suggestion only works with respct to one of<br>
> the axes.<br>
<br>
Wong again, the atan2() method can extend to angle between two arbitrary vectors (in R2 and R3, which is the case). I leave for you to find the formula as exercise Rune.<br>
<br>
> <br>
> 2) Somebody who needs to ask the question at all<br>
> is not concerned with numerical accuracies.<br>
> <br>
<br>
This is a bonus (beside it is a *correct* method, contrary to what you did claim)<br>
<br>
Bruno

Tue, 10 Jan 2012 18:26:07 +0000
Re: Angle between line and axis
http://www.mathworks.com/matlabcentral/newsreader/view_thread/315841#863393
Roger Stafford
Rune Allnor <allnor@tele.ntnu.no> wrote in message <859cce56847e4b0092aee68004ae82bf@z1g2000vbx.googlegroups.com>...<br>
> Two comments:<br>
> <br>
> 1) The inner product is the general method, while<br>
> your suggestion only works with respct to one of<br>
> the axes.<br>
> <br>
> 2) Somebody who needs to ask the question at all<br>
> is not concerned with numerical accuracies.<br>
> <br>
> Rune<br>
          <br>
In 3D and 2D space the inner (or scalar) product is not more fundamental than the vector product (or in 2D, the determinant.)<br>
<br>
The advantage of matlab's 'atan2' function is that it can take advantage of both the sine and cosine functions to ensure accuracy over its full range of angles. Also it allows a wider range from pi to +pi for the angle, as opposed to a restriction to 0 to pi for the arccosine and pi/2 to +pi/2 for the arcsine (and the arctangent) functions, if that is desired. A single glance at the plot of matlab's 'acos' function with its infinite derivatives at both the two ends should be a convincing argument as to the loss of accuracy there.<br>
<br>
Roger Stafford