d3 / d3-delaunay

Compute the Voronoi diagram of a set of two-dimensional points.

Home Page:https://d3js.org/d3-delaunay

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

delaunay.find seems… wrong?

mbostock opened this issue · comments

If the small red dot is the target (mouse location), is this the expected search path? It looks like it’s not actually choosing the points that are closest to the mouse while traversing, and I’m not sure if it’s an invalidation triangulation or something else weird. (This is a random 200-point sample of the delaunay.find notebook dataset.)

image

Okay, so the notebook’s implementation of delaunay.find was wrong. I have updated it to use delaunay._step and it is now correct. I didn’t investigate what was wrong with the notebook implementation.

Thanks!

Another visible issue in this notebook is that point 0 is degenerate (there are two butters in the dataset with the same x,y coordinates), so the first step in the notebook looks weird (because find is jumping arbitrarily to point 1). Not a problem per se but it makes the search path look wrong too, the first step being "backwards". Not sure if we should live with it or set start=1 instead of 0.

Capture d’écran 2019-07-16 à 06 42 58

https://observablehq.com/@d3/delaunay-find

The other reason that I was surprised is that I was expecting it to follow the straightest line from the source to the target, but the algorithm doesn’t minimize the length of the line—it minimizes the number of hops (the topological distance).

The strategy is to jump blindly to a neighbor that is closer to the target — it does not guarantee that minimum. There are often shorter paths, both in total distance and number of hops.

See https://observablehq.com/d/8dc20942c4df82d2 for the three approaches .

Sometimes they diverge completely!
Capture d’écran 2019-07-17 à 19 05 42

Cool demonstration! Thank you.