2026-09-22 Harsha Physics engine

This lerpette is unfinished3 problems
  • Chapter “The Loop” has no explicit id, so its runtime is looked up at code/the-loop/.

    Write the heading as ## The Loop {#the-loop}.

    physics-engine/point-dynamics/mixtape.md
  • No chapter in this lerpette has a runtime, so the page renders without a panel.

    Add code/the-loop/js/index.ts with a default-exported runtime.

    physics-engine/point-dynamics/
  • This lerpette has chapters but no code directory.

    Add physics-engine/point-dynamics/code//.

    physics-engine/point-dynamics/
00

Point bodies dynamics

A physics simulator solves the equations of motion using an integrator to iteratively advance the state through time. In simpler words, we use newton's laws of motion to update positions and velocities of bodies over small time steps.

In this article, we shall look at a simple physics simulation loop by building an n-body simulation. We shall start with a single particle under a spring force, and then build up to n-bodies that exert gravity on each other, which should not be that different qualitatively.

01 !

The Loop

Some terminology we need to familirize ourselves first -

  • State - the quantities that define the configuration of the system at that point of time. In this case (positions, velocities).
  • Integrator - a numerical method that takes in current state, acceleration and time step size and estimates the state at the next time step.

It would look something like this -

State(t)−>Integration overΔt−>State(t+Δt)State(t) -> Integration\ over \Delta t -> State(t+\Delta t)

Let's now take a look into the integration step. Let's say we start with state st=(xt,vt)s_t = (x_t, v_t). To calculate the next state st+1s_{t+1}, the most intuitive way to do it is just apply newton's equations on state sts_t at time tt.

at=k×xta_t = k \times x_t vt+1=at∗Δtv_{t+1} = a_t * \Delta t xt+1=vt∗Δtx_{t+1} = v_t * \Delta t

Okay, now onto the code.

Other lerpettes

More mixtapes in the library

Open the library