1
votes

How do I output the result from my delaunay triangulation in the code below. I know how to plot it with matplotlib but cant figure out how to output the numbers. Print just ouputs the objects but I cannot figure out how to access it.

import matplotlib.pyplot as plt
from scipy.spatial import Delaunay, delaunay_plot_2d
from scipy.spatial import Delaunay
import numpy as np

points = np.array([[0.1933333, 0.47],
                   [0.1966667, 0.405],
                   [0.2066667, 0.3375]])


tri = Delaunay(points)
print(tri)

delaunay_plot_2d(tri)
plt.plot(points[:, 0], points[:, 1], 'o')
plt.show()
1

1 Answers

1
votes

The ids of the triangle vertices are stored in the simplices attribute of the triangulation object. The indicies of the vertices in the array of input points are stored.

>>> points = np.array([[0.1933333, 0.47],
                   [0.1966667, 0.405],
                   [0.2066667, 0.3375]])
>>> tri = Delaunay(points)
>>> print(tri)
<scipy.spatial.qhull.Delaunay object at 0x000002E1EB4EE348>
>>> tri.simplices
array([[1, 2, 0]], dtype=int32)

To get back to the coordinates of the vertices, you need to look them up in the input points array:

>>> points[tri.simplices]
array([[[0.1966667, 0.405    ],
        [0.2066667, 0.3375   ],
        [0.1933333, 0.47     ]]])

The resulting Delaunay triangulation also contains some other attributes, notably neighbors which contains information about neighboring triangles and vertex_to_simplex which allows you to find some Delaunay triangle a given vertex belongs to (and then start traversing the triangulation using neighbors).