Example #1
0
        public static double Bearing(GeoPoint first, GeoPoint second)
        {
            //var y = Math.sin(λ2 - λ1) * Math.cos(φ2);
            //var x = Math.cos(φ1) * Math.sin(φ2) -
            //        Math.sin(φ1) * Math.cos(φ2) * Math.cos(λ2 - λ1);
            //var brng = Math.atan2(y, x).toDegrees();

            var deltaLat = ArgumentUtils.ToRadians(second.Latitude - first.Latitude);
            var deltaLon = ArgumentUtils.ToRadians(second.Longitude - first.Longitude);
            var lat1     = ArgumentUtils.ToRadians(first.Latitude);
            var lat2     = ArgumentUtils.ToRadians(second.Latitude);

            var y = Math.Sin(deltaLon) * Math.Cos(lat2);
            var x = Math.Cos(lat1) * Math.Sin(lat2)
                    - Math.Sin(lat1) * Math.Cos(lat2) * Math.Cos(deltaLat);

            return(ArgumentUtils.ToDegrees(Math.Atan2(y, x)));
        }
        private static double ToLat(double y, int zoomLevel)
        {
            var zoomFactor = K * Math.Pow(2, zoomLevel);

            return(ArgumentUtils.ToDegrees(2 * (Math.Atan(Math.Exp(Math.PI - y / zoomFactor)) - Math.PI / 4)));
        }
        private static double ToLon(double x, int zoomLevel)
        {
            var zoomFactor = K * Math.Pow(2, zoomLevel);

            return(ArgumentUtils.ToDegrees(x / zoomFactor - Math.PI));
        }