🚶♂️🚶♀️ 2D Pedestrian Flow
Top-down Social Force Model of two pedestrian streams walking opposite directions through a corridor. Watch spontaneous lane formation emerge purely from repulsive and driving forces — no scripted rules.
🚶♂️🚶♀️ 2D Pedestrian Flow — Bidirectional Lane Formation
A top-down Social Force Model of two pedestrian streams crossing a corridor in opposite directions. No agent is told to avoid the oncoming crowd by forming a lane — lanes emerge purely from the sum of driving and repulsive forces acting on every pedestrian, frame by frame.
🔬 What It Demonstrates
Each pedestrian is a self-driven particle: a driving force pulls it at constant desired speed along its travel direction, an exponentially decaying force repels it from every nearby pedestrian, and another repels it from the corridor walls and an optional pillar. Summed and integrated every frame, these forces alone are enough for the crowd to spontaneously segregate into alternating same-direction lanes — a hallmark self-organization result from Helbing's Social Force Model, distinct from the single-exit evacuation scenario in the companion 3D simulation.
🎮 How to Use
Set how many pedestrians walk each direction and how wide the corridor is, then watch the lane index climb from around 0.5 (fully mixed) toward 1.0 as blue (rightward) and orange (leftward) walkers separate into bands. Add a pillar mid-corridor to see how a single obstacle reshapes the lane pattern around it.
💡 Did You Know?
Lane formation in bidirectional pedestrian traffic was one of the first "self-organization phenomena" Dirk Helbing used to validate the Social Force Model in the 1990s — it requires no communication or rule-following between pedestrians, only local physical avoidance.
About this bidirectional Social Force Model
This simulation places two pedestrian streams — one travelling right, one travelling left — into a shared corridor and evolves them under the same Social Force Model that Dirk Helbing and Peter Molnar proposed in 1995: every agent sums a driving force toward its own desired velocity, an exponentially decaying repulsion from every nearby pedestrian, and a repulsion from the corridor walls, then integrates the result into acceleration, velocity, and position each frame. Unlike a single-exit evacuation, this corridor has no doorway to funnel agents through and no finish line — it models a continuous, steady-state flow, so agents leaving one end re-enter at the other.
The "Per side" slider sets how many pedestrians travel in each direction (10 to 70) and "Corridor width" sets how much vertical space they share (90 to 260 pixels). At low density the two streams pass through with little structure; as density rises, the repulsive forces alone are enough to sort same-direction walkers into alternating lanes, measured live by the lane index in the info bar. Adding a pillar drops a static circular obstacle into the middle of the corridor, which locally disrupts the lanes and forces pedestrians on both sides to renegotiate the shared space.
Frequently Asked Questions
What makes this different from the 3D Pedestrian Flow simulation?
The 3D companion models single-direction evacuation through one narrow exit, where the interesting phenomenon is arch-shaped clogging under panic. This 2D simulation instead models two crowds walking opposite directions through an open corridor with no exit — the interesting phenomenon here is spontaneous lane formation, a completely different emergent pattern from the same underlying Social Force Model.
How does lane formation happen without any lane-following rule?
No agent is told to form a lane. Each pedestrian only feels a forward driving force and short-range repulsion from nearby pedestrians and walls. When an oncoming pedestrian gets close, the repulsive force nudges both sideways in whichever direction is already less crowded. Repeated over many pedestrians and many frames, these purely local nudges snowball into stable, alternating bands of same-direction walkers.
What does the lane index measure?
For every pedestrian, the simulation looks at neighbours within a short radius and computes what fraction of them are travelling the same direction, then averages this across the whole crowd. A value near 0.5 means directions are fully mixed with no structure; a value approaching 1.0 means pedestrians are almost always surrounded by others going the same way — a clear, measurable sign that lanes have formed.
What do the two sliders control?
"Per side" sets the number of pedestrians walking in each direction, from 10 up to 70, directly controlling crowd density. "Corridor width" sets the vertical space available, from 90 to 260 pixels. Narrower corridors at higher counts push density up quickly, which is the condition under which lanes form fastest and most cleanly.
What happens when you add the pillar?
The pillar is a static circular obstacle that exerts the same kind of exponentially decaying repulsive force as a wall. Pedestrians route around it individually, which locally breaks up whatever lane pattern had formed nearby. Downstream of the pillar the lanes typically re-form, similar to how a real support column in a train station reshapes local foot traffic without stopping the overall flow.
Why do agents wrap around instead of leaving the corridor?
This simulation models a continuous, steady-state flow rather than a one-time evacuation, so when a pedestrian reaches the far end of the corridor they reappear at the opposite end, still travelling the same direction. This periodic boundary keeps the density constant over time, which is what lets a stable lane pattern persist indefinitely instead of draining away.
What are the model's exact parameters?
The simulation uses a desired speed of 1.35 pixels per frame, a relaxation time of 30 frames, a pedestrian-pedestrian repulsion magnitude of 0.85 with an 11-pixel decay length, a wall repulsion magnitude of 0.6 with a 9-pixel decay length, and a pillar repulsion magnitude of 1.0 with a 12-pixel decay length. Overlapping pedestrians also receive an extra linear contact push proportional to how much they overlap.
Is lane formation a real, observed phenomenon?
Yes. Lane formation in bidirectional pedestrian traffic has been documented in real corridors, train station concourses, and controlled experiments, and it is one of the classic validation results researchers use to check that a crowd model behaves realistically. It is also visible in ant trails and some vehicle traffic contexts, making it a widely cited example of self-organization from purely local interactions.
Is this simulation physically accurate?
It reproduces the qualitative Social Force Model mechanics — driving force, exponential pedestrian repulsion, and wall repulsion — and the lane-formation pattern that mechanism is known to produce. As with the 3D companion, constants are tuned in pixel units for a clear, responsive demonstration rather than calibrated to metric measurements, so treat it as an educational illustration rather than a certified crowd-engineering tool.
Top-down Social Force Model of two pedestrian streams crossing a corridor in opposite directions. Driving forces, exponentially decaying pedestrian repulsion, and wall repulsion alone are enough for the crowd to spontaneously self-organize into alternating lanes — watch the live lane index climb as density rises, and drop a pillar mid-corridor to disrupt the pattern.
2D · HTML5 Canvas 2D · 60 FPS target · runs fully client-side, no install