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

前端 未结 7 2014
一个人的身影
一个人的身影 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:45

    Here is an ellaboration on @astrofrog answer. This works also in more than 2D.

    It took about 300 ms on set of 2430 points in 3D (about 16000 simplices).

    from collections import defaultdict
    
    def find_neighbors(tess):
        neighbors = defaultdict(set)
    
        for simplex in tess.simplices:
            for idx in simplex:
                other = set(simplex)
                other.remove(idx)
                neighbors[idx] = neighbors[idx].union(other)
        return neighbors
    

提交回复
热议问题