Post Reply 
Tim Wesserman or Edward Shore
03-16-2019, 02:20 AM
Post: #3
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
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
Tim Wesserman or Edward Shore - mathnovice - 03-15-2019, 10:44 PM
RE: Tim Wesserman or Edward Shore - Thomas Klemm - 03-16-2019 02:20 AM
RE: Tim Wesserman or Edward Shore - JMB - 03-16-2019, 01:49 PM



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