A second way to name a point
Cartesian coordinates locate a point by “go right , go up .” There is another way, and it is the unit circle scaled up.
Polar coordinates name a point by : how far it is from the origin, and at what angle. To convert to the familiar and , you walk distance in the direction :
That is just the unit-circle definition, stretched by . Cosine and sine point you in a direction; says how far to go.
Pick a curve and scrub the angle dial. The left panel draws the path in polar; the right panel plots the same as an ordinary wave. One motion, two pictures.
Converting both directions
Forward, polar to Cartesian, is the pair above. Backward, Cartesian to polar, uses Pythagoras and an angle:
The radius is easy. The angle needs care, and that is the next idea: getting an angle back out of a coordinate is what inverse trig is for, and it has a catch.
Polar to Cartesian
Convert the polar point to Cartesian. Recall .
What is the -coordinate?
Inverse trig needs a restricted domain
You want to go from a sine value back to the angle. Define : “the angle whose sine is this.”
But there is a problem. is true at , and again at , and again every full turn after each of those. Infinitely many angles share a sine. So “the angle whose sine is ” is not a function yet, because a function must return one answer.
The fix is the same one you saw in algebra with , where returns only the non-negative root. We restrict the domain to a stretch where sine hits each value exactly once, the interval , and define to return the angle from that stretch. That chosen stretch is called the principal branch.
Cosine and tangent get the same treatment: returns angles in , and returns angles in .
The reciprocal trap
One notation warning. You will see written as . The there means “inverse function,” not “reciprocal.”
The reciprocal has its own name, cosecant, and it is a different thing. When in doubt, write . It cannot be misread.
An inverse sine
Evaluate , the principal angle whose sine is .
What is it, in radians?
An inverse tangent
Evaluate , the principal angle whose tangent is .
What is it, in radians?
Why atan2 exists
Back to converting a Cartesian point to its angle. Here is the catch in concrete form.
The point and the point have the same ratio . Feed that ratio to and it returns for both. But the two points are in opposite quadrants, apart. alone cannot tell them apart, because it only ever saw the ratio.
That is why code has a two-argument version, atan2(y, x). It takes both coordinates separately, so it can see the signs, and it returns the angle in the correct quadrant across the full . If you have ever written Math.atan2 in a program without quite knowing why it took two arguments, that is the reason: one argument throws away the quadrant.
Tagging a position with waves
Now the payoff the whole module was climbing toward.
Suppose you have a position, an integer , and you want to hand a machine a set of numbers that uniquely identifies it, smoothly, so that nearby positions get nearby numbers. Here is the move. Sample a stack of sine and cosine waves at the input , each wave at a different frequency:
where the wavelengths span a wide range. The fast waves change a lot between and ; the slow waves barely move. Together, the list of numbers is a fingerprint of .
Drag the position. The bar chart is the fingerprint at the current . The heatmap stacks the fingerprints of positions through , one per row.
Why many frequencies
Look at the heatmap. The high-frequency columns on the left flicker rapidly as you move down the rows: those waves separate adjacent positions sharply. The low-frequency columns on the right change slowly: those waves tell far apart from nearby.
Use only fast waves and distant positions start to look alike once the waves wrap around. Use only slow waves and neighbors are nearly identical. Use a spread of frequencies and you get both at once: every position gets a fingerprint that is unique, and that varies smoothly, so “close” and “far” are both visible in the numbers.
The fingerprint at position zero
At , every term is and every term is .
With frequency bands switched on, the fingerprint has components. How many of them equal ?
The endgame: where this whole module was going
Here is the artifact you have been building toward, named at last.
A transformer sees a bag of tokens with no order. “the cat sat” and “sat the cat” look identical to it unless position is added back in. To put position back, it tags each token with a vector of sines and cosines read off the unit circle at many frequencies, the exact fingerprint you just built. That is sinusoidal positional encoding, from the 2017 paper Attention Is All You Need:
That fraction is just the wavelength schedule, fast waves for small , slow waves for large , the same spread you saw in the heatmap.
And inside LLaMA 2 and 3, Mistral, and Gemma, the machine goes one step further: it rotates the query and key vectors by an angle proportional to position, the exact 2D rotation you derived from the angle addition formulas in the last lesson. That is RoPE. You did not just preview these ideas. You derived both halves of them.
What to expect next
The trigonometry you needed is done, and you can see the far shore from here.
Module four sharpens function transformations. Module five, calculus, shows why sine and cosine are unusually well-behaved under the derivative. Module seven recasts your rotation rule as a matrix. Module fifteen uses that matrix as RoPE inside attention, and module sixteen uses the multi-frequency fingerprint you built in this lesson. Every one of those is a turn of the same circle you have been dragging since lesson one.
Lesson complete
Nice tinkering.
Before you go