-
Notifications
You must be signed in to change notification settings - Fork 7
Open
Description
Hi,
I've found an error in the Boids pseudocode.
In the algorithm you have:
if (squared_distance < protected_range_squared):
# If so, calculate difference in x/y-coordinates to nearfield boid
close_dx += boid.x - otherboid.x
close_dy += boid.y - otherboid.y
...then later
# Add the avoidance contribution to velocity
boid.vx = boid.vx + (close_dx*avoidfactor)
boid.vy = boid.vy + (close_dy*avoidfactor)
The trouble with this is that the "repulsion force" represented by close_dx*avoidfactor decreases as the boids get closer together. In particular the repulsion force has value protected_range*avoidfactor when the boids are protected_range apart which then decreases down to zero when the distance between the boids is zero.
We want it to be the other way around, that is we want the repulsion force to be zero when the distance between the boids is protected_range (or greater), and have the repulsion force increase up to value protected_range*avoidfactor when the distance between the boids is zero.
So the pseudocode becomes something like:
turnX = (close_dx<=0) ? - proteced_range - close_dx : proteced_range - close_dx
turnY = (close_dy<=0) ? - proteced_range - close_dy : proteced_range - close_dy
...then later
boid.vx = boid.vx + (turnX*avoidfactor)
boid.vx = boid.vx + (turnY*avoidfactor)
Metadata
Metadata
Assignees
Labels
No labels