All paths

Vectors, trig and matrices for code

The math under every game and instrument, in C++ on an ESP32-C3: vectors, atan2, rotation, matrices, easing and smoothing, ending in a ship's compass needle on a screen.

ESP32-C3-DevKitM-1Free7 lessons5 h4 chapters1,970 XPCoding · Intermediate+150 XP

0 of 7 done

What you will build

3 projects, built step by step

7 lessons in 4 chapters, about 5 hours on a simulated ESP32-C3-DevKitM-1. Free, in your browser, every step checked by the simulator.

Chapter 1 project

Angles and atan2

Four beacons round a ship on a radar: radians and degrees, why atan(y / x) gets half of them wrong, how atan2 gets all four, compass bearings, wrapping, and the shortest turn.

Open it in the simulator
Chapter 2 project

Matrices

Six numbers that move, turn and grow a ship at once: 2D affine matrices, why the order of a product matters, the determinant as an area, and an inverse that turns a screen tap into ship coordinates.

Open it in the simulator
Chapter 3 project

Noise and smoothing

A shaky compass heading from the LIS3MDL, smoothed three ways: why averaging angles fails at north, averaging vectors instead, and an exponential filter that trades lag for calm.

Open it in the simulator
The map

Chapter by chapter

Each lesson opens when the one before it is done, and each chapter ends in a project.

Chapter 1

Arrows and angles

Vectors for motion and direction, and atan2 for which way to turn.

  1. Open205 XP

    Vectors

    A capsule drifting toward a docking port, in vectors: add and scale for motion, length and normalize for speed and direction, and the dot product for ahead or behind.

    0 of 5 steps

  2. ProjectLocked410 XP

    Angles and atan2

    Four beacons round a ship on a radar: radians and degrees, why atan(y / x) gets half of them wrong, how atan2 gets all four, compass bearings, wrapping, and the shortest turn.

    0 of 5 steps

4 questions, graded as you go.
Chapter 2

Turning things

Rotation by sine and cosine, and six numbers that do it all at once.

  1. Locked205 XP

    Rotation

    Turn a ship outline with sine and cosine: the rotation formula, why it turns clockwise on a screen, how small float errors pile up, and turning about a pivot instead of the corner.

    0 of 5 steps

  2. ProjectLocked410 XP

    Matrices

    Six numbers that move, turn and grow a ship at once: 2D affine matrices, why the order of a product matters, the determinant as an area, and an inverse that turns a screen tap into ship coordinates.

    0 of 5 steps

4 questions, graded as you go.
Chapter 3

Smooth motion

Interpolation that feels alive and filters that calm a shaky sensor.

  1. Locked205 XP

    Interpolation

    Glide a ship from a station to a dock: lerp, a vector lerp for a path, smoothstep easing that starts and stops gently, and turning a needle the short way around.

    0 of 5 steps

  2. ProjectLocked348 XP

    Noise and smoothing

    A shaky compass heading from the LIS3MDL, smoothed three ways: why averaging angles fails at north, averaging vectors instead, and an exponential filter that trades lag for calm.

    0 of 4 steps

4 questions, graded as you go.
Chapter 4

Project

A ship's compass on a screen.

  1. Locked187 XP

    Project: a compass needle on a screen

    A ship's compass from the LIS3MDL: atan2 for the heading, a vector filter for calm, a rotation matrix for the needle, the short way around, declination for true north and the cardinal point in big letters.

    0 of 5 steps

3 questions, graded as you go.
Syllabus

Every lesson in the course

All 7 lessons, in order, each with what it covers. Any of them opens in the editor right away.

Chapter 1

Arrows and angles

  1. VectorsA capsule drifting toward a docking port, in vectors: add and scale for motion, length and normalize for speed and direction, and the dot product for ahead or behind.
  2. Angles and atan2Four beacons round a ship on a radar: radians and degrees, why atan(y / x) gets half of them wrong, how atan2 gets all four, compass bearings, wrapping, and the shortest turn.
Chapter 2

Turning things

  1. RotationTurn a ship outline with sine and cosine: the rotation formula, why it turns clockwise on a screen, how small float errors pile up, and turning about a pivot instead of the corner.
  2. MatricesSix numbers that move, turn and grow a ship at once: 2D affine matrices, why the order of a product matters, the determinant as an area, and an inverse that turns a screen tap into ship coordinates.
Chapter 3

Smooth motion

  1. InterpolationGlide a ship from a station to a dock: lerp, a vector lerp for a path, smoothstep easing that starts and stops gently, and turning a needle the short way around.
  2. Noise and smoothingA shaky compass heading from the LIS3MDL, smoothed three ways: why averaging angles fails at north, averaging vectors instead, and an exponential filter that trades lag for calm.
Chapter 4

Project

  1. Project: a compass needle on a screenA ship's compass from the LIS3MDL: atan2 for the heading, a vector filter for calm, a rotation matrix for the needle, the short way around, declination for true north and the cardinal point in big letters.
Kits

Build it on your bench too

Every lesson runs in the simulator with nothing to buy. When you want the real thing, these kits have the parts.

Have a kit already?

Find your kit

Pick the starter kit you own and run every lesson in its manual with the same parts on the same pins.

See every kit
Questions

About Vectors, trig and matrices for code

Is Vectors, trig and matrices for code free?

Yes. All 7 lessons of Vectors, trig and matrices for code are free and run in your browser, with nothing to install and no parts to buy before you start.

Do I need a real ESP32-C3-DevKitM-1?

No. Every lesson runs on a simulated ESP32-C3-DevKitM-1 with its parts on the canvas, and the simulator checks each step as you go. When you want to build it for real, the same wiring and code work on a real board.

How long does Vectors, trig and matrices for code take?

About 5 hours: 7 lessons in 4 chapters, each one a few short steps. Your progress is kept, so you can stop after any lesson and pick up where you left off.

What will I build?

Each chapter ends in a project that puts it together: Angles and atan2, Matrices and Noise and smoothing.

Where do I start?

With "Vectors", and each lesson builds on the one before it. New to circuits? Electronics basics is the course that starts from zero.