Trigonometry: compact · 26 min

What rotation actually is

The angle addition formulas are not party tricks to memorize. They are the algebra of stacking two turns, and out of them falls the rule for rotating any point in the plane. That rule is the one a transformer uses to track position.

0 / 0

Turning, then turning again

Turn by α\alpha. Then, from where you stopped, turn by β\beta more. You have turned by α+β\alpha + \beta total. Obvious.

The non-obvious question: if you know the coordinates of the point at angle α\alpha and the coordinates at angle β\beta, can you compute the coordinates at angle α+β\alpha + \beta without measuring anything new?

You can, and the recipe is the angle addition formulas. They are the arithmetic of stacking turns. Once you have them, the rule for rotating a point falls out for free, and that rule is the destination of this whole module.

The formula for sine

Here is the sine of a sum:

sin(α+β)=sinαcosβ+cosαsinβ\sin(\alpha + \beta) = \sin\alpha\cos\beta + \cos\alpha\sin\beta

First, a warning about the obvious wrong guess. Addition does not distribute through sine: sin(α+β)\sin(\alpha + \beta) is not sinα+sinβ\sin\alpha + \sin\beta. Check it with α=β=π/2\alpha = \beta = \pi/2: the left side is sinπ=0\sin\pi = 0, the right side is 1+1=21 + 1 = 2. Trig functions are not linear, and that single counterexample settles it forever.

Drag Pα and Pβ. The four coordinates you read off the circle, plugged into the formula, always reproduce the third point. The angle addition formula is not magic — it is this arithmetic.

-1.5-1-0.50.511.5-1.5-1-0.50.511.5
read off cosα= 0.8253  sinα= 0.5646  cosβ=-0.3233  sinβ= 0.9463
cos(α+β) cosα·cosβ − sinα·sinβ =-0.8011  vs  x of Pα+β =-0.8011  ✓
sin(α+β) sinα·cosβ + cosα·sinβ = 0.5985  vs  y of Pα+β = 0.5985  ✓
angles α=0.600 rad  β=1.900 rad  α+β=2.500 rad

Drag PαP_\alpha and PβP_\beta. The widget reads their four coordinates straight off the circle, plugs them into the formula, and shows the result landing exactly on Pα+βP_{\alpha+\beta}.

The formula for cosine

And the cosine of a sum:

cos(α+β)=cosαcosβsinαsinβ\cos(\alpha + \beta) = \cos\alpha\cos\beta - \sin\alpha\sin\beta

Mind the minus sign. Sine of a sum adds its two terms; cosine of a sum subtracts. That sign is the single most common slip in this lesson, and it is the sign that will later separate a counterclockwise rotation from a clockwise one. The widget verifies this one too: the computed cosαcosβsinαsinβ\cos\alpha\cos\beta - \sin\alpha\sin\beta matches the xx-coordinate of Pα+βP_{\alpha+\beta} every time.

You do not have to memorize four formulas. Memorize these two for the plus case. The minus versions come from sin(β)=sinβ\sin(-\beta) = -\sin\beta and cos(β)=cosβ\cos(-\beta) = \cos\beta: just flip the sign of β\beta and watch the second term flip with it.

Build an exact value

You cannot read sin(75)\sin(75^\circ) off the unit circle directly, but 75=45+3075 = 45 + 30, and both of those are reference angles.

Apply sin(α+β)=sinαcosβ+cosαsinβ\sin(\alpha+\beta) = \sin\alpha\cos\beta + \cos\alpha\sin\beta with α=45\alpha = 45^\circ, β=30\beta = 30^\circ. What is sin(75)\sin(75^\circ), as a decimal?

Double angles, for free

Set β=α\beta = \alpha in the two formulas and you get the double-angle formulas with no extra work:

sin(2θ)=2sinθcosθ,cos(2θ)=cos2θsin2θ\sin(2\theta) = 2\sin\theta\cos\theta, \qquad \cos(2\theta) = \cos^2\theta - \sin^2\theta

These are not new facts to file away. They are the angle addition formulas with both inputs equal. Mention them so you recognize them later; they cost nothing.

The load-bearing step

Now the reason this lesson exists.

Take any point P=(x,y)P = (x, y). Write it in circle language: it sits at some distance rr from the origin, at some angle α\alpha. By the definition of sine and cosine scaled up by rr,

x=rcosα,y=rsinαx = r\cos\alpha, \qquad y = r\sin\alpha

Rotate PP counterclockwise by an angle θ\theta. It stays the same distance rr from the origin, it just swings to a new angle, α+θ\alpha + \theta. So its new coordinates are (rcos(α+θ), rsin(α+θ))(r\cos(\alpha + \theta),\ r\sin(\alpha + \theta)).

Those are angle-sum expressions. Expand them.

Out falls the rotation rule

Expand rcos(α+θ)r\cos(\alpha + \theta) with the cosine formula:

rcos(α+θ)=rcosαcosθrsinαsinθ=xcosθysinθr\cos(\alpha+\theta) = r\cos\alpha\cos\theta - r\sin\alpha\sin\theta = x\cos\theta - y\sin\theta

because rcosαr\cos\alpha is just xx and rsinαr\sin\alpha is just yy. Do the same with sine:

rsin(α+θ)=rsinαcosθ+rcosαsinθ=ycosθ+xsinθr\sin(\alpha+\theta) = r\sin\alpha\cos\theta + r\cos\alpha\sin\theta = y\cos\theta + x\sin\theta

Put them together. Rotating (x,y)(x, y) counterclockwise by θ\theta sends it to:

(x,y)    (xcosθysinθ,  xsinθ+ycosθ)(x, y) \;\longmapsto\; (x\cos\theta - y\sin\theta,\ \ x\sin\theta + y\cos\theta)

This was derived, not declared. It is the angle addition formulas read as a map on coordinate pairs. The rr and α\alpha vanished; you never need them.

Watch it run

The rotation rule is a plain function: feed it a pair of numbers and an angle, get a pair of numbers out.

rotation map — (x, y) ↦ (x cosθ − y sinθ,  x sinθ + y cosθ)
-4-224-4-224
x = 3.00 y = 1.00 θ = 30° cosθ = 0.866 sinθ = 0.500
x' = x·cosθ − y·sinθ = (3.00)(0.866) − (1.00)(0.500) = 2.098
y' = x·sinθ + y·cosθ = (3.00)(0.500) + (1.00)(0.866) = 2.366
P' = (2.10, 2.37)

Drag the point PP anywhere. Drag the angle dial to set θ\theta. The second dot is PP', and the readout substitutes your current numbers into xcosθysinθx\cos\theta - y\sin\theta and xsinθ+ycosθx\sin\theta + y\cos\theta step by step. No matrices, no magic. Two formulas, plugged in.

Rotate a point, x-coordinate

Rotate the point (3,0)(3, 0) counterclockwise by θ=π/2\theta = \pi/2. Recall cos(π/2)=0\cos(\pi/2) = 0 and sin(π/2)=1\sin(\pi/2) = 1.

Use x=xcosθysinθx' = x\cos\theta - y\sin\theta. What is the new xx-coordinate?

Rotate a point, y-coordinate

Same rotation: (3,0)(3, 0) turned counterclockwise by π/2\pi/2.

Use y=xsinθ+ycosθy' = x\sin\theta + y\cos\theta. What is the new yy-coordinate?

A note for later

One aside for the curious. If you have seen linear algebra, you will recognize the rotation rule as multiplication by the matrix

(cosθsinθsinθcosθ)\begin{pmatrix} \cos\theta & -\sin\theta \\ \sin\theta & \cos\theta \end{pmatrix}

That is the same map, repackaged. Module seven will introduce that packaging properly. The point worth making now: nothing you learned here will need to be unlearned. The matrix is just a tidier way to write the two formulas you derived.

Where this goes next

You just derived rotation from scratch, and that is not a small thing.

A transformer reads its words with no position attached. To fix that, it rotates pairs of numbers inside each word’s query and key vectors by an angle proportional to that word’s position. The mechanism has a name, rotary positional embedding, or RoPE, and it is the positional scheme inside LLaMA 2 and 3, Mistral, Gemma, Code-LLaMA, and PaLM. Flip the “RoPE view” toggle in the widget to see the same rotation relabeled in transformer terms.

The rotation is settled. The last lesson collects the other tools, polar coordinates and inverse trig, and then builds the position fingerprint itself.

Lesson complete

Nice tinkering.