Skip to main content
100%

Elastic collisions

✓ Published0🌍 Public
AAjayyy
Last edited Mar 19, 2019
Created on Mar 19, 2019

Four colored circles bounce off each other and the walls of a square canvas in elastic collisions, like billiard balls. The balls are draggable with the mouse, imparting velocity on release. The example adapts `d3.forceCollide` to compute two-dimensional elastic collision responses using physics formulas, with an SVG rendering. Forces are managed via `d3.forceSimulation` and a custom `boundedBox` force for wall bounces.

AI-generated description

Adapting d3.forceCollide to do elastic collisions (like billiards). You can click and drag the balls.

High school physics refresher from Wikipedia. Inspired by chatting with Robert Monfera and Chris Given's riffing on d3.forceCollide.

To-do:

  • Make it a proper es6 module
  • Log net momentum and kinetic energy for debugging
  • Balls can tunnel through each other or spawn atop each other, which somehow leads to non-conservation of momentum
  • In any case, momentum won't be conserved here because of the wall-bounces & dragging. A momentum-conserving finite-area alternative to walls would be to make the window a torus, I think, right?
  • Generalize to other shapes?
  • Relativistic! Lol.
  • Actual billiards game; then add gravitational forces and other twists...

forked from <a href='http://bl.ocks.org/tophtucker/'>tophtucker</a>'s block: <a href='http://bl.ocks.org/tophtucker/16fbd7e7c6274ed329111cbe139a6bb6'>Elastic collisions</a>

mit Licensed

Similar vizzes