Example #1
0
        /// <summary>
        /// Calculates a position on the line between source and target.
        /// e.g. distance 0 would be the position of target, 100 would be
        /// 100 points farther away from source.
        /// </summary>
        public static MabiVertex CalculatePosOnLine(MabiVertex source, MabiVertex target, int distance)
        {
            if (source.Equals(target))
                return new MabiVertex(source.X + 1, source.Y + 1);

            var deltaX = (double)target.X - source.X;
            var deltaY = (double)target.Y - source.Y;

            var deltaXY = Math.Sqrt(Math.Pow(deltaX, 2) + Math.Pow(deltaY, 2));

            var newX = target.X + (distance / deltaXY) * (deltaX);
            var newY = target.Y + (distance / deltaXY) * (deltaY);

            return new MabiVertex((uint)newX, (uint)newY);
        }