/// <summary> /// Executes the pursuit behavior. /// </summary> /// <param name="quarry">The car that should be pursuited.</param> /// <returns>The pursuit steering force.</returns> private Vector2 Pursuit(Car quarry) { Vector2 distance = quarry.GPSPosition - this.GPSPosition; //t is predicted time until interception. float t = distance.Length() / (this.Velocity - quarry.Velocity).Length(); //Seek predicted position. return Seek(AutonomousCar.PredictFuturePosition(quarry, t)); }
/// <summary> /// Executes the leader following behavior. /// </summary> /// <param name="leader">The car that is designated as leader.</param> /// <returns>The leader following steering force.</returns> private Vector2 FollowLeader(Car leader) { float distanceOffset = this.CollisionDist; return Arrive(leader.GPSPosition - distanceOffset * leader.Velocity); }
/// <summary> /// Executes the interpose behavior. /// </summary> /// <param name="car1">The first car.</param> /// <param name="car2">The second car.</param> /// <returns>The interpose steering force.</returns> private Vector2 Interpose(Car car1, Car car2) { float distance = (((car1.GPSPosition + car2.GPSPosition) / 2) - this.GPSPosition).Length(); float T = distance / this.Velocity.Length(); Vector2 desiredPosition = (PredictFuturePosition(car1, T) + PredictFuturePosition(car2, T)) / 2; return Seek(desiredPosition); }
/// <summary> /// Predicts the position of the specified car after the specified time. /// </summary> /// <param name="car">The car of which the position should be predicted.</param> /// <param name="t">The point in time at which the position should be predicted, in seconds.</param> /// <returns>The predicted future position.</returns> private static Vector2 PredictFuturePosition(Car car, float t) { return car.GPSPosition + car.Velocity * t; }