Pick a scenario; every slider stays editable.
Logarithmic bars. Same positions, same true contacts; only the number of pairs that must be examined differs.
The 40 left-most spheres sorted by x. Each bar is the sphere's x-interval; bars that overlap another bar are the candidate pairs (before the y and z test).
The science
Why a broad phase? Testing every pair of N bodies costs N(N-1)/2 sphere tests per step, which grows as N². Most pairs are far apart, so a cheap broad phase first discards them and only the surviving candidate pairs reach the exact narrow phase (|xj-xi|² < (2r)²). The result (the set of touching pairs) must be identical for every method; only the work differs.
Uniform grid. Space is cut into cubes of edge h ≥ 2r. A sphere only needs to be compared with spheres in its own and the 26 neighbouring cells; the lab visits the own cell plus the 13 forward neighbours so that each pair appears once. With density ρ = N/V a cell holds about ρh³ spheres, so the cost is ~ N · 14 ρ h³/2: linear in N at a fixed density. In a fixed box the density itself grows with N, so every method becomes quadratic and only the constant factor (about V/(28h³) for the grid) helps - the scaling sweep shows both cases. If h is much larger than 2r a cell holds too many spheres; if h < 2r the neighbour rule is no longer correct (the slider never goes below 2r).
Sweep and prune. Sort the spheres by their x coordinate (an insertion sort is almost linear because the order barely changes between steps - temporal coherence), then for each sphere scan forward only while xj - xi ≤ 2r, and keep the pair if the y and z boxes also overlap. Expected cost ~ N log N or less for the sort plus the number of x-overlapping pairs, which scales like N² r / L, so between linear and quadratic.
Expected number of touching pairs. For N centres uniform in a cube of side a = L - 2r the probability that two are closer than d = 2r is (4π/3)t³ - (3π/2)t&sup4; + O(t&sup5;) with t = d/a, so the mean contact count is N(N-1)/2 times that. The page compares it with a Monte Carlo average.
Response. Equal masses, normal impulse J = -(1+e)(vrel·n)/2 per unit mass. For e = 1 kinetic energy is conserved (checked), for a head-on pair the velocities swap, and the separation speed is e times the approach speed.
Honest simplifications. Spheres do not spin and there is no friction; contacts are resolved one pair at a time in sequence (no simultaneous solver), so a dense pile with gravity is only approximately physical. Timings are measured with performance.now() in JavaScript on your device: they depend on the browser, JIT warm-up and cache effects, so use the pair-test counts (exact) as the reliable comparison and the milliseconds as an indication. Real engines also use bounding-volume trees and persistent contact manifolds.