Chapter 07 · Sin, Cos & Motion

One spinning point
runs every game.

Forget the SOH-CAH-TOA trauma. Nobody in gamedev is solving triangles. sin and cos are just the coordinates of a point going around a circle — and once you see that, orbits, bobbing fish, water, swim paths and screen shake are all the same two lines of code.

press play — 90 seconds ↓
▶ watch rgbguy's original — Gamedev + Maths 🧮🐝🐟
The lesson · a 90-second movie you can touch

Press play. It explains itself.

Plays like the video — one caption at a time, the picture animating under it — and it pauses when it's your turn. Skip around with the dots or arrow keys. The full lab comes after.

2
skip the lesson ↓
90 seconds · it pauses when it's your turn
Step 1 · One spinning point

cos is across, sin is up

Take a circle of radius r. Put a point on the rim at angle θ. Where is it? X = r·cos(θ), Y = r·sin(θ). That's the entire definition — cos answers "how far across?", sin answers "how far up?". Drag the point around the rim (or hit spin) and watch the two legs trade lengths.

drag the rim point ↻

Spin it

120
θ = 47° = 0.82 rad
cos θ = 0.68  (across)
sin θ = 0.73  (up)
point = (r·cos θ, r·sin θ)
= (82, 88)
cos = how much across,
sin = how much up.
that's the whole of trig.
Step 2 · Unroll it

Where waves come from

Now the classic reveal. Keep the point spinning, but plot its height over time off to the right. The circle unrolls into the sine wave — that wobbly curve isn't a new thing to memorize, it's the same point, viewed sideways. Tick the cos box: same wave, just starting a quarter-turn (90°) earlier.

circle → wave

Speed

1.00

Plot

θ = 0.00 rad
y = sin(θ) = 0.00
x = cos(θ) = 1.00
cos leads sin by 90° — same wave, shifted
a wave is a circle
seen from the side.
Step 3 · Two lines of motion

Now make things move

Here's the gamedev payoff. Feed time in as the angle — θ = t·speed — and the spinning point becomes an orbit. Use only the sin half and it becomes a bob. Use two sins with different frequencies and you get the fish swim paths from the video. Every tab below is the same two lines wearing a different costume.

a sun, a planet, a moon
x = cx + r·cos(t·s)
y = cy + r·sin(t·s)

Orbit

115
1.00
x = cx + 115·cos(t·1.00) = …
y = cy + 115·sin(t·1.00) = …
the moon is the same formula, centred on the planet — circles on circles
it just... hovers
y = base + A·sin(t·f)
tilt = 0.2·cos(t·f)

Bob

30
2.0
y = base + 30·sin(t·2.0) = …
tilt = 0.2·cos(t·2.0) = …
the cos tilt is the sin's slope — it leans into the motion, so it feels alive
every idle animation ever.
the fish from the video 🐟
x = A·sin(a·t + φ)
y = B·sin(b·t)

Swim path

3
2
1.57
ratio a:b = 3:2
x = A·sin(3t + 1.57) = …
y = B·sin(2t) = …
two sins, different frequencies → Lissajous curve. integer ratio = closed loop
water, flags, grass...
yᵢ = base + A·sin(xᵢ·k + t·f)

Wave field

160
2.0
yᵢ = base + 34·sin(xᵢ·0.039 + t·2.0)
each dot runs the SAME formula — the phase offset xᵢ·k is what makes it travel
the dim cyan row is the same wave, +1.2 rad behind
Step 4 · Spot it in the wild
the same spinning point, everywhere —
  • Rotation matrices (chapter 03). That 2×2 matrix full of cos θ, −sin θ, sin θ, cos θ? It's this chapter in a coat — rotating a point is just moving it around the circle.
  • Screen shake. sin(t·40) × amplitude at high frequency, with the amplitude decaying over time. Chapter 09 will smooth the decay — but the wobble itself is pure sin.
  • Radar sweeps & minimaps. The sweeping line on a radar is (r·cos θ, r·sin θ) with θ climbing forever. Placing icons around a circular minimap? Same formula, one point per enemy.
  • Day–night cycles. Sun height = sin(timeOfDay). Ambient light, sky color, shadow length — all driven by one slow sine that loops forever for free.
See it in 3D · orbit it like Blender

The sin() ocean

Game water before fancy shaders existed — and still the backbone of stylized seas: every vertex of this mesh runs y = A·sin(x·k + t) + ½A·cos(z·k′ + t) each frame. The buoy just reads the same function at its own (x, z). The moon runs chapter-standard cos/sin orbit.

drag to orbit · scroll to zoom

Wave

0.7
0.6
y = 0.7·sin(x·0.6 + t)
every vertex, every frame
The source · rgbguy's original

Watch the video, jump by section

Click any moment on the right — it takes you straight there (in place when this site is served over http, on YouTube when opened as a local file).