Keegan Atchison

Work About Simulation

Starling Murmuration. November 2024, Florence, Italy

I was in Florence for the day, on vacation from WASP 3D to see the city’s ceramists, and was transfixed by the motion above. I followed these small starlings to a square and stared for hours. They moved with such coordination, creating fleeting organic shapes only to disperse then fold back together. When the birds twist to expose their sides, their form appears; but, as they turn to point away or toward the camera, they seem to disappear.

I wanted to capture the beauty I observed. The following algorithm is derived from past work by Craig Reynolds and V. Hunter Adams.


Modeling Parameters

Microneedle project image MN3 Microneedle project image MN4

The algorithm considers individual boid (named after bird-oid object) movement to model the flock’s behavior. We will consider one boid (orange), its immediate neighbors (red), its further neighbors that it can see (blue). The other birds (purple) are outside the boid’s visual range.

The simulation balances social dynamics with environmental constraints using the following factors:

  • Centering: The centering factor pulls boids toward the flock's center of mass (pink). The boid's direction is corrected to align with the flock's movement.
  • Avoidance: When the boid is too close to other birds (red), an avoidance range prevents collision.
  • Visual Range: Boids can only see so far, the visual range sets the area a bird can perceive.
  • Velocity Matching: The matching factor synchronizes a boid’s heading with its neighbors, creating unified flow.
  • Scout Hierarchy: 10% of the flock is assigned with bias toward the left or right screen edges, simulating food or shelter.

Mathematical Work

Distance Optimization

To avoid costly square root operations, neighborhood detection relies on squared Euclidean distance: $$dist^2 = \Delta x^2 + \Delta y^2$$

The Steering Sum

For every boid $i$, the velocity $\vec{v}$ is updated by summing the primary steering vectors:

  • Cohesion: $\vec{v} += (\text{AvgPos}_{neighbors} - \text{Pos}_i) \times \text{centering factor}$
  • Alignment: $\vec{v} += (\text{AvgVel}_{neighbors} - \vec{v}_i) \times \text{matching factor}$
  • Separation: $\vec{v} += \sum (\text{Pos}_i - \text{Pos}_{neighbors}) \times \text{avoid factor}$

Scout Bias (Lerp)

Scouts utilize linear interpolation to steer horizontal velocity ($v_x$) toward a goal ($G$) based on their increasing biasVal: $$v_{x\_new} = (1 - \text{bias}) \cdot v_x + \text{bias} \cdot G$$

Boundary Steering

A penalty method applies steering forces proportional to the depth of penetration into the screen margins: $$\text{Force} = \text{turnFactor} \times \left( \frac{\text{depth}}{\text{margin}} \right) \times 5$$

Note: I used html, javascript, & CSS; all code was developed by myself + AI collaboration.