language-icon Old Web
English
Sign In

atan2

The function atan2 ⁡ ( y , x ) {displaystyle operatorname {atan2} (y,x)} or arctan2 ⁡ ( y , x ) {displaystyle operatorname {arctan2} (y,x)} (from '2-argument arctangent') is defined as the angle in the Euclidean plane, given in radians, between the positive x-axis and the ray to the point (x,y) ≠ (0,0). The function atan2 ⁡ ( y , x ) {displaystyle operatorname {atan2} (y,x)} first appeared in the programming language FORTRAN (in IBM's implementation FORTRAN-IV in 1961) and is defined like this. It was originally intended to return a correct and unambiguous value for the angle θ in converting from cartesian coordinates (x,y) to polar coordinates (r,θ). Equivalently, atan2 ⁡ ( y , x ) {displaystyle operatorname {atan2} (y,x)} is the argument (also called phase or angle) of the complex number x + i y . {displaystyle x+iy.} atan2 ⁡ ( y , x ) {displaystyle operatorname {atan2} (y,x)} returns a single value θ such that −π < θ ≤ π and, for some r > 0, It is clear that r = x 2 + y 2 {displaystyle r={sqrt {x^{2}+y^{2}}}} always, but it is not always accurate to observe which is correct only when x > 0. When x < 0, the angle apparent from the expression above is pointing in the opposite direction of the correct angle and a value of π (or 180°) must be either added or subtracted from θ to put the cartesian point (x,y) into the correct quadrant of the Euclidean plane. This requires knowledge of the signs of x and y separately, which is information lost when y is divided by x. Since any integer multiple of 2π can be added to the angle θ without changing either x or y, implying an ambiguous value for the returned value, the principal value of the angle, in the interval (-π, π] is returned. θ is signed, with counterclockwise angles being positive, and clockwise being negative. Specifically, atan2 ⁡ ( y , x ) {displaystyle operatorname {atan2} (y,x)} is in the interval when y ≥ 0, and in (−π, 0) when y < 0. The atan2 function was first introduced in computer programming languages, but now it is also common in other fields of science and engineering. It dates back at least as far as the FORTRAN programming languageand is currently found in many modern programming languages. Among these languages are: C's math.h standard library, the Java Math library, .NET's System.Math (usable from C#, VB.NET, etc.), the Python math module, the Ruby Math module, the Golang math package, and elsewhere. In addition, many scripting languages, such as Perl, include the C-style atan2(y,x) function.

[ "Inverse trigonometric functions", "Function (mathematics)" ]
Parent Topic
Child Topic
    No Parent Topic