algorithm - 使用 BFS 找到三角形中的 Fermat 点

标签 algorithm graph geometry breadth-first-search

给定网格中的 3 个点,您如何找到一个点,使得该点到所有 3 个点的距离之和最小。这个问题的一个明显的答案是费马三角形。我有兴趣知道我们是否可以使用图中的广度优先搜索算法来定位费马点。

struct node{
  int Person1X,Person1Y,Person2X,Person2Y,Person3X,Person3Y; //X and Y coordinates of all 3 persons
  int steps;   //sum of distances covered by all 3 person to reach this state
}

在进行 BFS 时,我们可以设置一个约束, if steps>min(以3人为顶点的三角形任意两条边之和) return;

if(Person1X=Person2X=Person2X)AND(Person1Y=Person2Y=Person3Y) return steps;

最佳答案

无需搜索。

给定“三角形”ABC: SumOfDistances( p ) = dist( A, p ) + dist( B, p ) + dist( C, p )

其中 dist( q, p ) = |qx-px| + |qy-py| (曼哈顿距离)

您可以看到 SumOfDistances( p ) = SumOfDistancesx( p ) + SumOfDistancesy( p )

因此,您可以独立地最小化 x 轴和 y 轴上的距离。

因此,费马点的 x 坐标是 3 个给定 x 坐标的中值。 费马点的 y 坐标是 3 个给定 y 坐标的中值。

关于algorithm - 使用 BFS 找到三角形中的 Fermat 点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13023960/

相关文章:

algorithm - 如何知道一个二进制数是否被 3 整除?

算法题..链表

c++ - 编码正确逻辑时输出错误的原因?

python - 解析 MSDN 几何数据类型

python - 如何从 findHomography 获取旋转角度?

python - 按索引获取列表中元素的更快方法

c++ - 确定两个 vector 是否包含两个相同的相邻项

graph - TreeForm 无重叠

python - Networkx 图搜索 : dfs_successors vs. dfs_predecessors

Python 和 OpenCV。如何检测图像中的所有(填充)圆形/圆形对象?