Esempio n. 1
0
        /// <summary>
        /// Возвращает растояние между двумя географическими точками
        /// </summary>
        /// <param name="point1">Первая точка(начало отсчета)</param>
        /// <param name="point2">Вторая точка(окончание отсчета)</param>
        /// <returns>Растояние между двумя географическими точками</returns>
        /// <remarks>
        /// Используется расчет предоставленный  http://www.meridianworlddata.com/Distance-Calculation.asp
        /// Формула расчета x = EarthRadius * arctan[sqrt(1-x^2)/x], где
        /// EarthRadius - радиус Земли
        /// х = x = [sin(lat1/57.2958) * sin(lat2/57.2958)] +
        /// +[cos(lat1/57.2958) * cos(lat2/57.2958) * cos(lon2/57.2958 - lon1/57.2958)]
        /// </remarks>
        private static double GetDistanceFromPoints(IRoutePoint point1, IRoutePoint point2)
        {
            var dLat1InRad  = point1.Position.Lat * (Math.PI / 180.0);
            var dLong1InRad = point1.Position.Lon * (Math.PI / 180.0);
            var dLat2InRad  = point2.Position.Lat * (Math.PI / 180.0);
            var dLong2InRad = point2.Position.Lon * (Math.PI / 180.0);
            var dLongitude  = dLong2InRad - dLong1InRad;
            var dLatitude   = dLat2InRad - dLat1InRad;
            var x           = Math.Pow(Math.Sin(dLatitude / 2.0), 2.0) +
                              Math.Cos(dLat1InRad) * Math.Cos(dLat2InRad) *
                              Math.Pow(Math.Sin(dLongitude / 2.0), 2.0);
            var dist = 2.0 * Math.Atan2(Math.Sqrt(x), Math.Sqrt(1.0 - x));

            return(EarthRadius * dist);
        }
Esempio n. 2
0
        // :Helper functions
        // Calculate distance between 2 points.
        // Returns in unit 'km'.
        // Source for Haversine formula used: http://stackoverflow.com/questions/27928/how-do-i-calculate-distance-between-two-latitude-longitude-points/27943#27943
        private double DistancePointToPoint(IRoutePoint start, IRoutePoint end)
        {
            var R    = 6371; // Radius of the earth in km
            var dLat = DegreesToRadian(end.Latitude - start.Latitude);
            var dLon = DegreesToRadian(end.Longitude - start.Longitude);
            var a    =
                Math.Sin(dLat / 2) * Math.Sin(dLat / 2) +
                Math.Cos(DegreesToRadian(start.Latitude)) * Math.Sin(DegreesToRadian(end.Latitude)) *
                Math.Sin(dLon / 2) * Math.Sin(dLon / 2)
            ;
            var c = 2 * Math.Atan2(Math.Sqrt(a), Math.Sqrt(1 - a));
            var d = R * c; // Distance in km

            return(d);
        }
Esempio n. 3
0
 // :Helper functions
 // Calculate distance between 2 points.
 // Returns in unit 'km'.
 // Source for Haversine formula used: http://stackoverflow.com/questions/27928/how-do-i-calculate-distance-between-two-latitude-longitude-points/27943#27943
 private double DistancePointToPoint(IRoutePoint start, IRoutePoint end)
 {
     var R = 6371; // Radius of the earth in km
     var dLat = DegreesToRadian(end.Latitude - start.Latitude);
     var dLon = DegreesToRadian(end.Longitude - start.Longitude);
     var a =
       Math.Sin(dLat / 2) * Math.Sin(dLat / 2) +
       Math.Cos(DegreesToRadian(start.Latitude)) * Math.Sin(DegreesToRadian(end.Latitude)) *
       Math.Sin(dLon / 2) * Math.Sin(dLon / 2)
       ;
     var c = 2 * Math.Atan2(Math.Sqrt(a), Math.Sqrt(1 - a));
     var d = R * c; // Distance in km
     return d;
 }