Topic summary

Atan2

Atan2

In computing and mathematics, the functionatan2 is the 2-argumentarctangent. By definition, is the angle measure (in radians, with ) between the positive -axis and the ray from the origin to the point in the Cartesian plane. Equivalently, is the argument (also called phase or angle) of the complex number⁠⁠. (The argument of a function and the argument of a complex number, each mentioned above, should not be confused.)

The function first appeared in the programming language Fortran in 1961. It was originally intended to return a correct and unambiguous value for the angle ⁠⁠ in converting from Cartesian coordinates ⁠⁠ to polar coordinates⁠⁠. If and , then and ⁠⁠.

If ⁠⁠, the desired angle measure is ⁠⁠. However, when x < 0, the angle is diametrically opposite the desired angle, and ⁠⁠ (a half turn) must be added to place the point in the correct quadrant. Using the function does away with this correction, simplifying code and mathematical formulas.