In trigonometry, the math of angles in triangles, circles and waves, the letter you want often sits inside a sine, a cosine or a tangent. Transposing the formula to free it needs their opposites: arcsin, arccos and arctan. They come with a catch. Many angles share the same sine, so the way back can give only one of them, the principal angle. This lesson turns the shapes module's formulas around for each of their letters, then runs a transformer's angles and a photo's tilt backward.
What you'll be able to do
Rearrange sin θ = o/h, cos θ = a/h and tan θ = o/a for any letter, using arcsin, arccos and arctan for the angle
Say which angle inverse trig gives back, the principal value, and find the other angles that share a sine or a cosine
Turn arc length, sector area, degrees and radians, and the distance formula around, keeping the ± and the conditions
Get a point's distance and angle from (x, y) with math.atan2, and say why math.atan fails on the left half
Find when a wave reaches a height, and its period, and run position codes, rotary angles and a photo's tilt backward
Quick check
Have a guess before you start. A ramp is 2 m long along its slope and rises 1 m. What angle does it make with the ground?
30°
26.6°
0.5°
60°
Show the answer
30°
The rise is the side opposite the angle, and the ramp is the hypotenuse, so sin θ = 1/2. The angle whose sine is 1/2 is 30°. Getting an angle back from a sine is the first thing this lesson does.
The math: undo sin, cos and tan
Purpose. Free a side or an angle from sin, cos or tan, and know which angle comes back.
In a right triangle, name the sides from one sharp angle θ: the opposite side o, the adjacent side a, and the hypotenuse h, the longest. lesson 43 gave two ratios. The third, the tangent, is rise over run:
sinθ=hocosθ=hatanθ=ao
People remember them as SOH CAH TOA: Sine is Opposite over Hypotenuse, Cosine is Adjacent over Hypotenuse, and Tangent is Opposite over Adjacent. Each has an opposite that turns a ratio back into an angle:
Done to the angle
Undone by
In Python
sin
arcsin, also written sin⁻¹
math.asin
cos
arccos, or cos⁻¹
math.acos
tan
arctan, or tan⁻¹
math.atan
As in lesson 20, the ⁻¹ means "undo", not "one over".
Quick check
From an earlier lesson: in a 5-12-13 right triangle, what is cos θ for the angle across from the side of 5?
5/13
12/13
13/12
5/12
Show the answer
12/13
Cosine is adjacent over hypotenuse. The side next to θ is 12 and the hypotenuse is 13, so cos θ = 12/13.
Watch a 10 m ladder leaning at θ = 0.6 radians, about 34°, from the ground. Its top is o = 10 sin θ up the wall: two layers on θ, sin and then × 10. The way back runs ÷ 10, then arcsin.
Try it now
Then set the angle to 2.5, about 143°: past upright, so the ladder leans the other way. Press Use these numbers.
Symbols and formula. Each ratio links three letters, so it rearranges three ways:
sinθ=ho⇒o=hsinθ,h=sinθo,θ=arcsinho
In plain words: to free a side, multiply or divide by the ratio. To free the angle, divide the two sides, then undo the sine.
Cosine and tangent work the same way: a = h cos θ, h = a/cos θ and θ = arccos(a/h); o = a tan θ, a = o/tan θ and θ = arctan(o/a).
Conditions. The hypotenuse is the longest side, so a sine or cosine is never above 1. arcsin and arccos take only numbers from −1 to 1: an o/h of 1.2 means a slip. arctan takes any number. Each returns one angle, its principal value: arcsin from −90° to 90°, arccos from 0° to 180°, and arctan between −90° and 90°.
Quick check
A kite flies 30 m up, and its string makes 40° with the ground. Which gives the string's length h?
h = 30/cos 40°
h = sin 40°/30
h = 30 sin 40°
h = 30/sin 40°
Show the answer
h = 30/sin 40°
The height is opposite the angle and the string is the hypotenuse: sin 40° = 30/h. Multiply by h, then divide by sin 40°: h = 30/sin 40° ≈ 46.7 m. Check: 46.7 × sin 40° ≈ 30.
Named mistakes.
Dividing by sin. From sin θ = 0.6, θ isn't 0.6/sin. sin is a step, not a number, and arcsin undoes it.
arcsin of one side. θ = arcsin(o/h), not arcsin(o)/h: divide first, then undo.
Reading sin⁻¹ x as 1/sin x. On a function, ⁻¹ means its inverse.
Trusting the one angle. sin(180° − θ) = sin θ, so 30° and 150° share the sine 0.5. arcsin says 30°, but an angle known to be over 90° is 150°.
Quick check
cos θ = 0.5. Which two angles from 0° to 360° fit?
60° and 240°
60° and 120°
60° and 300°
60° only
Show the answer
60° and 300°
arccos 0.5 is 60°. Cosine is the across part, so its partner is the mirror image below the middle: 360° − 60° = 300°. Sine pairs θ with 180° − θ; cosine pairs θ with 360° − θ.
A wave's timing. A wave over time t is y = A sin(ωt + φ). Its speed ω (omega) is the k of lesson 44. The period is T = 2π/ω, so ω = 2π/T, and the frequency f = 1/T, in cycles per second, gives T = 1/f. To find when the wave is at height y, peel the layers on t: ÷ A, arcsin, − φ, then ÷ ω. So t = (arcsin(y/A) − φ)/ω, which needs y between −A and A, and A and ω not 0. arcsin's angle is on the rising part, so this is a time on the way up. The wave passes y on the way down too, and both times come round every period T: if t is below 0, add T until it isn't.
Circles and distances. The module's other formulas turn around with the same moves.
Arc length s = rθ gives θ = s/r and r = s/θ, with θ in radians.
Sector area, the area of a pizza slice with angle θ, is A = ½r²θ: the slice is θ/2π of the whole circle's πr². So r² = 2A/θ, and r = √(2A/θ), keeping only the + root for a radius, with θ above 0.
Degrees and radians. rad = deg × π/180 is undone by × 180/π: deg = rad × 180/π.
Distance. Square both sides of d = √((x₂ − x₁)² + (y₂ − y₁)²), take away (y₂ − y₁)², take the root with ±, then add x₁:
x2=x1±d2−(y2−y1)2
Two points fit, one on each side of x₁. If d is less than the gap in y, no point does.
In your own words
Why does the way back through a sine give one angle, when many angles have that sine?
Write a sentence or two, then compare it with a good answer in the lesson.
In Python: angles come back in radians
Purpose. Undo trig in code, in the right units and the right quadrant.
It runs right here in your browser, with nothing to install.
math.asin, math.acos and math.atan return radians, so math.degrees turns the answer into degrees. The other angle with this sine is 180° − 36.87° = 143.13°. Going forward, math.radians turns degrees back before math.sin: 36.87° gives a height of 6 again. math.acos(5 / 13) undoes a cosine: in the 5-12-13 triangle, the angle next to the side of 5 is 67.38°. The last line frees the adjacent side from tan θ = o/a: a = o/tan θ = 8, the third side of the 6-8-10 triangle.
Worked example
Worked example: a point to polar and back
A point can be given by its distance r from the origin and its angle θ: x = r cos θ and y = r sin θ. Turned around, Pythagoras gives r = √(x² + y²), and math.atan2(y, x) gives θ.
(4, 3) is 5 from the origin at 36.87°. (−4, −3) is also 5 away, but down and to the left, at −143.13°. atan2 takes y and x separately, so it sees both signs and returns the angle in the right quadrant, anywhere from −180° to 180°. The last line goes back: 5 at −143.13° lands on (−4, −3).
Quick check
What does this print?
import math
x = -1
y = -1print(round(math.degrees(math.atan(y / x))), round(math.degrees(math.atan2(y, x))))
45 -135
-45 135
45 45
-135 -135
Show the answer
45 -135
y/x = 1, the same as for (1, 1), so atan gives 45°. atan2 sees that both are negative: the point is down and to the left, at −135°.
Why atan fails. y/x throws the signs away: (1, 1) and (−1, −1) both give 1, and arctan 1 is 45°. arctan only returns angles in the right half, so every point on the left comes out pointing the wrong way. atan2 also copes with x = 0, where y/x would divide by 0. At the origin itself, r = 0 and the angle means nothing.
Quick check
Which call stops the program with an error?
math.asin(-0.5)
math.acos(-1)
math.asin(1.2)
math.atan(1.2)
Show the answer
math.asin(1.2)
No angle has a sine of 1.2, so math.asin raises a ValueError. That's the condition |o/h| ≤ 1: check it before you undo the sine.
Drill
Fix the angle functions
ramp_angle(rise, length) should give a ramp's angle in degrees, from sin θ = o/h. angle_of(x, y) should give the angle of the point (x, y) in degrees, in every quadrant. Each has one slip.
In the lesson, your code is checked as you write it.
In your own words
Why does math.atan2 take y and x separately, instead of y/x?
Write a sentence or two, then compare it with a good answer in the lesson.
In AI and ML: positions, frequencies and a level photo
Purpose. Transformers turn positions into angles, and image pipelines turn photos. Running those formulas backward tells you where a number came from.
Position codes.Lesson 44 coded a position p as waves at several speeds. In the original transformer, pair i of a code d numbers long turns at frequency ω = 1/10000^(2i/d). Which pair has a given ω? Take log₁₀ of both sides, as in lesson 35. Since log₁₀ 10000 = 4, log₁₀ ω = −8i/d, so i = −d·log₁₀(ω)/8. That pair repeats every 2π/ω positions: its period.
Rotary embeddings (RoPE). Many recent language models, such as Llama, turn each pair of a query and a key by θ = p·ω instead. Turned around, p = θ/ω. But angles repeat every turn, so positions 2π/ω apart get the same turn.
A rotary pair with ω = 0.02 has been turned by θ = 3 radians. Which position p is it?
1.5
0.0067
0.06
150
Show the answer
150
θ = p·ω, so p = θ/ω = 3 ÷ 0.02 = 150. Check: 150 × 0.02 = 3.
A level photo. Image pipelines rotate training photos, and they can straighten a crooked one. Mark a trail sign's top-left and top-right corners, in that order. The top edge points at θ = atan2(y₂ − y₁, x₂ − x₁), and rotating by −θ makes it level. If the photo is more than a quarter turn off, the right corner sits to the left, and only atan2 sees it: atan would leave the sign level but upside down. Here y is measured up, as on a graph. Many image libraries count y down from the top, which flips the angle's sign.
In the first photo the top edge rises 14 over 48 to the right: a tilt of 16.26°. In the second, the top-left corner sits right of the top-right one, so the photo is nearly upside down: −163.74°, which is 16.26° − 180°. atan(14/48) would say 16.26° for both.
Drill
Run the position codes and the tilt backward
Write index_for(omega, d), the pair i whose frequency is ω = 1/10000^(2i/d), position_for(theta, omega), the position p of a rotary pair turned by θ = p·ω, and level_angle(p1, p2), the angle in degrees of the edge from corner p1 to corner p2. Each has one slip.
31Formulas with fractions: clear them firstFreeClearing denominators, cross-multiplying, a letter in the bottom, and reciprocal formulas like 1/R = 1/R₁ + 1/R₂.35 min
37Inverse functions, lines and scalingFreeUndoing a function by making x the subject, domains that allow it, line forms, and unscaling predictions.40 min
38Sequences and sums: find n, a, d and rFreeEvery letter of the arithmetic and geometric formulas as the subject, and an average's window from its decay.40 min
40Review: rearrange anything (algebra)FreeBroken rearrangements to fix, mixed practice from the whole algebra block, a strategy chart, and its formula sheet.35 min
41Coordinates and distanceFreePoints as (x, y), Pythagoras, distance in any number of coordinates, and nearest neighbors.42 min
42Angles, degrees and radiansFreeMeasuring a turn, converting units, arcs, and the angle between two arrows.36 min
43Sine and cosineFreeAcross and up: right triangles, the unit circle, and directions and rotations.42 min
44Waves: height, speed and shiftFreeAmplitude, period and phase, sampling a wave, and position codes in transformers.37 min
68Vector equations: rearranging with arrowsFreeSolving for a vector or a scale, recovering a gradient from two weight snapshots, and an angle from a dot product.40 min
87Counting: choices, orders and groupsFreeThe counting principle, factorials, ordered picks and groups, and why attention's cost grows with the square of the length.43 min
88Probability: from counts to chancesFreeEqually likely outcomes, the complement, distributions, seeded simulation, and a next-word model.43 min
89Combining events: and, or, independentFreeThe or rule, independence, probability trees, drawing with and without replacement, and chains of steps.42 min
100Maximum likelihoodFreeLikelihoods as products, log-likelihoods as sums, grid search, underflow, and the negative log-likelihood loss.45 min
101Linear regression: the best lineFreeResiduals, least squares by formula, three roads to one line, the matrix form, and train versus test error.45 min
109One neuron, start to finishFreeWeighted sum, activation, loss, slopes and update, by hand and in code, and what one straight line can and can't split.45 min
111Training a small networkFreeThe backward pass in matrix form, gradient checks, a full training loop, and reading loss curves.45 min
112The same network in PyTorchFreenn.Sequential with the NumPy weights loaded, the same loss and slopes, then SGD and mini-batches.45 min
113Attention as matrix mathFreeScaled dot-product scores, the causal mask, a row-by-row softmax, and blending value vectors.45 min
114Residual connections and layer normFreeAdding the input back and why its slope keeps learning alive, layer norm by hand, and add and norm.40 min
115A transformer block, start to finishFreeA sentence through embeddings, attention, add and norm, a small network and next-word scores, every shape named.45 min
117Final test: transpose any formulaFreeSlips to fix from every topic, mixed practice of every kind of rearranging, the strategy chart and the full sheet.45 min
Learn the math behind AI from arithmetic up: numbers, algebra, vectors and matrices, calculus, probability and statistics, each shown as numbers moving and checked in Python, ending with a network you build and train from the formulas.
Learn to make any letter of any formula the subject: layers undone in reverse order, fractions, a letter that appears twice, powers, roots, quadratics, logs, inequalities, trigonometry, vectors, matrices, calculus, probability, statistics and the formulas inside AI models, each checked in Python.
See the course →
Never trained an AI? Teach a small one to write, right in your browser. It takes about 20 seconds and needs no account. Teach it to write