Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

Views expressed in these public forums are not endorsed by Drexel University or The Math Forum.


Math Forum » Discussions » Software » comp.soft-sys.matlab

Topic: Calculate angle on 0-360 scale from positive and negatives x and y vectors.
Replies: 2   Last Post: Mar 20, 2011 7:27 PM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View  
Ralph Schleicher

Posts: 29
Registered: 1/23/10
Re: Calculate angle on 0-360 scale from positive and negatives x and y vectors.
Posted: Mar 20, 2011 7:27 PM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

"Thomas " <wandernmann@gmail.com> writes:

>> If you want it to range between 0 and 2*pi, just do this:
>>
>> a = mod(atan2(y,x),2*pi);
>>
>> Roger Stafford


> Ahh...atan2 and mod were just the functions I was looking for,

You should not use 'mod' in combination with multiples of pi because
it may result in ulp errors.

a = atan2(y, x);
tem = (a < 0);
a(tem) = a(tem) + 2 .* pi;

is the accurate form.

>> x = (-2*pi:pi/3:2*pi)';
>> [x, sin(x) == sin(mod(x, 2*pi))]

ans =

-6.2832 0
-5.236 0
-4.1888 0
-3.1416 0
-2.0944 0
-1.0472 0
0 1
1.0472 1
2.0944 1
3.1416 1
4.1888 1
5.236 1
6.2832 0

--
Ralph Schleicher <http://ralph-schleicher.de>

Development * Consulting * Training
Mathematical Modeling and Simulation
Software Tools



Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.