The distance test
Give each object a collision radius and the test is almost embarrassingly simple: two circles touch exactly when the distance between their centres is less than the sum of their radii. Grow one circle's radius by the other's and the question becomes "is that centre inside this ring?" — a single distance, one comparison.
Drag the circles together and apart.
Normal and penetration
Knowing they overlap isn't enough; a solver needs to know which way and how much. Both fall out of the same line of centres: the contact normal is the unit vector along it, and the penetration depth is how much the radii overlap, r₁+r₂ − d. That's the whole contact — a direction to separate and a distance to travel.
Overlap the circles and watch the normal and depth.
Pushing them apart
Now do something about it. Move each overlapping pair back along the normal by the penetration — split between them so the lighter one moves more — and the overlap vanishes. Apply it to every pair, a few times over, and a jammed heap relaxes until nothing intersects. This positional fix is the backbone of packing, granular piles, and stable stacks.
Drag one into the others, or scatter them and watch them separate.
Not checking everyone
Testing every pair is O(n²) — a hundred objects is five thousand tests, a thousand is half a million. The fix is a broad phase: drop objects into a grid of cells sized to the largest one, and only test neighbours sharing a cell or an adjacent one. Distant objects are never compared at all, so the real work collapses to a tiny fraction — and it never misses a genuine contact.
Add objects and watch the two counts diverge.
The collision playground
Everything together: a box of bodies falling, colliding, transferring momentum and separating — all detected through the grid, so the check counter stays low even as the crowd grows. Drop an obstacle in the middle, tune the count, size and bounce, and turn on the grid to see the broad phase at work. This is the engine under packing, granular flow, and any crowd of solid things.