📜  将点移向另一点 - 无论代码示例

📅  最后修改于: 2022-03-11 14:58:52.332000             🧑  作者: Mango

代码示例1
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);
}