Learn Physics Simulation
From $F = ma$ to the Material Point Method, one runnable idea at a time.
This site teaches you to write physics simulations yourself. It starts with a single falling particle and ends with the methods behind modern snow, sand and fluid effects: the Affine Particle-In-Cell method, the Material Point Method and Position-Based MPM. On the way you will build ropes, rods that bend and twist, cable-driven tentacles, contact with friction, cloth, inflated bodies and muscles.
Every chapter works the same way. It introduces one idea: what problem it solves, the physics behind it and the maths you need, with small code snippets. Then it hands the keyboard to you. Each chapter comes with a starter file that runs in your browser but is missing the interesting part, and an exercise that asks you to fill it in. A reference solution is there when you need it, the same way LearnOpenGL teaches graphics.
You will understand three papers by the end. The last part walks through The Affine Particle-In-Cell Method (Jiang et al., SIGGRAPH 2015), The Material Point Method for Simulating Continuum Materials (Jiang et al., SIGGRAPH 2016 course) and A Position Based Material Point Method (Lewin, SIGGRAPH 2024 talk), section by section. Every idea they rely on is built earlier in the site, and the MPM chapters point out where each paper says the same thing in its own notation.
What you need
- A browser and a text editor. Everything runs as plain JavaScript in the browser: no install, no build step.
Clone or download the site, open
code/run.html?src=04-time-integration/starter.js, edit the starter, and refresh. - Some programming. If you can write a loop and a function in any C-like language, you can follow along. The code is deliberately plain so it ports easily to C#, C++ or Python.
- High-school maths, plus a willingness to meet more. Vectors and derivatives are enough to start. Matrices, partial derivatives and a little linear algebra come in gradually, each explained when it first appears.
How to use this site
- Read the chapter and run its demo. Play with the sliders before reading the maths; a feel for what happens makes the equations easier.
- Predict before you run. Each exercise asks you to guess what will happen first. Write the guess down; the surprises are where the learning is.
- Write the code yourself. Open the starter, find the
TODOs, and make the demo work. Use the hints only when stuck for a while, and the solution only to compare after you have something working. - Come back. The short questions at the end of each chapter are worth answering again a few days later, from memory. Recalling an idea is what makes it stick.