Skip to content

2-Argument Arctangent

Definition

The 2-argument arctangent, denoted as atan2⁡\operatorname{atan2}, is a function defined by

atan2⁡(y,x)={ arctan⁡(y/x),x>0, arctan⁡(y/x)+π,x<0 and y≥0, arctan⁡(y/x)−π,x<0 and y<0, π/2,x=0 and y>0, −π/2,x=0 and y<0, undefined,x=0 and y=0.\operatorname{atan2}(y,x)= \begin{cases} \displaystyle \,\arctan(y/x),& x>0,\\[2pt] \displaystyle \,\arctan(y/x)+\pi,& x<0 \text{ and }y\geq 0,\\[2pt] \displaystyle \,\arctan(y/x)-\pi,& x<0 \text{ and }y< 0,\\[2pt] \displaystyle \,\pi/2,& x=0 \text{ and }y> 0,\\[2pt] \displaystyle \,-\pi/2,& x=0 \text{ and }y< 0,\\[2pt] \displaystyle \,\text{undefined},&x=0 \text{ and }y= 0. \end{cases}

Interpretation

The function atan2⁡\operatorname{atan2} answers the question: in which direction does the point (x,y)(x,y) lie, seen from the origin? It returns the angle in (−π,π](-\pi,\pi] measured from the positive xx-axis, which is the principal argument of the complex number x+iyx+\mathrm{i}y.

Coordinate axes with a point (x, y) in the second quadrant and its opposite point (-x, -y), which has the same ratio y/x; the angle atan2(y, x) from the positive x-axis tells them apart.

The blue point (x,y)(x,y) lies in the second quadrant, with x<0x<0 and y>0y>0. The grey point (−x,−y)(-x,-y) has the same ratio y/xy/x, so the inverse tangent gives both points the same angle in (−π2,π2)(-\tfrac{\pi}{2},\tfrac{\pi}{2}), namely the direction of the grey point. For the blue point the definition adds π\pi, half a turn, which gives the correct direction.

Drag the point (x,y)(x,y) into the left half-plane: arctan⁡(y/x)\arctan(y/x) only sees the slope, while atan2⁡(y,x)\operatorname{atan2}(y,x) adds or subtracts π\pi to give the true direction.

Each case of the definition repairs one defect of arctan⁡(y/x)\arctan(y/x). For x>0x>0 the point lies in the right half-plane, where the range (−π2,π2)(-\tfrac{\pi}{2},\tfrac{\pi}{2}) of arctan⁡\arctan is already correct. For x<0x<0 the angle is shifted by π\pi, upwards when y≥0y\ge0 and downwards when y<0y<0, so that the result stays in (−π,π](-\pi,\pi]; points on the negative xx-axis get π\pi, not −π-\pi. For x=0x=0 the ratio y/xy/x is not defined, and the angle ±π2\pm\tfrac{\pi}{2} is read off directly. At the origin there is no direction at all, so no value is assigned.

In practice, atan2⁡\operatorname{atan2} is how the polar form of x+iyx+\mathrm{i}y is found: r=x2+y2r=\sqrt{x^2+y^2} and φ=atan2⁡(y,x)\varphi=\operatorname{atan2}(y,x). Python provides it as math.atan2(y, x). Note the order of the arguments: yy comes first, as in the ratio y/xy/x.


Key Results

  • The range of atan2⁡(y,x)\operatorname{atan2}(y, x) is (−π,π](-\pi, \pi], covering all four quadrants.
  • atan2⁡(y,x)\operatorname{atan2}(y, x) is continuous at every point (x,y)≠(0,0)(x, y) \neq (0, 0) that does not lie on the negative real axis. Crossing the negative real axis (x<0x<0, y=0y=0), it jumps by 2π2\pi: just below the axis its values are close to −π-\pi, on and just above the axis they are close to π\pi.

Examples

  • atan2⁡(1,−1)=3π/4\operatorname{atan2}(1, -1) = 3\pi/4 (second quadrant).
  • atan2⁡(−1,−1)=−3π/4\operatorname{atan2}(-1, -1) = -3\pi/4 (third quadrant, within range (−π,π](-\pi, \pi]).

Prerequisites

Sources

Aliases: atan2, two-argument arctangent, arctangent with two arguments, arctan with two arguments, arctangent with 2 arguments, arctan with 2 arguments, arctan2 Symbols: phi, pi, square root

Last updated: 22 October 2026 19:04