Flocking (Boids)
Emergence in action. Complex group behavior arises from three simple rules: Separation, Alignment, and Cohesion.
Craig Reynoldsβ Boids Algorithm (1987)
Craig Reynolds’ Boids Algorithm (1987)
Craig Reynolds discovered in 1987 that realistic flocking behaviour in birds, fish, and other social animals emerges from just three simple local rules, each agent following only what it can sense within its visual range — no central coordinator required:
- Separation: steer away from nearby neighbours to avoid collision
- Alignment: steer towards the average heading of nearby neighbours
- Cohesion: steer towards the average position (centre of mass) of nearby neighbours
Reynolds called these simulated creatures “boids” (bird-oids). The paper, published at SIGGRAPH 1987, is one of the most cited in computer graphics and was the first formal model of self-organised collective motion.
The Mathematics of Flocking
Each boid updates its velocity vector each frame by combining three force components with adjustable weights:
- Fsep = ∑j (posi − posj) / |posi − posj|² for all j within separation radius
- Falign = mean(velj) for all j in alignment radius − veli
- Fcohesion = mean(posj) for all j in cohesion radius − posi
The final velocity update is vnew = vold + wsFsep + waFalign + wcFcohesion, then clamped to maximum speed. Try adjusting the weights in real time to see how they affect flock behaviour.
Swarm Intelligence in Technology
The principles behind boids underpin entire fields of technology and science:
- Drone swarms — military and commercial drone formations use boid-like coordination
- Robotics — swarm robots for search-and-rescue, mapping unknown environments
- Animation & VFX — Reynolds’ algorithm is standard in film and game crowd simulation
- Ant colony optimisation — an AI metaheuristic modelled on ant foraging behaviour
- Particle swarm optimisation — a flocking-inspired algorithm for numerical optimisation
- Traffic modelling — collective vehicle behaviour modelled as continuous flocks
Experiments to Try
- Maximise cohesion, minimise separation — the flock should merge into a tight cluster.
- Maximise separation only — boids should scatter uniformly.
- All three at medium values — observe classic murmuration-like behaviour.
- Add many boids (200+) — observe the transition from small-group dynamics to large-flock emergent waves.
- Narrow the visual field — simulate blind-spot biology; observe how flock cohesion degrades.
Key Equations
| Rule | Vector Update | Notes |
|---|---|---|
| Separation | Fsep = ∑ (ri − rj) / |ri − rj|² | Sum over all neighbours j within separation radius |
| Alignment | Falign = 〈vj〉 − vi | Steer towards mean velocity of nearby neighbours |
| Cohesion | Fcoh = 〈rj〉 − ri | Steer towards centre of mass of nearby neighbours |
| Velocity update | v′ = v + wsFsep + waFalign + wcFcoh | Weights w control relative strength of each rule |
| Speed clamping | v = v × vmax / |v| | Prevents unlimited acceleration; mimics biological limits |
| Order parameter | φ = |∑ vj| / (Nvmax) | φ = 0 (disorder) to 1 (perfect alignment); measures flock coherence |
Curriculum Links
| Level | Topics |
|---|---|
| GCSE Biology | Animal behaviour, predator–prey dynamics, group living advantages |
| A-Level Biology | Collective behaviour, evolutionary advantages of flocking |
| A-Level Computing | Agent-based modelling, emergence, simulation design |
| University (Computer Science) | Swarm intelligence, multi-agent systems, distributed AI |
| University (Physics) | Statistical mechanics of active matter, non-equilibrium systems |
| Postgraduate | Active matter physics, flocking phase transitions, Vicsek model |
🔒 Unlock All 32 Simulations
Get unlimited access to all 32 interactive simulations including Flocking Boids, Evolution Simulator, Fluid Dynamics, Lorenz Attractor, and more with MySimulator Premium.
View Premium PlansShare this simulation
Send this page to students or colleagues.
Related simulations
Continue with similar experiments.
π Recommended Reading
Deepen your understanding with our in-depth articles.