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) and I have a set of 2 dimensional points, for which I compute the Delaunay traingulation (wiki) using scipy.spatial.Delaunay.
I need to write a function that, given any point a, will return all other points which are vertices of any simplex (i.e. triangle) that a is also a vertex of (the neighbors of a in the triangulation). However, the documentation for scipy.spatial.Delaunay (here) is pretty bad, and I can’t for the life of me understand how the simplices are being specified or I would go about doing this. Even just an explanation of how the neighbors, vertices and vertex_to_simplex arrays in the Delaunay output are organized would be enough to get me going.
Much thanks for any help.
I figured it out on my own, so here’s an explanation for anyone future person who is confused by this.
As an example, let’s use the simple lattice of points that I was working with in my code, which I generate as follows
Details here not really important, suffice to say it generates a regular triangular lattice in which the distance between a point and any of its six nearest neighbors is 1.
To plot it
Now compute the triangulation:
Let’s look at what this gives us.
output:
simple, just an array of all nine points in the lattice illustrated above. How let’s look at:
output:
In this array, each row represents one simplex (triangle) in the triangulation. The three entries in each row are the indices of the vertices of that simplex in the points array we just saw. So for example the first simplex in this array,
[4, 3, 6]is composed of the points:Its easy to see this by drawing the lattice on a piece of paper, labeling each point according to its index, and then tracing through each row in
triang.vertices.This is all the information we need to write the function I specified in my question.
It looks like:
And that’s it! I’m sure the function above could do with some optimization, its just what I came up with in a few minutes. If anyone has any suggestions, feel free to post them. Hopefully this helps somebody in the future who is as confused about this as I was.