LutzGross / esys-escript.github.io

Other
29 stars 13 forks source link

atan2 is not consistent with arctan2 of numpy #16

Closed LutzGross closed 3 years ago

LutzGross commented 3 years ago

atan2(X,Y) should be X>0 Y>0 = 0 to 90 (in rad) (is correct) X>0 Y<0 = 90 to 180 (is incorrect) X <0, Y>0 = 0 to -90 (is correct) X<0 Y<0 = -90 to -180 (is incorrect)

LutzGross commented 3 years ago

This could provide a fix in util.atan2

s=atan(arg0/(arg1+m))(1-m)+(np.pi/2)(1-2m2) m s+=(wherePositive(arg0)whereNegative(arg1)-whereNegative(arg0)whereNegative(arg1))*np.pi

but maybe this can be implemented better.

LutzGross commented 3 years ago

A better version:

z1=whereZero(arg1, rtol=EPSILON) s=(atan(arg0/(arg1+z1)) + sign(arg0)whereNegative(arg1)np.pi )(1-z1)+sign(arg0)whereNegative(arg1)np.pi/2z1

aellery commented 3 years ago

I have fixed this.