【发布时间】:2018-10-24 11:46:13
【问题描述】:
我使用一组 LatLon 点的scipy.spatial Python 库制作了一个 Voronoi 图,以查找每个点的邻居。然后,我发现 Delaunay Triangulation 会更有用,现在我可以使用以下算法轻松找到每个点的“第一层”和“第二层”邻居:
def findNeighbors(delaunay):
"Returns a adjacency list of the graph"
neighbors = defaultdict(set)
for simplex in delaunay.simplices:
for vertice in simplex:
other = set(simplex)
other.remove(vertice)
neighbors[vertice] = neighbors[vertice].union(other)
return neighbors
def neighborCount(graph, start, target):
if target in graph[start]:
return 'First Tier Neighbor'
elif graph[start] & graph[target]:
return 'Second Tier Neighbor'
但问题是我需要找到“第 6 层邻居”,如果不循环遍历所有邻接列表,我无法找到一种方法。这是我要查找的“3rd Tier Neighbor”示例。
有没有更聪明的方法来做到这一点?
【问题讨论】:
标签: python scipy voronoi delaunay