Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
atan2 angles

Subject: atan2 angles

From: Fran

Date: 11 Apr, 2013 21:57:08

Message: 1 of 2

Hello,

It's a bit embarrassing asking this owing to the simplicity but I am trying to do this:

given a vector from (0,0) to a point on a y-x axis (y pointing North, and x pointing to the East)...

calculate the angle between the positive Y axis and the vector.
1) I would like that if the vector lies on the positive Y i get 0 degrees.
2) The angle should increase as it goes ANTICLOCKWISE
3) I can only have values from 0-360 degrees.

Is it possible to avoid using IF loops and whatnot?

I think you need to use atan2...?

Please help.

Kind Regards,

F

Subject: atan2 angles

From: Roger Stafford

Date: 11 Apr, 2013 22:56:07

Message: 2 of 2

"Fran" wrote in message <kk7bjk$7hl$1@newscl01ah.mathworks.com>...
> given a vector from (0,0) to a point on a y-x axis (y pointing North, and x pointing to the East)...
>
> calculate the angle between the positive Y axis and the vector.
> 1) I would like that if the vector lies on the positive Y i get 0 degrees.
> 2) The angle should increase as it goes ANTICLOCKWISE
> 3) I can only have values from 0-360 degrees.
- - - - - - - -
  If I've understood you correctly, it would be this:

 a = 180/pi*mod(atan2(y,x)-pi/2,2*pi);

For example, if the vector points midway between south and east then 'a' would be 225 degrees, that is, a 225 degree swing counterclockwise from north down to southeast.

Roger Stafford

Tags for this Thread

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.

Contact us