예제 #1
0
        /// <a href="http://bit.ly/2Oq9xlg">Give a starting coordinate, a distance and a direction, calculate and return a destination coordinate.</a>
        public static Coordinates Destination(Coordinates start, double distanceKm, double bearingDegrees)
        {
            start = start.ToRadians();
            var bearingRadians   = Trig.ToRadians(bearingDegrees);
            var deltaDistance    = distanceKm / EarthMeanRadiusKm;
            var sinDeltaDistance = Math.Sin(deltaDistance);
            var cosDeltaDistance = Math.Cos(deltaDistance);
            var sinStartLatitude = Math.Sin(start.Latitude);
            var cosStartLatitude = Math.Cos(start.Latitude);

            var latitude = Math.Asin(
                (sinStartLatitude * cosDeltaDistance) +
                cosStartLatitude * sinDeltaDistance * Math.Cos(bearingRadians));

            var longitude = start.Longitude + Math.Atan2(
                Math.Sin(bearingRadians) * sinDeltaDistance * cosStartLatitude,
                cosDeltaDistance - sinStartLatitude * Math.Sin(latitude));

            return(Coords(latitude, longitude, radians: true));
        }
예제 #2
0
 /// <a href="http://bit.ly/2Oq9qpQ">Convert to degrees if needed.</a>
 public Coordinates ToDegrees() =>
 Radians?Coords(Trig.ToDegrees(Latitude), Trig.ToDegrees(Longitude), true) : this;
예제 #3
0
 /// <a href="http://bit.ly/2Oq9qpQ">Convert to radians if needed</a>
 public Coordinates ToRadians() =>
 Radians ? this : Coords(Trig.ToRadians(Latitude), Trig.ToRadians(Longitude), true);
예제 #4
0
 /// <a href="http://bit.ly/2Oq9oOK">Return the bearing in degrees to get from one point to another.</a>
 public static double BearingDegrees(Coordinates from, Coordinates to) => Trig.ToDegrees(BearingRadians(from, to));