コード例 #1
0
        /// <summary>
        /// Compute the compass direction between two points using the starting bearing as the direction
        /// </summary>
        /// <param name="fromX">source X ordinate</param>
        /// <param name="fromY">source Y ordinate</param>
        /// <param name="toX">destination X ordinate</param>
        /// <param name="toY">destination Y ordinate</param>
        /// <returns>The compass direction from a to b</returns>
        public double DirectionStartBearing(double fromX, double fromY, double toX, double toY)
        {
            fromX = AngleUtils.ToRadians(fromX);
            fromY = AngleUtils.ToRadians(fromY);
            toX   = AngleUtils.ToRadians(toX);
            toY   = AngleUtils.ToRadians(toY);
            double dLon = toX - fromX;
            double y    = Math.Sin(dLon) * Math.Cos(toY);
            double x    = Math.Cos(fromY) * Math.Sin(toY) - Math.Sin(fromY) * Math.Cos(toY) * Math.Cos(dLon);

            return(AngleUtils.ToDegrees(Math.Atan2(y, x)));
        }
コード例 #2
0
        /// <summary>
        /// Compute the compass direction between two points using the Mid-point of the path as the direction
        /// </summary>
        /// <param name="fromX">source X ordinate</param>
        /// <param name="fromY">source Y ordinate</param>
        /// <param name="toX">destination X ordinate</param>
        /// <param name="toY">destination Y ordinate</param>
        /// <returns>The compass direction from a to b</returns>
        public double DirectionMidBearing(double fromX, double fromY, double toX, double toY)
        {
            fromX = AngleUtils.ToRadians(fromX);
            fromY = AngleUtils.ToRadians(fromY);
            toX   = AngleUtils.ToRadians(toX);
            toY   = AngleUtils.ToRadians(toY);
            double dLon = toX - fromX;
            var    Bx   = Math.Cos(toY) * Math.Cos(dLon);
            var    By   = Math.Cos(toY) * Math.Sin(dLon);
            var    lat3 = AngleUtils.ToDegrees(Math.Atan2(Math.Sin(fromY) + Math.Sin(toY), Math.Sqrt((Math.Cos(fromY) + Bx) * (Math.Cos(fromY) + Bx) + By * By)));
            var    lon3 = AngleUtils.ToDegrees(fromX + Math.Atan2(By, Math.Cos(fromY) + Bx));

            return(DirectionStartBearing(lon3, lat3, toX, toY));
        }