Answers for "move point towards other point"

0

move point towards other point

public Point MovePointTowards(Point a, Point b, double distance)
{
    var vector = new Point(b.X - a.X, b.Y - a.Y);
    var length = Math.Sqrt(vector.X * vector.X + vector.Y * vector.Y);
    var unitVector = new Point(vector.X / length, vector.Y / length);
    return new Point(a.X + unitVector.X * distance, a.Y + unitVector.Y * distance);
}
Posted by: Guest on May-19-2021

Browse Popular Code Answers by Language