How to find all neighbors of a given point in a delaunay triangulation using scipy.spatial.Delaunay?

前端 未结 7 1995
一个人的身影
一个人的身影 2020-12-28 19:40

I have been searching for an answer to this question but cannot find anything useful.

I am working with the python scientific computing stack (scipy,numpy,matplotlib

7条回答
  •  感情败类
    2020-12-28 19:53

    I needed this too and came across the following answer. It turns out that if you need the neighbors for all initial points, it's much more efficient to produce a dictionary of neighbors in one go (the following example is for 2D):

    def find_neighbors(tess, points):
    
        neighbors = {}
        for point in range(points.shape[0]):
            neighbors[point] = []
    
        for simplex in tess.simplices:
            neighbors[simplex[0]] += [simplex[1],simplex[2]]
            neighbors[simplex[1]] += [simplex[2],simplex[0]]
            neighbors[simplex[2]] += [simplex[0],simplex[1]]
    
        return neighbors
    

    The neighbors of point v are then neighbors[v]. For 10,000 points in this takes 370ms to run on my laptop. Maybe others have ideas on optimizing this further?

提交回复
热议问题