示例#1
0
        public static ILocation MoveTowards(this ILocation a, ILocation b, float distance)
        {
            float slope   = (a.Top - b.Top) / (a.Left - b.Left);
            bool  forward = a.Left <= b.Left;
            bool  up      = a.Top <= b.Top;

            float  abDistance = a.CalculateDistanceTo(b);
            double angle      = Math.Asin(Math.Abs(b.Top - a.Top) / abDistance);
            float  dy         = (float)Math.Abs(distance * Math.Sin(angle));
            float  dx         = (float)Math.Sqrt((distance * distance) - (dy * dy));

            float x2 = forward ? a.Left + dx : a.Left - dx;
            float y2 = up ? a.Top + dy : a.Top - dy;

            var ret = Location.Create(x2, y2);

            return(ret);
        }
示例#2
0
 public static double CalculateDistanceTo(this ILocation locationFrom, ILocation locationTo)
 {
     return(locationFrom.CalculateDistanceTo(locationTo.Latitude, locationTo.Longitude));
 }