Dot product of the velocity vector of the boid and perpendicular to the
boundary is computed. If the dot product is positive, the boid is
moving towards it and vice versa. For approaching boids, the angle between the velocity vector and the boundary is computed. The boid is steered (rotated) by a small fraction of this angle. This ensures that the boid will smoothly move away from the boundary. It is important to determine the direction in which the boid should be steered away. To determine if the boid should be steered away in positive angle or negative angle, I use the cross product of the velocity vector and the boundary. |
The obstacles are modelled by their circle of influence. To avoid an
obstacle, I first determine if the boid will collide with it if it
continues to move in its current direction. To do this, I compute two angles. Angle
a, which is the angle between the velocity and the vector joining the
boid to the center of the obstacles. Angle b is the angle between the
tangent to the circle from the boid and the vector joining the boid to
the obstacles center. If ( angle a < angle b ), the boid will collide with the obstacle. So I steer the boid away from the obstacle by some angle to avoid the collision. |