block by mbostock 8027835

Closest Point on Path II

Full Screen

As an alternative to the search algorithm, another approximate method for finding the closest point on any given SVG path is to sample points on that path and then compute the Voronoi tessellation. Use the range slider to control the distance between samples; denser samples produce more accurate results, but is more expensive to compute.

(Sampling paths can also be useful for path tweening.)