Collision test with D3 4.0
Five particles in a D3.js 4.0 force-directed simulation demonstrate the inelastic nature of the built-in `collide` force. Two distinct sizes—four large dust particles and one small gas molecule—move and bounce within a bounded Canvas, colliding with each other and a vertical wall. The simulation runs via `d3.forceSimulation` with a `d3.forceCollide` radius function. Unlike elastic collisions, momentum is conserved but kinetic energy is not, as visible in the particle velocities after impacts. The particles are rendered as red, outlined circles on a transparent Canvas.
AI-generated descriptionFollowing up on a chat with Toph Tucker, this example shows that the collide force of d3.forceSimulation takes into account the particle "masses" (proxy: square radii of the colliding particles). It conserves momentum but the collision isn't elastic. It appears to be a perfectly inelastic collision.
Toph implemented elastic collisions with his force and the D3 force.
It doesn't matter much for the visual output of the Brownian motion example from which it's extracted, but for a pool / snooker simulator, just roll your own forces, similar to how the Brownian example makes particles bounce back from walls.
The main benefit of the built-in collide force is that it uses the quadtree for efficiency, but a cue game simulator would need to handle few "particles" only.
Built with blockbuilder.org
forked from <a href='http://bl.ocks.org/monfera/'>monfera</a>'s block: <a href='http://bl.ocks.org/monfera/9c5efcfa26e202f5653c692a6d3ba7fa'>Brownian motion with D3 4.0 velocity Verlet physics</a>
forked from <a href='http://bl.ocks.org/monfera/'>monfera</a>'s block: <a href='http://bl.ocks.org/monfera/ffa2a4fdacbb7c7b1c1ad34337fb8086'>Collision test with D3 4.0</a>