atan2 weirdness
Carsten Haese
carsten.haese at gmail.com
Sun Jul 20 00:24:25 EDT 2008
narutocanada at gmail.com wrote:
> hi
>
> atan2 is supposed to return the angle to x-axis when given y and x, I
> suppose if I take [x,y] to one full circle, I should get 0-360 degree
> back---- but no, I get 3 full revolutions!
> maybe my understanding is wrong.
>
> from math import *
>
> def f(ang):
> a=ang
> if a>360: a-=360
> if a>360: a-=360
> if a<0: a+=360
> if a<0: a+=360
> return round(a)
>
> for i in range(0,360):
> t=2*pi*i/360.0
> print i,f(atan2(sin(t),cos(t))*180.0)
Your understanding of atan2 is correct, but your conversion from radians
to degrees is off by a factor of pi. Since pi is close to 3, you're
getting what appears to be three full revolutions.
HTH,
--
Carsten Haese
http://informixdb.sourceforge.net
More information about the Python-list
mailing list