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

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

    I know it's been a while since this question was posed. However, I just had the same problem and figured out how to solve it. Just use the (somewhat poorly documented) method 'vertex_neighbor_vertices' of your Delaunay triangulation object (let us call it 'tri'). It will return two arrays:

    def get_neighbor_vertex_ids_from_vertex_id(vertex_id,tri):
        #use a less awful function name
        helper = tri.vertex_neighbor_vertices
        index_pointers = helper[0]
        indices = helper[1]
        result_ids = indices[index_pointers[vertex_id]:index_pointers[vertex_id+1]]
    
        return result_ids
    

    The neighbor vertices to the point with the index vertex_id are stored somewhere in the second array that I named 'indices'. But where? This is where the first array (which I called 'index_pointers') comes in. The starting position (for the second array 'indices') is index_pointers[vertex_id], the first position past the relevant sub-array is index_pointers[vertex_id+1]. So the solution is indices[index_pointers[vertex_id]:index_pointers[vertex_id+1]]

提交回复
热议问题