Atan2: Difference between revisions

From Wikipedia, the free encyclopedia
Content deleted Content added
Maulattu (talk | contribs)
No edit summary
moved sentance to its own section, sourced it, and added a references section.
Line 1: Line 1:
{{lowercase|atan2}}
{{lowercase|atan2}}
'''atan2''' is a two-parameter function for computing the [[arctangent]] in the [[C programming language]], [[C++]], [[Java (programming language)|Java]], [[PHP]], [[C Sharp|C#]], [[Fortran]], [[MATLAB]] and many other modern programming languages. The Linux Programmer's Manual [http://linux.ctyme.com/man/man0168.htm] says:
'''atan2''' is a two-parameter function for computing the [[arctangent]] in the [[C programming language]], [[C++]], [[Java (programming language)|Java]], [[PHP]], [[C Sharp|C#]], [[Fortran]], [[MATLAB]] and many other modern 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 [[positive and negative numbers|signs]] of both arguments are used to determine the [[Cartesian coordinate system|quadrant]] of the result." (Note that the atan2 function in Microsoft Excel reverses the two arguments.)
:"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 [[positive and negative numbers|signs]] of both arguments are used to determine the [[Cartesian coordinate system|quadrant]] of the result."


Effectively, this means that <code>atan2(y,x)</code> finds the counterclockwise angle in radians between the ''x''-axis and the vector '''<x,y>''' in 2-dimensional [[Euclidean space]], which is useful in many applications involving vectors, such as finding the direction from one point to another.
Effectively, this means that <code>atan2(y,x)</code> finds the counterclockwise angle in radians between the ''x''-axis and the vector '''<x,y>''' in 2-dimensional [[Euclidean space]], which is useful in many applications involving vectors, such as finding the direction from one point to another.
Line 13: Line 13:
* if ''y'' < 0, then −π < atan2(''y'', ''x'') < 0,
* if ''y'' < 0, then −π < atan2(''y'', ''x'') < 0,
* if ''y'' > 0, then 0 < atan2(''y'', ''x'') < π.
* if ''y'' > 0, then 0 < atan2(''y'', ''x'') < π.
==Variations==
*In [[Microsoft Excel]], the atan2 function has the two arguments reversed.<ref>{{cite web|url=http://msdn2.microsoft.com/en-us/library/bb238940.aspx|title=Atan2 Method|publisher=Microsoft}}</ref>

==References==
{{reflist}}


==External links==
==External links==

Revision as of 14:29, 6 April 2007

atan2 is a two-parameter function for computing the arctangent in the C programming language, C++, Java, PHP, C#, Fortran, MATLAB and many other modern programming languages. The Linux Programmer's Manual [1] 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."

Effectively, this means that atan2(y,x) finds the counterclockwise angle in radians between the x-axis and the vector <x,y> in 2-dimensional Euclidean space, which is useful in many applications involving vectors, such as finding the direction from one point to another.

This is the preferred form [2] for correctly finding the sign of the result in all quadrants. See also inverse trigonometric function.

More specifically, the function atan2(y, x) is defined as the arctangent of y / x with a range from (−π, π], determined by:

  • if x = y = 0, then the result is indefinite (the MATLAB atan2 function returns 0),
  • if x > 0 and y = 0, then atan2(y, x) = 0,
  • if x < 0 and y = 0, then atan2(y, x) = π,
  • if y < 0, then −π < atan2(y, x) < 0,
  • if y > 0, then 0 < atan2(y, x) < π.

Variations

References

  1. ^ "Atan2 Method". Microsoft.

External links

Other implementations/code for atan2