all Python 3mathterm
math.atan
trigonometry
The arc tangent of a value. It takes any real number and returns an angle in radians in (-π/2, π/2).
Syntax
math.atan(x)
atan only sees the ratio y/x, so the quadrant is lost: the points (1, 1) and (-1, -1) give the same ratio but angles that differ by π. To get the direction of a vector use math.atan2(y, x) instead — it keeps the quadrant and survives x == 0, where math.atan(y/x) would raise ZeroDivisionError.
Examples
import math
print(math.atan(0)) # → 0.0
print(math.atan(1)) # → 0.7853... (π/4)
print(math.atan(-1)) # → -0.7853...
print(math.atan(math.inf)) # → 1.5707... (π/2)
print(math.degrees(math.atan(1))) # → 45.0
print(math.atan(0.5)) # → 0.4636...
See also
Open in the full glossarydocs.python.orgReport an inaccuracy