Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

arctan2 discrepancy in NumPy

I have come across a puzzling issue when using arctan2 in Numpy. Searching for atan2 errors did not answer the question, but someone might know the reason for this.

f = np.arange(0,100)
w = 2*np.pi*f/50
x = np.arctan2(sin(-w*d/2)*cos(w*d/2), cos(w*d/2)*cos(w*d/2))

gives different results to

f = np.arange(0,100)
w = 2*np.pi*f/50
x = np.arctan2(sin(-w*d/2), cos(w*d/2))

The former is out by an offset of $pi$ every period. Looks like a numeric issue but I have not seen any notes on this particular case.

like image 413
vlazzarini Avatar asked Jul 09 '26 19:07

vlazzarini


1 Answers

atan2( y, x) gives the angle between the x axis and the vector x,y. Therefore atan2( y, x) and atan2( ay, ax) are the same if and only if a>0. For example atan2( y, x) is pi/4 but atan2( -1*y, -1*x) is -3pi/4.

like image 97
dmuir Avatar answered Jul 11 '26 10:07

dmuir



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!