A Delaunay triangulation connects a set of points into triangles, or higher-dimensional simplices in more than 2D, such that it maximizes the minimum angle across all triangles, avoiding the thin, needle-like triangles that a naive triangulation could produce, which makes it especially useful for mesh generation in simulations, terrain modeling, and interpolation over scattered data points. The resulting object's .simplices attribute gives the indices of the points forming each triangle.
1Understanding spatial.Delaunay()
A Delaunay triangulation connects a set of points into triangles, or higher-dimensional simplices in more than 2D, such that it maximizes the minimum angle across all triangles, avoiding the thin, needle-like triangles that a naive triangulation could produce, which makes it especially useful for mesh generation in simulations, terrain modeling, and interpolation over scattered data points. The resulting object's .simplices attribute gives the indices of the points forming each triangle.
Use the resulting Delaunay object's .find_simplex() method to quickly determine which triangle a given query point falls inside, rather than manually checking every triangle yourself — it's an efficient, purpose-built lookup.
from scipy.spatial import Delaunay
import numpy as np
points = np.array([[0, 0], [1, 0], [0, 1], [1, 1]])
tri = Delaunay(points)
print(tri.simplices)2Practical Example
Here is a real-world application of spatial.Delaunay() showing how it is used in production SciPy code.
from scipy.spatial import Delaunay
import numpy as np
points = np.array([[0, 0], [1, 0], [0, 1], [1, 1], [0.5, 0.5]])
tri = Delaunay(points)
print(len(tri.simplices))3Best Practices
Follow these guidelines when working with spatial.Delaunay():
1. Use Delaunay triangulation as a robust default when you need to triangulate a set of scattered points into a well-shaped mesh, rather than a naive or ad-hoc triangulation approach
2. Use .find_simplex() to locate which triangle contains a given query point efficiently, instead of a manual loop checking every triangle
3. Access .simplices to get the point-index triples defining each triangle, ready for further mesh-based processing or visualization
Tip: Use the resulting Delaunay object's .find_simplex() method to quickly determine which triangle a given query point falls inside, rather than manually checking every triangle yourself — it's an efficient, purpose-built lookup.
from scipy.spatial import Delaunay
import numpy as np
points = np.array([[0, 0], [1, 0], [0, 1], [1, 1]])
tri = Delaunay(points)
print(tri.simplices)