Skip to main content
100%

d3-voronoi.clipCircle

✓ Published0🌍 Public
KKcnarf
Last edited Jan 29, 2017
Created on Jan 27, 2017

This example demonstrates a Voronoi tessellation clipped by a circular boundary that follows the mouse cursor. It shows how to programmatically clip Voronoi cells to a circle, rather than relying on browser-level clipping, with the clipping circle moving interactively as the user drags. The algorithm computes segment-circle intersections and constructs a path using lines and arcs, blending d3.line with curveCatmullRomClosed. Built with d3.v4, it uses d3.voronoi, d3.scaleOrdinal with d3.schemePastel1, and renders 100 randomly placed sites as SVG polygons and circles.

AI-generated description

This block experiments how to programmatically circle-clip a Voronoï tessellation, and does not rely on the browser to do the clipping in the screen space. It is a is a continuation of a previous one, and follows the work done by Philippe Riviere in its Circular Bounded Voronoi Tessellation.

By default, d3.voronoi comes with a rectangular clipping, through the d3-voronoi.extent() API. This block shows another way to clip the initial tesselation.

The algorithm used in this block is basically a copy/paste of the algorithm used in the d3.distanceLimitedVoronoi d3 plugin I made. The two algorithms have distinct purposes: the plugin leverages UX by defining [interactive and not-too-far] areas around each site, whereas this block define a global clipping.

Acknowledgments to:

lgpl-3.0 Licensed

Similar vizzes