TExcelTAD
Home › Pre-Calculus, Geometry & Trigonometry › Inverse Trigonometric Functions

Inverse Trigonometric Functions

The trig functions turn an angle into a ratio. Their inverses go the other way: given a ratio, which angle produced it? Because sine and cosine repeat forever, the answer is only unique once we restrict the angles, and those restrictions matter a lot in code.

The problem: many angles, one value

sin⁡30∘=sin⁡150∘=sin⁡390∘=12\sin 30^\circ = \sin 150^\circ = \sin 390^\circ = \frac{1}{2}. Infinitely many angles share each sine value, so sine has no inverse on its whole domain. A function needs to be one-to-one to have an inverse (see Composition and Inverse Functions). The fix is to keep only one stretch of the graph where the function takes every value exactly once, and invert that piece.

Function Restricted to Inverse Domain of inverse Range of inverse (principal value)
sin⁡\sin [−π/2,π/2][-\pi/2, \pi/2] arcsin⁡=sin⁡−1\arcsin = \sin^{-1} [−1,1][-1, 1] [−π/2,π/2][-\pi/2, \pi/2]
cos⁡\cos [0,π][0, \pi] arccos⁡=cos⁡−1\arccos = \cos^{-1} [−1,1][-1, 1] [0,π][0, \pi]
tan⁡\tan (−π/2,π/2)(-\pi/2, \pi/2) arctan⁡=tan⁡−1\arctan = \tan^{-1} all reals (−π/2,π/2)(-\pi/2, \pi/2)

Note: sin⁡−1x\sin^{-1} x means arcsin⁡x\arcsin x, not 1/sin⁡x1/\sin x. The reciprocal is csc⁡x\csc x. In code the names are asin, acos, atan.

The restricted intervals are chosen so that each covers all output values once, includes the first quadrant and is a single unbroken piece.

Using them

python · try it yourself
import math

print("asin(0.5)  =", round(math.degrees(math.asin(0.5)), 6), "°")
print("acos(-0.5) =", round(math.degrees(math.acos(-0.5)), 6), "°")
print("atan(-1)   =", round(math.degrees(math.atan(-1)), 6), "°")
print("atan(1e6)  =", round(math.degrees(math.atan(1e6)), 6), "°  (approaches 90° but never reaches it)")

try:
    math.asin(1.0000001)
except ValueError as e:
    print("asin(1.0000001):", e)
asin(0.5)  = 30.0 °
acos(-0.5) = 120.0 °
atan(-1)   = -45.0 °
atan(1e6)  = 89.999943 °  (approaches 90° but never reaches it)
asin(1.0000001): math domain error

The last line is a real-world bug: computing acos(dot(u, v) / (|u||v|)) for two nearly parallel unit vectors can produce 1.0000000000000002 because of rounding, and the call crashes. Always clamp the argument to [−1,1][-1, 1] first.

Composing a function with its inverse

sin⁡(arcsin⁡x)=xfor every x in [−1,1]arcsin⁡(sin⁡θ)=θonly for θ in [−π/2,π/2]\begin{aligned} \sin(\arcsin x) &= x && \text{for every } x \text{ in } [-1, 1] \\ \arcsin(\sin\theta) &= \theta && \text{only for } \theta \text{ in } [-\pi/2, \pi/2] \end{aligned}

Outside the restricted range the second one fails: arcsin⁡(sin⁡150∘)=arcsin⁡(1/2)=30∘\arcsin(\sin 150^\circ) = \arcsin(1/2) = 30^\circ, not 150°.

A classic exercise is to simplify expressions like cos⁡(arcsin⁡x)\cos(\arcsin x). Let θ=arcsin⁡x\theta = \arcsin x, so sin⁡θ=x\sin\theta = x with θ\theta in [−π/2,π/2][-\pi/2, \pi/2], where cos⁡θ≥0\cos\theta \ge 0. Then

cos⁡(arcsin⁡x)=1−sin⁡2θ=1−x2\cos(\arcsin x) = \sqrt{1 - \sin^2\theta} = \sqrt{1 - x^2}

A right triangle with opposite xx and hypotenuse 1 gives the same result. SymPy agrees:

python · try it yourself
import sympy as sp

x = sp.Symbol("x", real=True)
print("cos(asin x) =", sp.cos(sp.asin(x)))
print("tan(acos x) =", sp.tan(sp.acos(x)))
print("asin(sin(5π/6)) =", sp.asin(sp.sin(5 * sp.pi / 6)))
print("acos(cos(-π/3)) =", sp.acos(sp.cos(-sp.pi / 3)))
cos(asin x) = sqrt(1 - x**2)
tan(acos x) = sqrt(1 - x**2)/x
asin(sin(5π/6)) = pi/6
acos(cos(-π/3)) = pi/3

atan2: the angle of a vector

To get the direction of a vector (x,y)(x, y), the naive formula atan(y / x) has two problems. It fails when x=0x = 0, and it cannot tell (1,1)(1, 1) from (−1,−1)(-1, -1), since both give y/x=1y/x = 1. The two-argument function atan2(y, x) looks at the signs of xx and yy separately and returns the true angle in (−π,π](-\pi, \pi]:

atan2⁡(y,x)=the angle θ with (cos⁡θ,sin⁡θ) pointing the same way as (x,y)\operatorname{atan2}(y, x) = \text{the angle } \theta \text{ with } (\cos\theta, \sin\theta) \text{ pointing the same way as } (x, y)

Note the argument order: yy first, then xx, in Python, C, JavaScript, NumPy and most other languages (Excel's ATAN2 is the exception, with xx first).

python · try it yourself
import math

points = [(1, 1), (-1, 1), (-1, -1), (1, -1), (0, 2), (-3, 0)]
print(" point      atan(y/x)   atan2(y, x)")
for x, y in points:
    naive = "undefined" if x == 0 else f"{math.degrees(math.atan(y / x)):7.1f}°"
    print(f"{str((x, y)):9} {naive:>10}   {math.degrees(math.atan2(y, x)):7.1f}°")
 point      atan(y/x)   atan2(y, x)
(1, 1)         45.0°      45.0°
(-1, 1)       -45.0°     135.0°
(-1, -1)       45.0°    -135.0°
(1, -1)       -45.0°     -45.0°
(0, 2)     undefined      90.0°
(-3, 0)        -0.0°     180.0°

The last row shows another trap: y/x=0/−3y/x = 0/{-3} is −0.0, so the naive formula says the vector points along the positive x-axis, the exact opposite of the truth. atan2 gets every row right.

In software

  • Aiming. To make a turret, an enemy or a camera face a target, compute angle = atan2(target.y − me.y, target.x − me.x). That one line is in nearly every 2D game (atan2 in game math, Trig in Games).
  • Angle between vectors with acos(clamp(cos_value, −1, 1)), or more robustly atan2(|u × v|, u · v), which is accurate even for tiny angles.
  • Inverse kinematics, robotics and geolocation (latitude from 3D coordinates uses asin or atan2).
  • Angles in [0,2π)[0, 2\pi). atan2 returns (−π,π](-\pi, \pi]; add % (2*math.pi) if you need a compass-style angle.
python · try it yourself
import math

def aim(me, target):
    return math.degrees(math.atan2(target[1] - me[1], target[0] - me[0]))

def clamp(v, lo, hi):
    return max(lo, min(hi, v))

print("aim from (2, 3) to (5, 7):", round(aim((2, 3), (5, 7)), 3), "°")
print("aim from (2, 3) to (-4, 3):", round(aim((2, 3), (-4, 3)), 3), "°")

a = 8 / 37
u = v = (math.cos(a), math.sin(a))   # the same unit vector twice
c = u[0]*v[0] + u[1]*v[1]            # should be exactly 1, rounds above it
print("dot product:", c)
try:
    math.acos(c)
except ValueError as e:
    print("acos(dot):", e)
print("safe angle:", math.acos(clamp(c, -1.0, 1.0)))
aim from (2, 3) to (5, 7): 53.13 °
aim from (2, 3) to (-4, 3): 180.0 °
dot product: 1.0000000000000002
acos(dot): math domain error
safe angle: 0.0

Exercises

Exercise 1: Exact principal values

Find arcsin⁡(−3/2)\arcsin(-\sqrt{3}/2), arccos⁡(−2/2)\arccos(-\sqrt{2}/2) and arctan⁡(3)\arctan(\sqrt{3}) in radians.

Answer

−π3-\frac{\pi}{3}, 3π4\frac{3\pi}{4}, π3\frac{\pi}{3}.

Solution
arcsin⁡(−3/2): angle in [−π/2,π/2] with sine −3/2→−π/3arccos⁡(−2/2): angle in [0,π] with cosine −2/2→3π/4arctan⁡(3): angle in (−π/2,π/2) with tangent 3→π/3\begin{aligned} \arcsin(-\sqrt{3}/2)&: \ \text{angle in } [-\pi/2, \pi/2] \text{ with sine } -\sqrt{3}/2 \to -\pi/3 \\ \arccos(-\sqrt{2}/2)&: \ \text{angle in } [0, \pi] \text{ with cosine } -\sqrt{2}/2 \to 3\pi/4 \\ \arctan(\sqrt{3})&: \ \text{angle in } (-\pi/2, \pi/2) \text{ with tangent } \sqrt{3} \to \pi/3 \end{aligned}
python · try it yourself
import sympy as sp
print(sp.asin(-sp.sqrt(3)/2), sp.acos(-sp.sqrt(2)/2), sp.atan(sp.sqrt(3)))
-pi/3 3*pi/4 pi/3

Exercise 2: Simplify a composition

Simplify sin⁡(arctan⁡x)\sin(\arctan x).

Answer

x/1+x2x / \sqrt{1 + x^2}.

Solution

Let θ=arctan⁡x\theta = \arctan x, so tan⁡θ=x\tan\theta = x with θ\theta in (−π/2,π/2)(-\pi/2, \pi/2). Draw a right triangle with opposite xx and adjacent 1; the hypotenuse is 1+x2\sqrt{1 + x^2}.

sin⁡θ=oppositehypotenuse=x1+x2\sin\theta = \frac{\text{opposite}}{\text{hypotenuse}} = \frac{x}{\sqrt{1 + x^2}}

The sign is right for negative xx too, since sin⁡θ\sin\theta and xx have the same sign in (−π/2,π/2)(-\pi/2, \pi/2).

Exercise 3: When the inverse does not undo

Evaluate arccos⁡(cos⁡(5π/3))\arccos(\cos(5\pi/3)) and arcsin⁡(sin⁡2)\arcsin(\sin 2) exactly.

Answer

π3\frac{\pi}{3} and π−2\pi - 2.

Solution
cos⁡(5π/3)=1/2, and the angle in [0,π] with cosine 1/2 is π/3.2 rad is not in [−π/2,π/2] (π/2≈1.571). sin⁡2=sin⁡(π−2), and π−2≈1.1416 is in range.\begin{aligned} &\cos(5\pi/3) = 1/2, \text{ and the angle in } [0, \pi] \text{ with cosine } 1/2 \text{ is } \pi/3. \\ &2\ \text{rad is not in } [-\pi/2, \pi/2]\ (\pi/2 \approx 1.571).\ \sin 2 = \sin(\pi - 2), \text{ and } \pi - 2 \approx 1.1416 \text{ is in range.} \end{aligned}
python · try it yourself
import math
print(round(math.acos(math.cos(5 * math.pi / 3)), 6), round(math.pi / 3, 6))
print(round(math.asin(math.sin(2)), 6), round(math.pi - 2, 6))
1.047198 1.047198
1.141593 1.141593

Exercise 4: Turn toward the target

A ship at (10, 10) faces 30° (math angle). A buoy is at (4, 18). Use atan2 to find the bearing to the buoy, then the signed turn in (−180∘,180∘](-180^\circ, 180^\circ] the ship must make.

Answer

Bearing≈126.87∘\text{Bearing} \approx 126.87^\circ, turn≈+96.87∘\text{turn} \approx +96.87^\circ (counter-clockwise).

Solution
direction=(4−10,18−10)=(−6,8)atan2⁡(8,−6)≈126.87∘(quadrant II)turn=126.87−30=96.87∘\begin{aligned} \text{direction} &= (4 - 10, 18 - 10) = (-6, 8) \\ \operatorname{atan2}(8, -6) &\approx 126.87^\circ && \text{(quadrant II)} \\ \text{turn} &= 126.87 - 30 = 96.87^\circ \end{aligned}
python · try it yourself
import math
bearing = math.degrees(math.atan2(18 - 10, 4 - 10))
turn = (bearing - 30 + 180) % 360 - 180
print(round(bearing, 2), round(turn, 2))
126.87 96.87

Test yourself

What is the range of arccos?

  1. [−π/2,π/2][-\pi/2, \pi/2]
  2. [0,π][0, \pi]
  3. [0,2π)[0, 2\pi)
  4. [−1,1][-1, 1]

What does math.atan2(-1, -1) return in degrees?

  1. 45°
  2. −45°
  3. 135°
  4. −135°

Why should you clamp before calling acos on a computed cosine?

  1. To convert to degrees
  2. Rounding can push the value slightly outside [−1,1][-1, 1], which raises a domain error or returns NaN
  3. acos only accepts positive numbers
  4. Clamping makes it faster