d3-delaunay
repository·main·Indexed 20 days ago
https://github.com/d3/d3-delaunayA high-performance JavaScript library for computing Voronoi diagrams from 2D points, built upon the Delaunator Delaunay triangulation engine. It provides the Delaunay class for computing triangulations and spatial queries, and the Voronoi class for generating clipped Voronoi diagrams.
What's inside d3-delaunay
- d3-delaunay is a high-performance JavaScript library used to compute the Voronoi diagram of a set of two-dimensional points. It leverages the Delaunator library to perform fast Delaunay triangulation using sweep algorithms, then constructs the Voronoi diagram by connecting the circumcenters of adjacent triangles.
Create a Voronoi diagram with Voronoi
mainThe
Voronoiclass is used to compute Voronoi diagrams. It is typically instantiated from an existingDelaunaytriangulation. You can define the bounding box for the diagram to ensure cells are clipped correctly.import { Delaunay, Voronoi } from "d3-delaunay"; const points = [[0, 0], [1, 0], [0, 1]]; const delaunay = Delaunay.from(points); const voronoi = Voronoi.from(delaunay).extent([[0, 0], [1, 1]]);Create a Delaunay triangulation with Delaunay
mainThe
Delaunayclass is the primary entrypoint for computing Delaunay triangulations. It takes an array of points (typically an array of arrays, e.g.,[[x0, y0], [x1, y1], ...]) and computes the triangulation. It provides methods for spatial queries, finding neighbors, and generating Voronoi diagrams.import { Delaunay } from "d3-delaunay"; const points = [[0, 0], [1, 0], [0, 1]]; const delaunay = Delaunay.from(points);