math.acos(x) returns the arc cosine (inverse cosine) of x in radians, within the principal range [0, pi].
Like math.asin(), it requires -1 <= x <= 1 and raises ValueError outside that range. It is the standard tool for finding the unsigned angle between two vectors.
math.acos() is a function in Python's standard math module: import it with import math and call math.acos(...), or import the name directly with from math import acos.
Syntax
Import math and pass a cosine ratio in [-1, 1].
python
import math
angle_rad = math.acos(cos_value)
Call
What it does
math.acos(1)
Returns 0.0.
math.acos(0)
Returns approximately 1.570796... (pi / 2).
math.acos(-1)
Returns 3.141592653589793 (math.pi).
math.acos(2)
Raises ValueError: outside [-1, 1].
Always clamp dot-product cosines into [-1.0, 1.0] before calling math.acos() so tiny float drift does not raise ValueError.
Function signatures
python
math.acos(x, /)
# returns: float arc cosine in [0, pi] for -1 <= x <= 1
Parameters
Parameter
Description
x
Required positional number (int or float) between -1 and 1 inclusive.
Return Value
Return Value
Description
float
Angle in radians in [0.0, math.pi]; returns nan for nan.
Python Examples
Example 1 — Find the Angle Between Two 2D Robot Vectors
Compute normalized dot products and convert math.acos() radians into degrees.
Convert lat/lon to radians. Degrees are converted before evaluating spherical trig terms.
Central angle via acos. Ninety degrees along the equator yields a central angle of pi / 2 radians.
Multiply by radius. Scaling by Earth radius gives ~10,007.54 km, one quarter of the equator.
Example 3 — Test Exact Endpoints and Catch Out-of-Range Errors
Check endpoints 1, 0, and -1 and handle values outside [-1, 1].
python
import math
print(math.acos(1))
print(math.acos(-1) == math.pi)
print(round(math.degrees(math.acos(0)), 1))
for x in [-1.5, 2.0]:
try:
math.acos(x)
except ValueError:
print(f"acos({x}) raises ValueError")