HomeAlgorithms & AISpatial Hash Grid: Broad-Phase Collision Indexing

Spatial Hash Grid: Broad-Phase Collision Indexing

Watch a uniform spatial-hash grid index thousands of moving spheres so collision detection runs near O(n) instead of O(n²) brute force — toggle methods and watch the comparison counter live.

Algorithms & AI3DModerate60 FPS📱 Mobile-adapted⇄ 2D version
indexx ↗ Open standalone

Hundreds of spheres bounce inside a box while the simulation indexes their positions into a uniform 3D grid every frame, so collision checks only ever look at the 27 cells around each particle instead of every other particle in the scene. A live counter tracks exactly how many distance checks the indexed grid performs versus how many brute-force O(n²) comparison would need at the same particle count, and a method switch lets you run true brute force to watch frame time and the comparison counter both spike as particle count grows — a direct, moving picture of why every serious physics engine, spatial database and collision system indexes its objects instead of scanning them all.

⚙ Under the hood

Hundreds of bouncing spheres are indexed into a uniform 3D grid every frame so collision detection runs near O(n) instead of O(n²) brute force — switch methods live and watch the comparison counter diverge.

spatial hashingcollision detectiondata structuresindexingalgorithmsbroad-phase

3D · Three.js / WebGL renderer · 60 FPS target · runs fully client-side, no install

What did you find?

Add reproduction steps (optional)