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

delaunay.find seems… wrong? #78

Closed mbostock closed 5 years ago

mbostock commented 5 years ago

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

mbostock commented 5 years ago

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.

Fil commented 5 years ago

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

mbostock commented 5 years ago

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).

Fil commented 5 years ago

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 .

Fil commented 5 years ago

Sometimes they diverge completely!

Capture d’écran 2019-07-17 à 19 05 42
mbostock commented 5 years ago

Cool demonstration! Thank you.