The question every 13-year-old asks
I was thirteen, sat in a maths classroom that smelled of radiator dust and felt-tip pens, staring at a triangle on the blackboard waiting for the end so I could run off to the bottom field for a cigarette. The teacher droned on about SOH CAH TOA, what felt like the fortieth time. Sine was opposite over hypotenuse. Cosine, adjacent over hypotenuse. Write it down. Learn it. There’ll be a test.
From the back of the room, someone spoke up, saying what we were all thinking: “Where the hell am I ever going to need this?”
It’s the oldest question in education. Every generation asks it, usually about algebra, Shakespeare or trigonometry. Nobody ever had a good answer. We got “you’ll need it for exams”, which is like saying “because I said so”.
I didn’t know it then, but within a couple of years I’d be using sin() and cos() nearly every day. Not because anyone made me. Because I wanted to make things move on a screen, and it turned out those two boring little functions were the key to almost all of it.
Ladders against walls
The problem wasn’t trigonometry; it was how it was sold to us.
Every example was a ladder leaning against a wall. Or a flagpole casting a shadow. Or a surveyor measuring the height of a building he could presumably have just walked into and asked about. Find the angle. Find the missing side. Turn the page, do questions 1 to 20.
That graph came next, with the teacher drawing a wavy line and explaining, enthusiastically, how sine goes from 0 to 1, down to −1, and back to 0 as the angle increases. And it does that over and over.
Wow. So a number goes from −1 to 1 in small steps. Sure. I’m certain that will come in handy in a career I have no idea about yet.
Nobody in that classroom wanted to know how tall a flagpole was. And not one of those examples hinted at what sine and cosine really are, or why they matter. We were shown triangles, but not the circle.
What got lost is that sine and cosine aren’t about triangles; they’re about things that go round and back and forth. Which, as I was about to find out, describes almost everything that looks good on a screen.
The Commodore 64: making things move
Later I had a Commodore 64, and I wasn’t interested in flagpoles. I was interested in sprites. I loved how spaceships swooped across the screen in my favourite games, instead of just sliding left to right.
Sprites moving in straight lines look dead. Move it in a curve, have it bob gently up and down, have a row of them ripple like a flag in the wind, and suddenly it looks alive. And every one of those motions is a sine wave.
Think back to Space Invaders. The aliens shuffle left, stop, drop down, shuffle right. No momentum, no inertia, no acceleration. Just left, then right, then left again. It’s static, it’s dull, and it’s very 1970s.
Now think of Asteroids, my favourite arcade game of all time. Spin the ship, hit thrust, and it surges forward, then keeps drifting after you let go. Turn round and you’ve to fight your own momentum to stop. It feels real in a way Space Invaders never did.
And under the bonnet? Every time you press thrust, the game works out which way the ship is pointing and turns that angle into movement. The push sideways is cos() of the angle. The push up or down is sin() of the angle. Add that to the ship’s speed every frame and you get acceleration, drift and that lovely floaty feel. The most satisfying ship in arcade history is a direction, a speed and two trig functions.
It’s a… it’s a… it’s a sin(). (Sorry. The Pet Shop Boys came on the radio while I was writing this. I couldn’t resist.)
The C64’s BASIC included a SIN() function, but it was slow on a 1 MHz 6510, turning smooth animations into slideshows when called every frame. Every coder back then did the same thing: they calculated values ahead of time and stored them in a table, using 256 bytes for numbers that followed a smooth curve. This way, each frame only required stepping through the table to read off the next position, a much faster process.
This sine table, just 256 bytes, proved incredibly useful. It enabled sprites to fly in arcs, raster bars to swing up and down the border, and text to scroll along the bottom of the screen with a wobble. All these effects came from the same small table of numbers, which I had initially thought I’d never need, just a few years prior.
It clicked at midnight in my bedroom, with a cassette deck and code print out I paid 75p for after reading an advert in the back of Your Commodore magazine, or whichever one it was at the time, not in some classroom setting.
The Amiga: sine waves everywhere
The Amiga. And demoscene arrived, and sin() and cos() became ubiquitous.
Amiga demos from the late 80s and early 90s are essentially trigonometry set to music:
- Sine scrollers. Each letter’s height was read from a sine table and offset for a snaking effect.
- Copper bars. Coloured bars bouncing up and down behind everything, sine waves controlled their movement at varying speeds, causing them to cross and overlap.
- Spinning objects like cubes and logos. Spinning cubes, glenz vectors, logos turning in 3D. The rotation formula was the same: new x = x × cos(a) − y × sin(a), and new y = x × sin(a) + y × cos(a). Do it on two or three axes and you’ve got a 3D engine.
- The plasma effect. Add a few sine waves together across the screen, run the result through a colour palette, and you get that hypnotic, liquid effect. Sine waves were used throughout.
- Bobs and dot tunnels, also based on sine and cosine. Objects traced circles and figure-eights using cosine for x and sine for y.
With a 7 MHz 68000, calling a proper sine function every frame wasn’t an option. It was lookup tables again, usually in fixed-point maths, with cosine read from the same table a quarter of the way along. Half the craft of the scene was squeezing as many of those lookups into a frame as the hardware would allow.
That rotation formula is the one I’d most like to have been shown at thirteen. This simple formula, with just two lines and four multiplications, is the basis for every 3D game.
The price of a sine
These days you call Math.sin(). And never think about it. In the 8-bit and 16-bit days, a sine was expensive, and you thought about it all the time.
The C64’s 6510 lacked multiplication capabilities. It couldn’t divide. It didn’t understand decimal points. BASIC’s SIN() function used a slow floating-point routine in ROM, which processed a polynomial series one byte at a time. This took thousands of CPU cycles to produce a single result. A PAL frame gives you roughly 20,000 cycles to do everything: move the sprites, play the music, scroll the text. A few SIN() calls would quickly deplete your frame’s cycle allocation.
We found a workaround. We calculated all sine values beforehand and stored them in memory for later use. This is what’s known as a sine table.
The classic C64 trick was to forget about 360 degrees altogether. A circle had 256 steps instead, because that’s exactly what fits in one byte. Count past 255 and you wrap back to 0, which is precisely what an angle does when it goes all the way round. Each entry was pre-scaled to the desired range, such as a screen position that oscillates between 50 and 200, eliminating the need for more math.
ldx angle ; current angle, 0-255
lda sintab,x ; look up the sine - about 4 cycles
sta $d001 ; drop it straight into sprite 0's Y position
inc angle ; next frame, next step round the circle
Four cycles, not thousands. Cosine was also free; it’s just sine, a quarter of a circle later, so you read 64 entries further along in the table. Make the table 256 plus 64 bytes long and you never have to worry about running off the end.
Tables came from all over the place. Some tables were generated by a slow BASIC loop that ran once, with the screen blank. Some were typed in as rows of DATA statements from a magazine. Some were generated by the assembler at build time or calculated on a bigger machine and copied over.
The Amiga had more power, but the A500’s 68000 lacked a floating-point unit, with even a plain integer multiply costing around 70 cycles. So the scene did the same thing, using fixed-point maths. A typical table held 1024 entries, each one the sine multiplied by 16384, so a whole number could stand in for a fraction.
lea sintab,a0
move.w angle,d0
and.w #1023,d0 ; keep the angle inside the circle
add.w d0,d0 ; entries are 2 bytes each
move.w (a0,d0.w),d1 ; sin(angle) x 16384
muls d2,d1 ; multiply by the point's coordinate
lsl.l #2,d1
swap d1 ; together: divide by 16384
How bad it got
Sine waves don’t leave once they’re in your head. It got this bad for me.
On a train from Exeter to Cardiff, I. One of those single-line LED scrollers was above the aisle, crawling through the stops: Bristol Temple Meads, Newport, Cardiff Central. Normal people read it, checked they were on the right train, and went back to staring out the window.
And I noticed the reflection underneath.
That scroller reflected in a curved piece of plastic trim, making the text below upside down and warped. As they moved through the bend, the letters stretched and squashed. And all my brain could think was: how would I code that?
I spent the next 30 to 45 minutes with my notebook out, Red Sector Megademo soundtrack blasting through my headphones, working it out. Flip the text vertically to mirror it. Darken it a bit, since reflections aren’t as bright as the real thing. Then shift each line of the reflection by a different amount to fake the curve; and there it was again, a sine wave deciding how far each row of pixels bent.
Somewhere around Newport I had a working routine on paper. No one else on the train had any idea they’d just been part of a demo effect.
Is that very sad, or is it no. It’s just sad. But it’s also what happens when maths stops being a lesson and becomes a tool. You stop seeing a reflection, start seeing a formula.
My Eurovision secret. I’m in it for the visuals. One act always has these huge screens with wild geometric patterns. Love those moments. Notepad comes out, I scribble down the effect and how they pull it off.
The circle, not the triangle
I wish someone had explained it to me like this; it takes about thirty seconds.
Picture a dot going round a circle. At any moment, cos() shows how far left or right the dot is; sin() honestly shows how far up or down. That’s all there’s to it.
Now look at just the up-and-down part over time and you get a wave that rises, falls and repeats forever, smoothly, with no sharp corners. This wave is what makes sine look natural in motion. Pendulums swing like that; springs bounce like that; and sound travels like that.
Sine and cosine give you two key abilities. Put them together and you can move anything in a circle, or rotate anything to any angle. Using one alone gives you perfectly smooth back-and-forth motion. Ladders and flagpoles are just a byproduct.
Still underneath everything
Forty-odd years have passed and hardware is now thousands of times faster, making hand-built sine tables obsolete. Nevertheless, sin() and cos() are still around, they’ve just become less prominent.
- The same maths used in old Amiga demos is still used today in every 3D game to rotate its world and camera.
- Sine waves are the basis for every sound you hear from a speaker, and they’re also used in synthesisers, MP3s, and phone calls.
- Many smooth animations on websites and apps, like “ease in, ease out”, rely on a sine curve.
- Trigonometry plays a crucial role in a lots of fields, including GPS, signal processing, image compression, physics engines, and robotics.
Even now, I use them in my browser canvas and WebGL work. They’re perfect for creating a tunnel effect or a wobbling logo, and they can also be used to make a starfield spin. JavaScript has replaced 68000 assembly as my language of choice, but the two key functions that do all the work are still the same ones I initially came up with on that blackboard.
So, to answer the question
If I could go back to that classroom, I wouldn’t tell thirteen-year-old me to pay attention because of the exam. I’d say go home and make something move.
That’s what teachers often miss. Not ‘it’s for later’, but ‘here’s what it does, try it out’. When sine and cosine went from exercises to making a spaceship move, I learned more in a week than in a year of SOH CAH TOA.
For every kid in a maths class wondering where they’ll use this, that’s a fair question. But there’s a better question. What do you want to make happen?
Because the answer to that will lead you straight back to sin() and cos(). That’s what happened for me.

Comments (0)