Particles connected with springs and Simon’s Physics Library

Simulation of multiple particles connected mutually with springs. Made for Dan from the Coding Train.

Simon’s original code with 2 particles: https://editor.p5js.org/simontiger/sketches/18ib3ZNKm

Four particles: https://editor.p5js.org/simontiger/sketches/gkexoSqZZ

Simon has also started building his own physics library on a local server (work in progress). In Simon’s physics library, the user can play with four different force laws:

  • a constant force law (applies a specified constant force to objects)
  • a damping law (like friction, applies a force opposite to the object’s velocity)
  • a gravity law (like gravity, applies a force proportional to mass)
  • a spring (like a spring, applies a force based on Hooke’s law)

The user can also change the spring’s rest length and stiffness. The length is where the value at which the spring is “happy”, i.e. doesn’t want to expand or contract. The stiffness is how much it wants to move towards rest length. At a stiffness of 0, it doesn’t care at all about changing to its rest length, and at a stiffness of 1, it instantly changes back to its rest length.

It’s technically a variation of the physics engine from MyPhysicsLab, it uses the same kind of API.

Simon explains the constant law and the gravity law in his physics library
applying the damping law
undamped vs.damped spring

Leave a comment