math.atan(x) returns the arc tangent (inverse tangent) of x in radians, within [-pi / 2, pi / 2].
Unlike math.asin() and math.acos(), math.atan() accepts every real number including inf and -inf. When you have separate dy and dx coordinates, prefer math.atan2() to keep all four quadrants apart.
math.atan() is a function in Python's standard math module: import it with import math and call math.atan(...), or import the name directly with from math import atan.
Syntax
Import math and pass any slope or real number.
python
import math
angle_rad = math.atan(slope)
Call
What it does
math.atan(0)
Returns 0.0.
math.atan(1)
Returns approximately 0.785398... (pi / 4).
math.atan(float("inf"))
Returns approximately 1.570796... (pi / 2).
math.atan(float("-inf"))
Returns approximately -1.570796... (-pi / 2).
Because (-dy) / (-dx) == dy / dx, calling atan(dy / dx) loses the quadrant sign and fails when dx == 0; use math.atan2(dy, dx) instead.
Function signatures
python
math.atan(x, /)
# returns: float arc tangent in [-pi/2, pi/2]
Parameters
Parameter
Description
x
Required positional real number (int or float), unrestricted range including infinities.
Return Value
Return Value
Description
float
Angle in radians inside [-pi / 2, pi / 2]; returns nan for nan.
Python Examples
Example 1 — Compute Camera Field of View From Focal Length
Use 2 * math.degrees(math.atan(width / (2 * focal))) for camera lenses.
python
import math
sensor_mm = 36.0
for focal_mm in [24.0, 35.0, 50.0, 85.0]:
fov = 2.0 * math.degrees(math.atan(sensor_mm / (2.0 * focal_mm)))
print(f"{focal_mm:>4.0f}mm lens -> {fov:>5.2f} deg FOV")
Half-sensor right triangle. Half the sensor width divided by focal length gives the tangent of half the horizontal field angle.
Double for full FOV. Multiplying the arc tangent by two converts half-angle into total horizontal view.
Longer lenses narrow view. Stepping from 24mm wide angle to 85mm portrait narrows the view from 73.74 to 23.91 degrees.
Example 2 — See Why atan(y / x) Loses Opposite Quadrants
Compare math.atan(y / x) with math.atan2(y, x) on opposite points (1, 1) and (-1, -1).
python
import math
for y, x in [(1, 1), (-1, -1)]:
a1 = math.degrees(math.atan(y / x))
a2 = math.degrees(math.atan2(y, x))
print(f"({y:>2}, {x:>2}) -> atan={a1:>5.1f} atan2={a2:>6.1f}")
Classic pi identity. Since tan(pi / 4) = 1, four times atan(1) matches math.pi.
Asymptotes at ±90 degrees. Positive and negative infinity converge cleanly to 90.0 and -90.0 degrees.
Frequently Asked Questions
math.atan(x) takes one slope value and returns [-pi/2, pi/2]. math.atan2(y, x) takes two coordinates separately, handles x == 0 without division by zero, and returns the full [-pi, pi] range.
Not on real numbers or infinities. Unlike asin() and acos(), atan() accepts the entire real line plus inf and -inf.