Atan2

In computing, atan2 is a two-argument function that makes it easy to find the angle round the origin of a point. When given the coordinates ("x", "y") the angle is atan2("y", "x"). It is implemented in many different programming languages. The Linux Programmer's Manual [http://linux.ctyme.com/man/man0168.htm] says::"The atan2 C++ function calculates the arctangent of the two variables "y" and "x". It is similar to calculating the arctangent of "y"/"x", except that the signs of both arguments are used to determine the quadrant of the result."

In mathematical terms atan2 computes the principal value of the argument function applied to the complex number "x"+i"y".That is atan2("y", "x") = Pr arg("x"+i"y") = Arg("x"+i"y"). The argument can be changed by 2π corresponding to a complete turn round the origin without making any difference to the angle, the principal value is the value in the range (-π,π] , that is -π < atan2("y", "x") ≤ π.

Effectively, this means that atan2 finds the counterclockwise angle in radians between the "x"-axis and the vector in 2-dimensional Euclidean space, which is useful in many applications involving vectors, such as finding the direction from one point to another. A principal use is in computer graphics rotations, for converting rotation matrix representations into Euler angles.

The function atan2 dates back at least as far as the FORTRAN programming language and is currently found in the C programming language's math.h standard library, the Java (programming language) Math library and elsewhere. Many scripting languages, such as Perl, include the C-style atan2 function.

In other languages there are a number of variations in the name and sometimes the order of the parameters is reversed.

Some scientific calculators implement the function, it is the angle given when ("x", "y") is converted from rectangular coordinates to polar coordinates.

Motivation

The one-argument arctangent function does not distinguish between diametrically opposite directions. For example, the anticlockwise angle from the "x"-axis to the vector <1, 1>, calculated in the usual way as arctan(1/1), is π/4 (radians), or 45°. However, the angle between the "x"-axis and the vector <−1,−1> appears, by the same method, to be arctan(−1/−1), again π/4, even though the answer clearly should be −3π/4, or −135°.

The "atan2" function takes into account the signs of both vector components, and places the angle in the correct quadrant. Thus, atan2(1, 1) = π/4 and atan2(−1, −1) = −3π/4.

Additionally, the ordinary arctangent method breaks down when required to produce an angle of ±π/2 (or ±90°). For example, an attempt to find the angle between the "x"-axis and the vector <0,1> requires evaluation of arctan(1/0), which fails on division by zero. In contrast, atan2(1,0) gives the correct answer of π/2.

When calculations are performed manually, the necessary quadrant corrections and exception handling can be done by inspection, but in computer programs it is extremely useful to have a single function that always gives an unambiguous correct result.

Definition

For y≠0::operatorname{atan2}(y, x) = egin{cases}varphicdot sgn(y) & qquad x > 0 \frac{pi}{2}cdot sgn(y) & qquad x = 0 \(pi - varphi)cdot sgn(y) & qquad x < 0 \end{cases}

where varphi, is the angle in [0,π/2) such that an(varphi) = left| frac{y}{x} ight|, and sgn is the sign function.

And::operatorname{atan2}(0, x) = egin{cases}0 & qquad x > 0 \ ext{undefined} & qquad x = 0 \pi & qquad x < 0 \end{cases}

Notes:
* This produces results in the range (-π,π] , which can be mapped to [0,2π) by adding 2π to negative values.
* Traditionally, atan2(0,0) is undefined. Most current implementations define it as 0. It should always return a value rather than for instance a NaN (Not a Number).

Variations

*In Common Lisp, where optional arguments exist, the atan function allows to optionally supply the "x" coordinate as in (atan "x" "y")
*In Mathematica, the form ArcTan [x, y] is used where the one parameter form supplies the normal arctangent.
* In Microsoft Excel, the atan2 function has the two arguments reversed. [cite web|url=http://msdn2.microsoft.com/en-us/library/bb238940.aspx|title=Atan2 Method|publisher=Microsoft] OpenOffice.org Calc also reverses the arguments.
* In the Intel Architecture assembler code, "atan2" is known as FPATAN (floating-point partial arctangent) instruction. [IA-32 Intel Architecture Software Developer’s Manual. Volume 2A: Instruction Set Reference, A-M, 2004.] It can deal with infinities and results range from [-pi,+pi] (closed interval), e.g. operatorname{atan2}(infty, x)=+pi. Particularly, FPATAN is defined when both arguments are zero:
*:operatorname{atan2}(+0, +0) = +0
*:operatorname{atan2}(+0, -0) = +pi
*:operatorname{atan2}(-0, +0) = -0
*:operatorname{atan2}(-0, -0) = -pi
*:This definition is related with the concept of signed zero, i.e. pm 0; overset{def}{=} lim_{;x ightarrow 0^pm} x
* On the TI-89 calculator, the equivalent function is called R►Pθ and has the arguments reversed.

Illustrations

The first diagram shows values of atan2 at selected points on the unit circle. The values are shown in blue inside the circle. The four points (1,0), (0,1), (-1,0), and (0,-1) are labeled outside the circle.



The second diagram shows the values of atan2 over a region of the plane. The discontinuity along the negative half of the "x" axis is visible as a "wall" extending towards the top left of the graph.



References

ee also

*Arg (mathematics)
*Complex number
*Inverse trigonometric function including atan
*Complex argument (continued fraction)

External links

* [http://www.cplusplus.com/ref/cmath/atan2.html C++ Programmer's Reference]
* [http://www.mathworks.com/access/helpdesk/help/techdoc/ref/atan2.html MATLAB Function Reference]
* [http://reference.wolfram.com/mathematica/ref/ArcTan.html Mathematica Function Reference] (note argument order is reversed)
* [http://everything2.com/index.pl?node_id=1008481 atan2] at Everything2

Other implementations/code for atan2

* [http://mathforum.org/library/drmath/view/55417.html Bearing Between Two Points]
* [http://mathforum.org/library/drmath/view/54114.html Arctan and Polar Coordinates]
* [http://mathforum.org/library/drmath/view/54172.html What's 'Arccos'?]


Wikimedia Foundation. 2010.

Look at other dictionaries:

  • Atan2 — ██████████60  …   Wikipédia en Français

  • Atan2 — Arkustangens und Arkuskotangens sind mathematische Funktionen. Sie sind die Umkehrfunktionen des Tangens bzw. des Kotangens und damit Arkusfunktionen. Da der Tangens periodisch ist, wird zur Umkehrung der Definitionsbereich von Tangens auf ( − π… …   Deutsch Wikipedia

  • Arkustangens und Arkuskotangens — Der Arkustangens – geschrieben arctan, atan, neuerdings auch tan  − 1[1]) – sowie Arkuskotangens – geschrieben arccot, acot, neuerdings auch cot  − 1[2] – sind die Umkehrfunktionen der eingeschränkten Tangens und Kotangensfunktion: Da… …   Deutsch Wikipedia

  • Acot — Arkustangens und Arkuskotangens sind mathematische Funktionen. Sie sind die Umkehrfunktionen des Tangens bzw. des Kotangens und damit Arkusfunktionen. Da der Tangens periodisch ist, wird zur Umkehrung der Definitionsbereich von Tangens auf ( − π… …   Deutsch Wikipedia

  • Arccot — Arkustangens und Arkuskotangens sind mathematische Funktionen. Sie sind die Umkehrfunktionen des Tangens bzw. des Kotangens und damit Arkusfunktionen. Da der Tangens periodisch ist, wird zur Umkehrung der Definitionsbereich von Tangens auf ( − π… …   Deutsch Wikipedia

  • Arctan — Arkustangens und Arkuskotangens sind mathematische Funktionen. Sie sind die Umkehrfunktionen des Tangens bzw. des Kotangens und damit Arkusfunktionen. Da der Tangens periodisch ist, wird zur Umkehrung der Definitionsbereich von Tangens auf ( − π… …   Deutsch Wikipedia

  • Arctan2 — Arkustangens und Arkuskotangens sind mathematische Funktionen. Sie sind die Umkehrfunktionen des Tangens bzw. des Kotangens und damit Arkusfunktionen. Da der Tangens periodisch ist, wird zur Umkehrung der Definitionsbereich von Tangens auf ( − π… …   Deutsch Wikipedia

  • Arcus-Cotangens — Arkustangens und Arkuskotangens sind mathematische Funktionen. Sie sind die Umkehrfunktionen des Tangens bzw. des Kotangens und damit Arkusfunktionen. Da der Tangens periodisch ist, wird zur Umkehrung der Definitionsbereich von Tangens auf ( − π… …   Deutsch Wikipedia

  • Arcus-Tangens — Arkustangens und Arkuskotangens sind mathematische Funktionen. Sie sind die Umkehrfunktionen des Tangens bzw. des Kotangens und damit Arkusfunktionen. Da der Tangens periodisch ist, wird zur Umkehrung der Definitionsbereich von Tangens auf ( − π… …   Deutsch Wikipedia

  • Arcus Cotangens — Arkustangens und Arkuskotangens sind mathematische Funktionen. Sie sind die Umkehrfunktionen des Tangens bzw. des Kotangens und damit Arkusfunktionen. Da der Tangens periodisch ist, wird zur Umkehrung der Definitionsbereich von Tangens auf ( − π… …   Deutsch Wikipedia


Share the article and excerpts

Direct link
Do a right-click on the link above
and select “Copy Link”

We are using cookies for the best presentation of our site. Continuing to use this site, you agree with this.