ATAN2(y, x) function

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) * 2
    if x <> 0 then arctan = atn(y/x)
 
    select case
        case x > 0
        atan2 = arctan
 
        case y>=0 and x<0
        atan2 = pi + arctan
 
        case y<0 and x<0
        atan2 = arctan - pi
 
        case y>0 and x=0
        atan2 = pi / 2
 
        case y<0 and x=0
        atan2 = pi / -2
    end select
end function

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) 
    On Error GoTo [DivZero]      'If y is 0 catch division by zero error
        atan2 = (2 * (atn((sqr((x * x) + (y * y)) - x)/ y)))
        exit function
    [DivZero]
        atan2 = (y=0)*(x<0)*acs(-1)
End Function