如何使用 Delaunay 三角剖分输出包含三角剖分中的所有连接及其距离的矩阵?

问题描述

我想使用 Delaunay 三角剖分来计算坐标数组的网络的最小生成树。如何从三角剖分中获取所有边及其距离,以便将它们用于 MST?

解决方法

以下代码是根据我之前的回答 here 修改的。 它将边(点数组中的索引对)存储为字典的键,将距离作为字典值。

# Computing Delaunay
tri = Delaunay(points)

# Building the edges-distance map:
edges_dist_map = {}
for tr in tri.simplices:
    for i in range(3):
        edge_idx0 = tr[i]
        edge_idx1 = tr[(i+1)%3]
        if (edge_idx1,edge_idx0) in edges_dist_map:
            continue  # already visited this edge from other side
        p0 = points[edge_idx0]
        p1 = points[edge_idx1]
        dist = np.linalg.norm(p1 - p0)
        edges_dist_map[(edge_idx0,edge_idx1)] = dist

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...