Skip to content

Spatial Hashing for Boids

March 2024

Uniform grid spatial hashing to speed up neighbor searches in boids simulation. Without hashing, finding neighbors for each boid is O(n2)O(n^2). With spatial hashing, it drops to roughly O(n)O(n) by only checking nearby cells.

Try adding more boids with the + key and see when it starts to stutter. Toggle hashing on/off with H to feel the difference.

Loading...

Controls:

  • H: Toggle spatial hashing
  • V: Visualize the hash grid
  • +: Add 500 boids
  • -: Remove 500 boids