ATAN2


'atan2' is a two-argument function that computes the arctangent of y/x given ''y'' and ''x'', but with a range of (-pi,pi]. It was introduced first in many computer programming languages but is now common in all fields of science and engineering too.

Contents
Definition
Variations
References
See also
External links
Other implementations/code for atan2

Definition


''atan2'' is defined using the standard arctan function, whose range is (−π/2, π/2), as follows:
:operatorname{atan2}(y, x) = egin{cases}
rctan( rac y x) & qquad x > 0 \
pi + rctan( rac y x) & qquad y ge 0 , x < 0 \
-pi + rctan( rac y x) & qquad y < 0 , x < 0 \
rac{pi}{2} & qquad y > 0 , x = 0 \
- rac{pi}{2} & qquad y < 0 , x = 0 \
ext{undefined} & qquad y = 0, x = 0 \
end{cases}
(Note that the first parameter is ''y'' and ''x'' is the second.)
The so defined atan2 has domain in Bbb{R}^2 - {(0, 0)} and range in (−π, π].
If z = x + jy ,= r,mathrm{e}^{i arphi}, is a complex number, then
: arphi,=operatorname{arg}(z),=operatorname{atan2}(y, x),
is its argument in the interval (-π,π].
The same result is valid if a point on a plane is represented by (x,y) in cartesian coordinates and by (r,φ) in polar coordinates.
atan2 is available in most 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 '' 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 [1] for correctly finding the sign of the result in all quadrants. See also inverse trigonometric function.
:operatorname{atan2}(y, x) = egin{cases}
-operatorname{atan2}(-y, x) & qquad y < 0 \
pi - rctan(- rac y x) & qquad y ge 0 , x < 0 \
rctan( rac y x) & qquad y ge 0 , x > 0 \
rac{pi}{2} & qquad y > 0 , x = 0 \
ext{undefined} & qquad y = 0, x = 0 \
end{cases}

Variations



★ In Microsoft Excel, the atan2 function has the two arguments reversed.[2] . OpenOffice.org Calc also reverses the arguments.

★ In the Intel Architecture assembler code, ''atan2'' is known as FPATAN (floating-point partial arctangent) instruction [3]. 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.

References


1. [2]
2. Atan2 Method
3. IA-32 Intel® Architecture Software Developer’s Manual. Volume 2A: Instruction Set Reference, A-M, 2004.

See also



Complex number

Inverse trigonometric function

External links



C++ Programmer's Reference

MATLAB Function Reference

Mathematica Function Reference
Other implementations/code for atan2


[3]

Bearing Between Two Points

Arctan and Polar Coordinates

What's 'Arccos'?

This article provided by Wikipedia. To edit the contents of this article, click here for original source.

psst.. try this: add to faves