Python Boids with Spatial Hashing

Описание к видео Python Boids with Spatial Hashing

An implementation of the boids algorithm I've been working on as I learn to code.

https://www.red3d.com/cwr/boids/

Each boid scans it's neighbours and makes three calculations:
Separation: steers away from nearby boids so it doesn't crash into them
Alignment: each boids tries to slign with the nearby population
Cohesion: finds the centre of the nearby population

These three forces are combined into a single vector which is used to steer each boid. Every boid has to scan the entire population of boids, so the complexity of each frame increases as more boids are added. Spatial hashing is used to break the population up into smaller chunks. In this case, the screen is broken up into 100 by 100 squares, each square has it's own list. When a boid enters a square it only has to calculate for the other boids in the same square.

Комментарии

Информация по комментариям в разработке