From Wikipedia , the free encyclopedia: In trigonometry, the two-argument function atan2 is a variation of the arctangent function. For any real arguments x and y not both equal to zero, atan2(y, x) is the angle in radians between the positive x-axis of a plane and the point given by the coordinates (x, y) on it.

It is often used then we need to get angle from 2d coordinates. Like, in simulations.
One could create a function of his own - returning angle in degrees or value from 0 to 2Pi - but there is de-facto standard for this function: Wikipedia defines it more as The angle is positive for counter-clockwise angles (upper half-plane, y > 0), and negative for clockwise angles (lower half-plane, y < 0).

−Pi < atan2(y, x) ≤ Pi.

Using compatible function increases your chances then converting code from other languages. Please pay attention to argument order!

Version by Stefan Pendl

Here's version coded by Stefan Pendl (translated from Wikipedia page):

function atan2(y,x)
pi =asn(1)*2if x <>0then arctan =atn(y/x)selectcasecase x >0
atan2 = arctan
case y>=0and x<0
atan2 = pi + arctan
case y<0and x<0
atan2 = arctan - pi
case y>0and x=0
atan2 = pi /2case y<0and x=0
atan2 = pi /-2endselectendfunction

Version by Brandon (nukesrus21)

If you prefer shorter code, here's version coded by Brandon (nukesrus21) (translated from alternate version, same Wikipedia page):

function atan2(y, x)OnErrorGoTo[DivZero]'If y is 0 catch division by zero error
atan2 =(2*(atn((sqr((x * x)+(y * y))- x)/ y)))exitfunction[DivZero]
atan2 =(y=0)*(x<0)*acs(-1)EndFunction

## ATAN2(y, x) function

## Table of Contents

In trigonometry, the two-argument function atan2 is a variation of the arctangent function. For any real arguments x and y not both equal to zero, atan2(y, x) is the angle in radians between the positive x-axis of a plane and the point given by the coordinates (x, y) on it.It is often used then we need to get angle from 2d coordinates. Like, in simulations.

One could create a function of his own - returning angle in degrees or value from 0 to 2Pi - but there is de-facto standard for this function: Wikipedia defines it more as

The angle is positive for counter-clockwise angles (upper half-plane, y > 0), and negative for clockwise angles (lower half-plane, y < 0).Using compatible function increases your chances then converting code from other languages.

Please pay attention to argument order!## Version by Stefan Pendl

Here's version coded by Stefan Pendl (translated from Wikipedia page):## Version by Brandon (nukesrus21)

If you prefer shorter code, here's version coded by Brandon (nukesrus21) (translated from alternate version, same Wikipedia page):