d3 / d3-delaunay

Compute the Voronoi diagram of a set of two-dimensional points.
https://d3js.org/d3-delaunay
ISC License
611 stars 57 forks source link

Find Voronoi cell and neighbors #51

Closed igagen closed 6 years ago

igagen commented 6 years ago

Is there a way to find the voronoi cell covering a point? And once you have a cell, is there a way of getting all the neighboring cells?

mbostock commented 6 years ago

delaunay.find

delaunay.neighbors

igagen commented 6 years ago

I’m asking about the Voronoi cell and it’s neighbors, not the Delaunay triangle at a point. Is there a simple way to go from Delaunay triangle and neighbors to Voronoi?

mbostock commented 6 years ago

The Voronoi is the dual of the Delaunay, so the tasks are equivalent.

So, the closest point to a given location [x, y] returned by delaunay.find is the Voronoi cell that contains that point.

And given a point i, delaunay.neighbors returns the connected points on the Delaunay triangulation, which are also the adjacent Voronoi cells.

igagen commented 6 years ago

Got it, I wasn’t sure if the Voronoi indices matched the Delaunay indices. Thanks!