Showing posts with label atan. Show all posts
Showing posts with label atan. Show all posts

Tuesday, November 8, 2011

atan2 overview

The atan2 function computes the principal value of the arc tangent of y / x, using the signs of both arguments to determine the quadrant of the return value. It produces correct results even when the resulting angle is near π/2 or -π/2 (or x near 0).

The atan2 function is used mostly to convert from rectangular (x,y) to polar (r, θ) coordinates that must satisfy x = r cos(θ) and y = r sin (θ). In general, conversions to polar coordinates should be computed thus


r := \sqrt{x^2 + y^2}
\theta := \mathrm{atan2}(y,x)

  • atan2 ( ±0, -0) returns ± π.
  • atan2 ( ±0, +0 ) returns ±0.
  • atan2 ( ±0, x ) returns ±π for x < 0.
  • atan2 ( ±0 , x ) returns ±0 for x > 0.
  • atan2 ( ±0 ) returns -π/2 for y > 0.
  • atan2 ( ±y, -∞ ) returns ±π for finite y > 0.
  • atan2 ( ±y, +∞ ) returns ±0 for finite y > 0.
  • atan2 ( ±∞, +x ) returns ±π/2 for finite x.
  • atan2 ( ±∞, -∞ ) returns ±3π/4.
  • atan2 ( ±∞, +∞ ) returns ±π/4.