A short tour of a first physics simulation: the simulation loop, integrating position and velocity, and substepping for stability. Watch it first, then build the integrators here and measure what they do to energy.
COURSE / REAL PRACTICE
Simulation
Build small physics and agent simulations in NumPy: stable integrators, flocking, slime trails, a spatial hash, particle fluid, smoke on a grid, cloth and rigid bodies. Every build is checked against conserved quantities, closed forms or brute force. Lessons pair with public videos by Sebastian Lague and Ten Minute Physics. Unofficial practice material, not affiliated with the videos’ authors.
Read the explanation and diagrams, then work through the practice. Your browser profile supplies your saved progress.
What you’ll work toward
Write simulations whose energy, momentum, density or constraints you can measure, and tell a stable method from one that only looks right.
Read an explanation, inspect the diagrams and work through the available checks, debugging exercises and builds. Feedback and prerequisite links guide the next step.
Before you start
This course builds on these skills:
Individual lessons can add prerequisites. Your lesson progress shows your actual readiness.
A look inside the first lesson
def energy(x, v):
return 0.5 * v * v + 0.5 * x * x # k = m = 1
x, v, dt = 1.0, 0.0, 0.5
a = -x
v_new = v + a * dt
verlet_x = x + v * dt + 0.5 * a * dt * dt
verlet_v = v + 0.5 * (a + -verlet_x) * dt
print("explicit ", x + v * dt, v_new, energy(x + v * dt, v_new))
print("symplectic", x + v_new * dt, v_new, energy(x + v_new * dt, v_new))
print("verlet ", verlet_x, verlet_v, round(energy(verlet_x, verlet_v), 5))Your lesson sequence
Follow the same units and lessons in either view. Prerequisite links and your practice progress stay with each lesson.
Motion and agents
- LESSON 01.01
Integrators and energy
Step a spring with explicit Euler, symplectic Euler and velocity Verlet, watch their energy, measure their order, and run them from a fixed timestep.
Open lesson - LESSON 01.02
Flocking from three rules
Steer a flock with separation, alignment and cohesion, update every boid from the same old state, and test it on a wrapping torus.
Open lesson - LESSON 01.03
Slime trails on a grid
Agents sense a trail, steer toward it, move, deposit and let it diffuse and fade. Build each piece on a wrapping grid and test it against brute force.
Open lesson
Fluids
- LESSON 02.01
A spatial hash for neighbor search
Sort points into a hashed grid with a counting sort, then answer radius queries and list every close pair by looking only at the cells around a point.
Open lesson - LESSON 02.02
A particle fluid
Turn particles into a fluid: smoothing kernels, density, pressure and viscosity forces that cancel in pairs, and a stepper with walls.
Open lesson - LESSON 02.03
Smoke on a grid
Make a staggered velocity grid divergence free with Gauss-Seidel around solid cells, carry smoke along it by tracing backward, and check the result against a direct pressure solve.
Open lesson
Constraints and bodies
- LESSON 03.01
Cloth with position constraints
Hang a grid of particles on distance constraints, solve them by moving positions (XPBD), and prove the solver with exact single-edge, momentum and hanging-spring checks.
Open lesson - LESSON 03.02
Capstone: rigid bodies that collide
Build a small 2D rigid body engine: shoelace mass properties, separating axis contacts and impulses with spin and friction, checked by conservation laws.
Open lesson
WATCH ALONG
Videos for these lessons
One hand-picked talk, lecture or tutorial per lesson, in course order. They play here when you press play; nothing loads from the video provider before that.
8 videos· 2 h 44 min
-
-
The video this lesson is paired with: the three rules of a boid, then obstacle avoidance and speeding the simulation up. Watch it first, then build the rules and the update step here and test them against a brute-force oracle.
-
The paired video, on ant and slime simulations: agents that follow and lay trails, then many of them on one map. Watch the slime chapters first, then build the sense, turn, move, deposit and diffuse steps here.
04A spatial hash for neighbor search
An eleven-minute talk on finding close objects among thousands without testing every pair: the problem, the simple solution, the grid idea, the data structure and an implementation. Watch it first, then build the same lookup here.
-
A long build of a smoothed-particle fluid, from gravity and collisions through density, the pressure force, neighbour lookup, viscosity and a third dimension. Watch it first, then write a small 2D version of the same ideas here.
-
A long walk through an Eulerian smoke simulation, with chapters on divergence, solving for pressure, Gauss-Seidel iteration, solid cells and semi-Lagrangian advection. Watch it first, then build the same pieces here and compare against a direct solve.
07Cloth with position constraints
A short video on simulating cloth as particles joined by stretch constraints that are solved by moving positions, with chapters on stretchability and on finding neighbors. Watch it first for the overall picture.
08Capstone: rigid bodies that collide
Covers rigid body properties and a position-based solver for contacts. This lesson uses velocity impulses instead, so watch it for the vocabulary of mass, inertia and contacts, then compare the two ways of resolving an overlap.