Skip to content

Instantly share code, notes, and snippets.

@nsdevaraj
Created November 10, 2023 16:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nsdevaraj/d57e81b3e32170e7d2856ec72b1fa761 to your computer and use it in GitHub Desktop.
Save nsdevaraj/d57e81b3e32170e7d2856ec72b1fa761 to your computer and use it in GitHub Desktop.
// Import the d3 library
var d3 = require("d3");
// Define the circle and proportions
var center = {x: 0, y: 0};
var radius = 1;
var proportions = [0.2, 0.3, 0.5];
// Create the Voronoi diagram
var voronoi = d3.voronoi()
.extent([[-radius, -radius], [radius, radius]]);
// Create the points for the Voronoi diagram
var points = proportions.map(function(proportion, i) {
var angle = proportion * 2 * Math.PI;
return [center.x + radius * Math.cos(angle), center.y + radius * Math.sin(angle)];
});
// Compute the Voronoi diagram
var diagram = voronoi(points);
// The Voronoi polygons are now in diagram.polygons()
@nsdevaraj
Copy link
Author

@nsdevaraj
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment