From the course: D3.js Essential Training for Data Scientists

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Making a Voronoi tessellation

Making a Voronoi tessellation - D3.js Tutorial

From the course: D3.js Essential Training for Data Scientists

Start my 1-month free trial

Making a Voronoi tessellation

- [Instructor] D3 isn't just for charts. It's great at physical simulations and spatial mapping, too. So I'm going to show you how to make a diagram you might never have heard of. Imagine you have a map in front of you, and it shows all the gas stations on it as little dots. You're frequently running low on fuel because you drive all over the region. And you want a graphic that will always be able to tell you which is the closest gas station. One way of doing this would be to superimpose a Voronoi diagram over your map. And that's what this is here. A Voronoi takes an input, the locations of the fuel stations, and outputs a series of tessellating polygon shapes, one per fuel station. On any of these black lines you are equally far from two dots. Within a polygon, your best bet for fuel is to head for the dot inside the polygon. For this graphic we're going to take a different approach. We're going to put all the CSS and JavaScript into the HTML document. So create a new file and save…

Contents