与起点相比,终点是否更接近任意点 x%

Whether the end-point is x% closer to an arbitrary point when compared to the start-point

我有三个坐标位置 A(x1, y1)、B(x2, y2) 和 C(x3, y3)。 A为起始位置,B为结束位置,C为任意坐标位置。现在我想计算与起始位置 (A) 相比,结束位置 (B) 是否至少更接近点位置 (C) 25%。

有人可以为这个问题编写伪代码吗?

假设您使用某种浮点数:

distance_to_a := dist(A, B)
distance_to_c := dist(C, B)

if distance_to_c <= 0.75 * distance_to_a:
    output "C at least 25% closer"
else:
    output "C not at least 25% closer"

现在假设你想使用欧氏距离,定义如下:

def dist(A: Point, B: Point):
    return sqrt((A.x-B.x)^2 + (A.y-B.y)^2)

这是简单的向量几何:

A​​到B的平方距离d2为(Ax - Bx)^2 + (Ay - By)^2

所以 B 到 C 比 A 到 C 少 25% 如果:

sqrt(d2(A,C)) * 0.75 >= sqrt(d2(B,C))

并且简化了,所以你不需要处理根:

d2(A, C) * 0.75^2 >= d2(B, C)