Search All of the Math Forum:
Views expressed in these public forums are not endorsed by
NCTM or The Math Forum.



Re: Calculate angle on 0360 scale from positive and negatives x and y vectors.
Posted:
Mar 20, 2011 7:27 PM


"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://ralphschleicher.de>
Development * Consulting * Training Mathematical Modeling and Simulation Software Tools



