如何解决如何使用 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
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。