Tim Wesserman or Edward Shore
03-16-2019, 02:20 AM
Post: #3
 Thomas Klemm Senior Member Posts: 1,770 Joined: Dec 2013
RE: Tim Wesserman or Edward Shore
(03-15-2019 10:44 PM)mathnovice Wrote:  I need to extend the function atan2(y,x).

Not sure if this helps, but you can emulate atan2:

$$atan2(y, x) = 2 \arctan \frac{y}{r+x}$$ where $$r=\sqrt{x^2+y^2}$$

In Python:
Code:
from math import pi, sqrt, atan

def atan2(y, x):
r = sqrt(x*x + y*y)
return 0.0 if r == 0.0 else pi if r + x == 0.0 else 2 * atan(y / (r + x))

Code:
>>> atan2(0, 0)
0.0

>>> atan2(0, 3)
0.0

>>> atan2(0, -3)
3.141592653589793

>>> atan2(2, 3)
0.5880026035475675

>>> atan2(-2, 3)
-0.5880026035475675

>>> atan2(2, -3)
2.5535900500422257

>>> atan2(-2, -3)
-2.5535900500422257

Quote:It is in FORTRAN and I have no idea about that.

Me neither.

Cheers
Thomas
 « Next Oldest | Next Newest »

 Messages In This Thread Tim Wesserman or Edward Shore - mathnovice - 03-15-2019, 10:44 PM RE: Tim Wesserman or Edward Shore - chromos - 03-15-2019, 11:09 PM RE: Tim Wesserman or Edward Shore - Thomas Klemm - 03-16-2019 02:20 AM RE: Tim Wesserman or Edward Shore - toml_12953 - 03-17-2019, 02:59 AM RE: Tim Wesserman or Edward Shore - ijabbott - 03-16-2019, 08:59 AM RE: Tim Wesserman or Edward Shore - JMB - 03-16-2019, 01:49 PM RE: Tim Wesserman or Edward Shore - Albert Chan - 03-16-2019, 09:11 PM RE: Tim Wesserman or Edward Shore - mathnovice - 03-16-2019, 03:39 PM RE: Tim Wesserman or Edward Shore - SammysHP - 03-16-2019, 06:25 PM

User(s) browsing this thread: 1 Guest(s)