Learning Objectives
After this section you will be able to:
- Explain why the sine, cosine, and tangent functions are not invertible on their full domain, and how restricting their domain fixes the problem.
- State the principal-branch domain and range of , , and — and know why each range is chosen.
- Use the cancellation identities and (and recognize when the second one fails).
- Reach for
atan2instead of plainarctanwhenever you have separate and components, and explain why it covers all four quadrants. - Implement the inverse trig functions in plain Python and use the differentiable PyTorch versions for ML pipelines.
- Apply them to real problems: angles of elevation, robotics joint angles, phase recovery, computer-graphics surface normals.
The Problem: From Ratio Back to Angle
The forward trig functions answer the question: “Given an angle, what is the ratio?” For instance, climbing a ramp at means you rise units for every 1 unit of slope.
But in real engineering and science the question almost always runs the other way:
I measured the rise and the slope length. What angle is the ramp at?
That is what the inverse trig functions exist to do. , , and reverse the arrow: feed them the ratio, get back the angle.
Notation: arcsin and sin⁻¹ mean the same thing
arc prefix is preferred in physics and engineering because the result IS an arc length on the unit circle; the notation is preferred in calculus textbooks. Note that does not mean — that would be the cosecant.Why Sin, Cos, Tan Aren't Invertible Yet
A function is invertible only when each output comes from one and only one input — the so-called horizontal-line test: every horizontal line must hit the graph at most once.
Sine fails this test catastrophically. The horizontal line crosses at infinitely many places — every , , , and so on. So if someone says “sin θ = 0.5, what is θ?”, the honest answer is “infinitely many possibilities”. That is useless.
The fix: restrict the domain
Cosine and tangent need the same trick, but with different slices:
| Function | Principal-branch slice | Why this slice? |
|---|---|---|
| sin x | x ∈ [-π/2, π/2] | sin is strictly increasing here; covers all outputs in [-1, 1] exactly once. |
| cos x | x ∈ [0, π] | cos is strictly decreasing here; covers [-1, 1] exactly once. (Can't use [-π/2, π/2] — cos is even, so each output is hit twice.) |
| tan x | x ∈ (-π/2, π/2) | tan is strictly increasing, covers all of ℝ, and the slice is open because tan blows up at ±π/2. |
arcsin: The Inverse of Sine
Take the sine curve and clip it to the principal slice . Now reflect it across the diagonal line . That mirror image IS .
This is the deepest single picture in the section — drag the slider below and watch the mirror move with you.
Reflecting the sine curve to build arcsin
Drag the slider. The blue dot slides along the restricted sine on [-π/2, π/2]. The pink dot is its mirror image across the dashed diagonal — that mirror trace IS the arcsin curve.
Notice three things in the picture:
- The blue point lives on the sine curve, with coordinates .
- The pink point lives on the arcsin curve, with coordinates — its x and y are simply swapped. That swap is what "reflection across " means.
- The pink curve only exists for inputs in , because that is the range of sine. Try to ask and you get a domain error: no angle has a sine of 1.5.
Formal definition. For , is the unique angle such that .
Reading the triangle
If a right triangle has opposite side and hypotenuse , then the angle opposite to side is recovered by . Try the interactive triangle below with the "arcsin" tab — slide the ratio and watch the angle change.
From a ratio back to an angle
Choose which ratio you know (opposite/hypotenuse for arcsin, adjacent/hypotenuse for arccos, opposite/adjacent for arctan) and slide the value. The triangle and the angle on the unit circle update live.
arccos and arctan
arccos: the "adjacent over hypotenuse" inverse
takes a value in and returns an angle in . Why and not ? Because cosine is even: , so the values it produces on exactly repeat what it does on . We need a slice where cosine is strictly monotone, and the natural choice is , where cosine is strictly decreasing from to .
arctan: the "opposite over adjacent" inverse
accepts any real number and returns an angle in — open intervals at both ends, because tangent has vertical asymptotes there. As the input grows without bound, the output approaches but never reaches .
This is why arctan is the only inverse trig function with a bounded range but an unbounded domain. It maps the whole real line to a finite open interval — that property makes it a popular "soft clamp" in machine learning and signal processing.
A useful limit
The Three Graphs Side by Side
Switch tabs in the viewer below to see each principal-branch graph with its domain on the x-axis, its range as a shaded band on the y-axis, and a live readout for the value you pick.
The three principal-branch graphs
A few features deserve attention:
- arcsin: domain , range . Passes through the origin. Odd function — symmetric about the origin.
- arccos: domain , range . Passes through . Strictly decreasing — bigger cosine means smaller angle (think: the closer the adjacent is to the hypotenuse, the more the triangle is "flattened").
- arctan: domain all of , range . Two horizontal asymptotes. Odd function.
Cancellation Identities (and a Common Trap)
Because is the inverse of restricted sine, the cancellation works perfectly in one direction:
Same pattern for the other two:
But the other direction is delicate. Try plugging into :
The trap: composition with the principal branch
Concretely, if (which is , in the third quadrant), then , and — definitely not . Information about which "copy" of the angle we started in was destroyed by sine and cannot be recovered by arcsin alone.
Useful Pythagorean identities
Frequently the angle is just an intermediate step; what you really want is another trig value of it. These identities let you skip the angle entirely:
Both of these come from drawing a right triangle that realises the inverse-trig input as one of its sides. For : let , so the opposite side is and the hypotenuse is ; by Pythagoras the adjacent side is , and . You can derive every entry in this table that way.
Worked Example: Finding the Angle of a Roof
A construction crew is building a roof. The rise (vertical) is meters and the run (horizontal) is meters. The supervisor needs the angle of the roof in degrees so the trusses can be cut. Let's do this by hand before letting a calculator do it, so the meaning of every step is clear.
▶ Step-by-step worked solution (click to expand and solve along)
Step 1 — Identify which ratio you have. Rise is the side opposite the angle you want; run is the side adjacent to it. So the natural ratio is , which means we use to recover .
Step 2 — Apply arctan. Using the Taylor series (which converges nicely for ):
Computing the first three terms:
Sum so far: radians. The remaining terms shave off a few thousandths to give the true value rad.
Step 3 — Convert to degrees. Multiply by :
Step 4 — Sanity check with the triangle. The hypotenuse is . So , and rad — the same answer. Two different paths through the triangle converge on the same angle, which is exactly the consistency check the cancellation identities promise.
Engineer's takeaway
atan2: The Practical Four-Quadrant Inverse
Here is a problem you will hit in your first robotics, game, or graphics project. You know a point's in the plane, and you want the angle from the positive -axis to the point. The naive answer is . The naive answer is wrong half the time.
Why? returns angles only in , which covers only the right half of the plane. And dividing by throws away the sign information you need to tell, for example, the point in the second quadrant apart from in the fourth — both have .
The fix is a function that takes and separately, looks at the sign of each, and returns the correct angle anywhere in . Every language calls it the same name: atan2(y, x).
Drag the yellow point in the viewer below. The green ray shows the angle that atan2 recovers (always correct). The dashed pink ray shows what arctan(y/x) would give — watch it stay in the right half-plane even when the actual point is on the left.
arctan(y/x) vs atan2(y, x): why the second one exists
Drag the yellow point anywhere. arctan(y/x) only ever returns angles in (-π/2, π/2), so it cannot tell (x, y) apart from (-x, -y). atan2(y, x) uses both signs and returns the correct angle anywhere in (-π, π].
The piecewise definition of atan2
Under the hood, atan2(y, x) is just arctan(y/x) with a sign correction that depends on the quadrant. The full definition (using radians) is:
The piecewise nature of the definition is exactly what makes it correct: it inspects the sign of (which arctan never sees) and pushes the answer into the correct half-plane.
Rule of thumb
atan2(y, x), never arctan(y/x). The only time plain arctan is the right tool is when you genuinely only have the ratio and know the answer lives in the right half-plane.Python Implementation: From Scratch
Let's build ourselves using only the most basic Python — no math.atan, no NumPy — so the inner workings are exposed. The Taylor series gives us the principle; an iterative argument reduction trick makes it fast enough to use.
Take a moment to appreciate what just happened. We turned the abstract object "the inverse of the tangent function" into a 20-line Python program that any reader can step through with a pencil. The series gives us correctness; the reduction gives us speed; the sign trick gives us coverage of negative inputs. That is what every production atan implementation in libm ultimately is, with more polish for floating-point edge cases.
PyTorch: Vectorised and Differentiable
In machine learning the inverse trig functions show up wherever an angle is hidden inside another quantity: angular regression, orientation prediction in 6-DoF pose estimation, normalizing-flow Jacobians, hyperbolic embeddings. PyTorch ships them as first-class differentiable ops. The key point is that they propagate gradients exactly the way calculus says they should.
Derivatives you'll see in autograd
Gradient blow-up near the boundary
asin, your gradients can explode. Common fixes: clamp inputs to with a small , or rephrase the problem in terms of atan2, whose derivative is bounded everywhere.Real-World Applications
Robotics: inverse kinematics for a 2-link arm
A robotic arm with two segments of lengths and reaches a point . The two joint angles are recovered with inverse trig:
Notice , not — the target can be in any quadrant, including behind the robot. Using plain arctan would silently put the arm in the wrong half-plane.
Computer graphics: surface normals
The angle a surface normal makes with the camera is for unit vectors. This powers diffuse-lighting calculations in every raster and ray tracer. A pixel's brightness is roughly proportional to where came from an arccos.
Signal processing: phase recovery
A complex number has phase . FFT bins, OFDM demodulators, GPS carrier-tracking loops — they all unwrap phases using atan2, and they all subtly break if a developer reaches for arctan instead.
Geolocation: bearing between two GPS points
Given two latitude/longitude pairs, the compass bearing from one to the other is computed with atan2 of the cross-track and along-track displacements on the sphere. Every navigation app you have ever opened uses this formula thousands of times per second.
Machine learning: angular losses
For tasks where the output is an angle (head pose, wind direction, magnetic declination), naive MSE on the raw value fails because of the wraparound: predicting when the truth is is a 358° error in raw MSE, but only 2° geometrically. A clean fix: predict the unit-vector and recover the angle with .
Summary
| Function | Domain | Range | Key idea |
|---|---|---|---|
| arcsin(x) | [-1, 1] | [-π/2, π/2] | Reverses sin on the principal branch. |
| arccos(x) | [-1, 1] | [0, π] | Reverses cos on [0, π] (cos is even, can't use a symmetric slice). |
| arctan(x) | (-∞, ∞) | (-π/2, π/2) | Soft-clamps the whole real line into a bounded angle. |
| atan2(y, x) | (y, x) ∈ ℝ² \ {(0,0)} | (-π, π] | Full four-quadrant inverse — always use this for vector→angle. |
Key takeaways
- Inverse trig functions exist to recover an angle from a ratio. They are the everyday-use direction.
- Sin, cos, tan are not invertible globally. Each one is restricted to a principal branch where it is strictly monotone — that branch determines the range of the inverse.
- always, but only inside the principal branch. Outside, the composition folds the input back into the branch.
- is wrong half the time. Always prefer
atan2(y, x)when both components are available. - PyTorch's
asin,acos,atan, andatan2are fully differentiable. Their gradients are the textbook derivatives and . - The Pythagorean identities like let you skip computing the angle altogether when only another trig ratio is needed downstream.
Exercises
Conceptual
- Explain in your own words why uses the range instead of like . Hint: think about what symmetry cosine has that sine doesn't.
- Without computing, decide whether each statement is true or false. Justify briefly.
- (a)
- (b)
- (c)
- Sketch on the entire real line. Mark the two horizontal asymptotes and the point of inflection.
Computational
- A ladder of length 5 m leans against a wall. Its base is 1.5 m from the wall. What angle does the ladder make with the ground? Use and show the steps.
- Simplify, leaving no inverse trig in the answer: for .
- Evaluate exactly (no calculator):
- (a)
- (b)
- (c)
- Compute by hand the bearing from the origin to the point using both and
atan2(y, x). Which one gives the geometrically correct angle? By how much do they differ?
Programming
- Extend
my_arctanfrom this section to handlex = ±infandx = NaNgracefully (returning andNaNrespectively). Test with the edge cases. - Implement
my_atan2(y, x)in plain Python by composing yourmy_arctanwith the piecewise sign-correction rules. Verify on the four points (1, 1), (-1, 1), (-1, -1), (1, -1). - Train a tiny PyTorch model that predicts the angle of a 2D unit vector by outputting and recovering . Compare its accuracy to a model that predicts directly with MSE. Explain the gap.
Exploration
- The Leibniz series for is . How many terms do you need to compute to 6 decimal places? Now use Machin's formula — how many fewer terms are needed?
- Investigate the unwrap operation in
numpy.unwrap. Why is it needed when you compute the phase of a time-varying complex signal withatan2?
Next we'll meet hyperbolic functions — close cousins to sine and cosine, defined by exponentials instead of circles. They will give us the same kind of story all over again: forward, inverse, identities, derivatives — but with a hyperbola in the picture instead of a unit circle.