Source: https://mokxi.com/teachers/plans/vectors-trig-and-matrices
Updated: 2026-11-19

Lesson plan

# Vectors, trig and matrices for code lesson plan

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.

4 chapters, 7 lessons, about 5 hours, on the ESP32-C3-DevKitM-1. Every lesson runs in the browser, with nothing to install.

Start a class from this course

The unit

## Objectives and materials

### By the end, students can

- Vectors for motion and direction, and atan2 for which way to turn.
- Rotation by sine and cosine, and six numbers that do it all at once.
- Interpolation that feels alive and filters that calm a shaky sensor.
- A ship's compass on a screen.

### Materials for the whole unit

- ESP32-C3-DevKitM-1
- Full-size breadboard
- Magnetometer, LIS3MDL
- TFT display, 240x320

Every part is already on the simulator’s bench, so there is nothing to buy or hand out. The counts are the most any one lesson uses, if you build it on real breadboards too.

Chapter 1. About 1 h 30 min

## Arrows and angles

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

Lesson | Time | What students do

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. | 45 min

- Arrows in code
- Speed and direction
- Ahead or behind?
- Twice as fast
- Overshoot

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. | 45 min

- Radians
- atan forgets the signs
- Compass bearings
- Wrap to 360
- The shortest turn

### Materials

- ESP32-C3-DevKitM-1
- Full-size breadboard
- Magnetometer, LIS3MDL
- TFT display, 240x320

### Check for understanding

Each student finishes "Angles and atan2" on their own, without opening the hints. The simulator checks 5 of its 5 steps as they go.

Then ask each one to explain, in a sentence or two, the last thing it asked of them: "The shortest turn".

Chapter 2. About 1 h 30 min

## Turning things

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

Lesson | Time | What students do

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. | 45 min

- Two lines of trig
- Errors pile up
- Lost in the corner
- Turn about a pivot
- Any angle

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. | 45 min

- Six numbers
- Order matters
- The determinant
- Bigger ship
- Undo it: a tap

### Materials

- ESP32-C3-DevKitM-1
- Full-size breadboard
- Magnetometer, LIS3MDL
- TFT display, 240x320

### Check for understanding

Each student finishes "Matrices" on their own, without opening the hints. The simulator checks 5 of its 5 steps as they go.

Then ask each one to explain, in a sentence or two, the last thing it asked of them: "Undo it: a tap".

Chapter 3. About 1 h 20 min

## Smooth motion

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

Lesson | Time | What students do

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. | 45 min

- lerp
- A glide in frames
- Ease in, ease out
- Angles wrap
- The long way is short

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. | 35 min

- A shaky compass
- Average the vectors
- Exponential smoothing
- Lag against calm

### Materials

- ESP32-C3-DevKitM-1
- Full-size breadboard
- Magnetometer, LIS3MDL
- TFT display, 240x320

### Check for understanding

Each student finishes "Noise and smoothing" on their own, without opening the hints. The simulator checks 4 of its 4 steps as they go.

Then ask each one to explain, in a sentence or two, the last thing it asked of them: "Lag against calm".

Chapter 4. About 45 min

## Project

A ship's compass on a screen.

Lesson | Time | What students do

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. | 45 min

- The instrument
- Come about
- Southwest
- True north
- Make it yours

### Materials

- ESP32-C3-DevKitM-1
- Full-size breadboard
- Magnetometer, LIS3MDL
- TFT display, 240x320

### Check for understanding

Each student finishes "Project: a compass needle on a screen" on their own, without opening the hints. The simulator checks 5 of its 5 steps as they go.

Then ask each one to explain, in a sentence or two, the last thing it asked of them: "Make it yours".

Your class

## Teach this unit as a class

Start a class from this course and its 7 lessons are assigned in one go, in order. Students join with a six-character code or printed login cards, and each one’s work comes back to you.

The class tools are free for 30 days for one class of up to 20 students, with no card. The lessons themselves are free either way.

Start a class from this course See the demo class

More units

## Other lesson plans

Electronics basics 20 lessons, about 10 h. Embedded on the Arduino Uno 16 lessons, about 12 h. Embedded on the ESP32-C3 13 lessons, about 11 h. Embedded on the Raspberry Pi Pico 7 lessons, about 6 h. Build your own fight stick 5 lessons, about 4 h. Embedded on the STM32F411 6 lessons, about 6 h. C++ on a board 13 lessons, about 10 h. Digital logic and memory 4 lessons, about 4 h. Interactive devices on the Uno 9 lessons, about 8 h. From gates to a computer 23 lessons, about 16 h. Build a claw machine 8 lessons, about 6 h. Every unit All the courses as ready-made units, on the teachers page.
