Created
November 10, 2023 16:02
-
-
Save nsdevaraj/d57e81b3e32170e7d2856ec72b1fa761 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://graphics.uni-konstanz.de/publikationen/Balzer2005VoronoiTreemaps/index.html and https://onlinelibrary.wiley.com/doi/10.1111/j.1467-8659.2012.03078.x use these scientific papers to create pseudo code for splitting a circle into polygons of different proportions
https://www.jasondavies.com/voronoi-treemap/