🚀 LEVEL UP TO SENIOR:Unlock 500+ Advanced Practical Challenges & Exercises.
🎓 COURSERA PARTNER:Earn professional Google, Meta, and IBM certificates to supercharge your resume.
REFERENCEscipy

scipy Documentation

LOADING ENGINE...

spatial.Delaunay()

AI & DATA SCIENCE // spatial-delaunay

scipy.spatial.Delaunay() computes the Delaunay triangulation of a set of points — a triangulation where no point lies inside the circumcircle of any triangle, a property that avoids thin, sliver-like triangles.

Syntax

scipy.spatial.Delaunay(points)

Deep Dive Course

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.

editor.html
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)
localhost:3000

2Practical Example

Here is a real-world application of spatial.Delaunay() showing how it is used in production SciPy code.

editor.html
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))
localhost:3000

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.

editor.html
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)
localhost:3000

Examples

Example 01Basic Usage
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)
Example 02Advanced Example
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))

Best Practices

  • 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
  • Use .find_simplex() to locate which triangle contains a given query point efficiently, instead of a manual loop checking every triangle
  • Access .simplices to get the point-index triples defining each triangle, ready for further mesh-based processing or visualization

Interview Question

Why is Delaunay triangulation generally preferred over an arbitrary or naive triangulation of the same set of points?

Hint: Think about what specific geometric property Delaunay triangulation optimizes for.

Delaunay triangulation specifically maximizes the minimum angle across all the triangles it produces, which is equivalent to its defining property that no point lies inside the circumscribed circle of any triangle in the triangulation. This avoids the thin, needle-like, sliver triangles that an arbitrary triangulation of the same points could easily produce, and those well-shaped, more equilateral-like triangles are numerically much better behaved for downstream uses like finite-element simulation or interpolation, where extremely thin triangles can cause serious numerical accuracy problems.

Exercises

MediumPractice using spatial.Delaunay() in a real scenario.
View Solution
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)

Frequently Asked Questions

Why is Delaunay triangulation generally preferred over an arbitrary or naive triangulation of the same set of points?

Delaunay triangulation specifically maximizes the minimum angle across all the triangles it produces, which is equivalent to its defining property that no point lies inside the circumscribed circle of any triangle in the triangulation. This avoids the thin, needle-like, sliver triangles that an arbitrary triangulation of the same points could easily produce, and those well-shaped, more equilateral-like triangles are numerically much better behaved for downstream uses like finite-element simulation or interpolation, where extremely thin triangles can cause serious numerical accuracy problems.

Related Functions

spatial-convexhullspatial-kdtreeinterpolate-rbf