2

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.

vlazzarini
  • 31
  • 2

2 Answers2

0

Note that the error seems to be induced by a negative value in the cos() factor. This gets calculated correctly.

H = np.arctan2(sin(-w*d/2)*abs(cos(w*d/2)), cos(w*d/2)*abs(cos(w*d/2)))
vlazzarini
  • 31
  • 2
0

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.

dmuir
  • 4,211
  • 2
  • 14
  • 12