Beispiel #1
0
        /// <summary>
        /// Compute the longitudinal acceleration of a car in a lane, based on the IDM
        /// </summary>
        /// <param name="car">Car to compute acceleration of</param>
        /// <param name="carInFront">Car in front of the current car, may be null if current car is the leader</param>
        /// <param name="lane">Lane the two cars are in</param>
        /// <returns></returns>
        private static float AccelerationOfCarInLane(Vehicle car, Vehicle carInFront, Lane lane)
        {
            if (car == null)
            {
                return(0);
            }
            LeaderVehicleInfo leaderCarInfo    = lane.ComputeLeaderCarInfo(car, carInFront);
            Vector2           trafficDirection = lane.Path.TangentOfProjectedPosition(car.Position);
            Vector2           acc = IntelligentDriverModel.ComputeAccelerationIntensity(
                car,
                trafficDirection,
                leaderCarInfo.DistToNextCar,
                leaderCarInfo.ApproachingRate
                );

            // Acceleration in direction of traffic (can be negaitve, -> vehicle will have to brake)
            return(Vector2.Dot(acc, trafficDirection));
        }