예제 #1
0
        /// <summary>
        /// calculate the angle from the location to the "centre" of the racetrack
        /// </summary>
        /// <param name="location">location on the racetrack</param>
        /// <returns></returns>
        public double GetAngleToCentre(JLocation location)
        {
            if (location is null)
            {
                throw new ArgumentNullException(nameof(location));
            }

            double latDelta = location.Lat - Centre.Lat;
            double lonDelta = location.Lon - Centre.Lon;

            return(Math.Atan2(latDelta, lonDelta) * (180 / Math.PI));
        }
예제 #2
0
        /// <summary>
        /// Calculates the angle to a location taking into account a bendy bit of the track
        /// where all locations are adjusted to be equal
        /// </summary>
        /// <param name="location">the location</param>
        /// <returns>the angle to the location, adjusted if necessary for bendy bits of the track</returns>
        internal double GetAngleForPosition(JLocation location)
        {
            double angle = GetAngleToCentre(location);

            if (BendyBit[0] < angle && angle < BendyBit[1])
            {
                // position by angle is unreliable in the bendy bit of the track
                // so use the angle to the start for all cars on the bend(s)
                angle = BendyBit[0];
            }
            return(angle);
        }
예제 #3
0
 private RaceTrack(string name, JLocation centre, JLocation startFinish, JLocation[] bendyBit)
 {
     Name   = name;
     Centre = centre;
     // convert all other locations to angles relative to the centre
     BendyBit = new double[bendyBit.Length];
     for (int i = 0; i < bendyBit.Length; i++)
     {
         BendyBit[i] = GetAngleToCentre(bendyBit[i]);
     }
     StartFinishAngle = GetAngleToCentre(startFinish);
 }
예제 #4
0
 /// <summary>
 /// copy constructor
 /// </summary>
 /// <param name="location">location value</param>
 public JLocation(JLocation location)
     : this(location.Lat, location.Lon)
 {
 }