Skip to content

Instantly share code, notes, and snippets.

@Radcliffe
Created December 21, 2013 16:04
Show Gist options
  • Save Radcliffe/8071295 to your computer and use it in GitHub Desktop.
Save Radcliffe/8071295 to your computer and use it in GitHub Desktop.
Covering a grid with circles
x1 y1 r1 x2 y2 r2 x3 y3 r3 x4 y4 r4 x5 y5 r5 x6 y6 r6
2.5 7.5 3.53553390593 3.0 3.0 2.2360679775 2.0 3.0 2.2360679775 3.5 1.5 1.58113883008 1.5 1.5 1.58113883008 2.5 1.5 2.91547594742
2.5 3.5 1.58113883008 2.5 2.5 1.58113883008 2.5 3.5 2.91547594742 2.5 1.5 1.58113883008 2.5 2.5 2.91547594742 2.5 1.5 2.91547594742
3.0 4.5 2.06155281281 2.0 4.5 2.06155281281 2.5 2.5 1.58113883008 2.5 2.5 2.5495097568 2.5 0.5 1.58113883008 2.5 0.5 2.5495097568
2.5 6.5 2.91547594742 3.5 3.5 1.58113883008 1.5 3.5 1.58113883008 3.5 1.5 1.58113883008 1.5 1.5 1.58113883008 2.5 -1.5 2.91547594742
2.5 5.0 2.5 3.5 2.5 1.58113883008 1.5 2.5 1.58113883008 2.5 2.5 2.5495097568 2.5 2.5 2.91547594742 2.5 0.0 2.5
3.5 3.5 1.58113883008 1.5 3.5 1.58113883008 2.5 3.5 2.91547594742 3.5 1.5 1.58113883008 1.5 1.5 1.58113883008 2.5 1.5 2.91547594742
2.5 6.5 2.91547594742 2.5 2.5 0.707106781187 2.5 2.5 1.58113883008 2.5 2.5 2.5495097568 2.5 2.5 2.91547594742 2.5 -1.5 2.91547594742
2.5 4.5 1.58113883008 2.5 2.5 1.58113883008 2.9 2.5 3.26496554346 2.5 2.5 2.5495097568 2.5 0.5 1.58113883008 2.1 2.5 3.26496554346
2.5 4.0 1.11803398875 2.5 2.5 1.58113883008 2.5 3.5 2.91547594742 2.5 1.0 1.11803398875 2.5 2.5 2.91547594742 2.5 1.5 2.91547594742
2.5 5.5 2.5495097568 3.0 3.0 2.2360679775 2.0 3.0 2.2360679775 3.0 2.0 2.2360679775 2.0 2.0 2.2360679775 2.5 -0.5 2.5495097568
2.5 3.5 1.58113883008 2.5 3.5 2.5495097568 2.5 1.5 2.5495097568 2.5 1.5 1.58113883008 2.5 2.5 2.91547594742 2.5 2.5 3.53553390593
2.5 3.5 1.58113883008 2.5 2.5 1.58113883008 3.1 2.5 3.14006369362 2.5 1.5 1.58113883008 2.5 2.5 2.91547594742 1.9 2.5 3.14006369362
2.5 4.5 1.58113883008 2.5 4.5 2.5495097568 2.5 2.5 1.58113883008 2.5 2.5 2.5495097568 2.5 0.5 1.58113883008 2.5 0.5 2.5495097568
2.5 4.5 2.5495097568 2.5 2.5 1.58113883008 2.5 2.5 2.12132034356 2.5 2.5 2.5495097568 2.5 2.5 2.91547594742 2.5 0.5 2.5495097568
2.5 5.5 3.53553390593 2.5 -0.5 3.53553390593 2.5 2.5 1.58113883008 3.5 2.5 2.91547594742 2.5 2.5 2.91547594742 1.5 2.5 2.91547594742
3.5 3.5 2.12132034356 1.5 3.5 2.12132034356 2.5 2.5 1.58113883008 2.5 1.5 1.58113883008 2.5 2.5 2.91547594742 2.5 1.5 2.91547594742
2.5 4.5 2.5495097568 3.5 2.5 1.58113883008 1.5 2.5 1.58113883008 3.5 2.5 2.5495097568 1.5 2.5 2.5495097568 2.5 0.5 2.5495097568
3.5 4.5 1.58113883008 1.5 4.5 1.58113883008 2.5 3.0 2.5 3.5 0.5 1.58113883008 2.5 2.0 2.5 1.5 0.5 1.58113883008
2.5 4.5 1.58113883008 2.5 2.5 1.58113883008 2.5 2.5 2.5495097568 2.5 0.5 1.58113883008 2.5 2.5 2.91547594742 2.5 2.5 3.53553390593
2.5 5.5 2.5495097568 2.5 2.5 1.58113883008 2.5 2.5 2.5495097568 2.5 0.5 1.58113883008 2.5 2.5 2.91547594742 2.5 1.5 2.91547594742
2.5 4.0 2.69258240357 3.0 3.0 2.2360679775 2.0 3.0 2.2360679775 3.5 1.5 1.58113883008 1.5 1.5 1.58113883008 2.5 1.25 2.79508497187
4.5 4.5 0.707106781187 0.5 4.5 0.707106781187 2.5 2.5 1.58113883008 2.5 2.5 2.5495097568 2.5 0.5 1.58113883008 2.5 0.5 2.5495097568
2.5 4.5 2.5495097568 2.5 2.5 1.58113883008 2.5 2.5 2.5495097568 2.5 1.5 1.58113883008 2.5 2.5 2.91547594742 2.5 1.5 2.91547594742
2.5 3.5 1.58113883008 1.83333333333 2.5 1.90029237517 3.16666666667 2.5 1.90029237517 2.5 1.5 1.58113883008 2.5 2.5 2.91547594742 2.5 2.5 3.53553390593
2.5 7.5 3.53553390593 2.5 3.5 1.58113883008 2.5 3.5 2.5495097568 2.5 1.5 1.58113883008 2.5 2.5 2.91547594742 2.5 1.0 2.69258240357
2.5 0.5 3.53553390593 3.0 3.0 2.2360679775 2.0 3.0 2.2360679775 3.5 1.5 1.58113883008 1.5 1.5 1.58113883008 2.5 2.5 3.53553390593
2.5 6.5 2.91547594742 2.5 2.5 1.58113883008 2.5 2.5 2.5495097568 2.5 1.5 1.58113883008 2.5 2.5 2.91547594742 2.5 -0.5 2.5495097568
3.5 4.0 1.80277563773 2.5 2.5 1.58113883008 1.5 2.5 1.58113883008 3.5 1.0 1.80277563773 2.5 2.5 2.91547594742 1.5 2.5 2.91547594742
2.5 4.5 2.5495097568 2.5 2.5 1.58113883008 2.5 3.0 2.5 2.5 2.5 2.5495097568 2.5 2.0 2.5 2.5 0.5 2.5495097568
2.5 4.0 2.69258240357 2.5 3.5 1.58113883008 2.5 2.5 1.58113883008 2.5 1.5 1.58113883008 2.5 2.5 2.91547594742 2.5 1.0 2.69258240357
2.5 4.5 1.58113883008 2.5 2.5 1.58113883008 2.5 3.0 3.20156211872 2.5 2.5 2.5495097568 2.5 0.5 1.58113883008 2.5 2.0 3.20156211872
2.5 1.5 3.53553390593 0.5 1.5 3.53553390593 4.5 1.5 3.53553390593 3.5 1.5 1.58113883008 1.5 1.5 1.58113883008 2.5 1.5 2.91547594742
3.0 4.0 2.2360679775 1.5 2.5 1.58113883008 0.5 2.5 2.91547594742 3.0 1.0 2.2360679775 2.5 2.5 2.91547594742 1.5 2.5 2.91547594742
2.5 3.5 1.58113883008 2.5 3.5 2.5495097568 2.5 1.5 2.5495097568 2.5 1.5 1.58113883008 3.0 2.5 3.20156211872 2.0 2.5 3.20156211872
2.5 3.5 1.58113883008 2.5 2.5 1.58113883008 2.5 2.5 2.5495097568 2.5 1.5 1.58113883008 2.5 2.5 2.91547594742 2.5 2.5 3.53553390593
2.5 2.5 0.707106781187 2.5 2.5 1.58113883008 2.5 2.5 2.12132034356 2.5 2.5 2.5495097568 2.5 2.5 2.91547594742 2.5 2.5 3.53553390593
2.5 3.5 1.58113883008 2.5 3.5 2.5495097568 2.5 1.5 2.5495097568 2.5 1.5 1.58113883008 2.5 2.9 3.26496554346 2.5 2.1 3.26496554346
2.5 4.5 2.5495097568 3.0 3.0 2.2360679775 2.0 3.0 2.2360679775 3.0 2.0 2.2360679775 2.0 2.0 2.2360679775 2.5 0.5 2.5495097568
2.5 7.5 3.53553390593 2.5 3.5 1.58113883008 2.5 2.5 2.5495097568 2.5 1.5 1.58113883008 2.5 2.5 2.91547594742 2.5 -2.5 3.53553390593
2.5 3.5 1.58113883008 3.5 2.5 1.58113883008 1.5 2.5 1.58113883008 2.5 1.5 1.58113883008 2.5 2.5 2.91547594742 2.5 2.5 3.53553390593
2.5 3.5 1.58113883008 2.5 3.75 2.79508497187 2.5 2.5 2.5495097568 2.5 1.5 1.58113883008 2.5 2.5 2.91547594742 2.5 1.25 2.79508497187
2.5 2.5 0.707106781187 3.0 3.0 2.2360679775 2.0 3.0 2.2360679775 3.0 2.0 2.2360679775 2.0 2.0 2.2360679775 2.5 2.5 3.53553390593
2.5 0.5 3.53553390593 2.5 3.5 1.58113883008 2.5 4.5 3.53553390593 2.5 1.5 1.58113883008 2.5 2.5 2.91547594742 2.5 2.5 3.53553390593
2.5 2.5 0.707106781187 2.5 2.5 1.58113883008 2.5 3.5 2.91547594742 2.5 2.5 2.5495097568 2.5 2.5 2.91547594742 2.5 1.5 2.91547594742
2.5 3.5 1.58113883008 1.83333333333 2.5 1.90029237517 4.16666666667 2.5 2.63523138347 2.5 1.5 1.58113883008 2.5 2.5 2.91547594742 1.9 2.5 3.14006369362
3.5 3.5 1.58113883008 1.5 3.5 1.58113883008 2.5 2.5 2.12132034356 3.5 1.5 1.58113883008 1.5 1.5 1.58113883008 2.5 2.5 3.53553390593
2.5 6.5 2.91547594742 2.5 2.5 1.58113883008 2.5 2.5 2.5495097568 2.5 0.5 1.58113883008 2.5 2.5 2.91547594742 2.5 0.5 2.5495097568
2.5 3.5 1.58113883008 4.16666666667 2.5 2.63523138347 2.5 2.5 2.5495097568 2.5 1.5 1.58113883008 2.5 2.5 2.91547594742 0.833333333333 2.5 2.63523138347
2.5 3.5 1.58113883008 2.5 3.75 2.79508497187 2.5 1.5 2.5495097568 2.5 1.5 1.58113883008 2.5 2.5 2.91547594742 2.5 1.5 2.91547594742
2.5 4.5 2.5495097568 2.5 2.5 1.58113883008 3.16666666667 2.5 2.63523138347 2.5 2.5 2.5495097568 1.83333333333 2.5 2.63523138347 2.5 0.5 2.5495097568
2.5 5.0 2.5 3.5 2.5 1.58113883008 1.5 2.5 1.58113883008 2.5 1.5 1.58113883008 2.5 2.5 2.91547594742 2.5 1.9 3.14006369362
2.5 4.0 2.69258240357 2.5 3.5 1.58113883008 2.5 4.5 3.53553390593 2.5 1.5 1.58113883008 2.5 2.5 2.91547594742 2.5 1.25 2.79508497187
2.5 5.5 2.5495097568 2.5 2.5 1.58113883008 2.5 2.5 2.12132034356 2.5 2.5 2.5495097568 2.5 2.5 2.91547594742 2.5 -0.5 2.5495097568
2.5 7.5 3.53553390593 2.5 3.5 1.58113883008 2.5 4.5 3.53553390593 2.5 1.5 1.58113883008 2.5 2.5 2.91547594742 2.5 1.5 2.91547594742
x1 y1 r1 x2 y2 r2 x3 y3 r3 x4 y4 r4 x5 y5 r5
1.5 0.5 1.58113883 1.5 1.5 1.58113883 2.166666667 2.833333333 2.173067468 0.5 0.5 3.535533906 2.5 2.5 1.58113883
1.5 0.5 1.58113883 2 2.5 2.5 1.5 2.5 1.58113883 2.5 1.5 2.121320344 3.166666667 2.833333333 1.178511302
1.5 0.5 1.58113883 2 2.5 2.5 1.5 2.5 1.58113883 2.5 1.166666667 1.900292375 2.5 2.5 1.58113883
1.5 0.5 1.58113883 1.5 2.5 1.58113883 1.666666667 2.333333333 2.357022604 2.5 1.5 2.121320344 3.5 2.5 1.58113883
1.5 0.5 1.58113883 1.5 2.5 1.58113883 1.5 1.5 2.915475947 2.166666667 1.5 1.900292375 4 1.5 2.5
1.5 0.5 1.58113883 1.5 2.5 1.58113883 1.5 1.5 2.915475947 3.166666667 1.5 2.635231383 2.5 1.5 1.58113883
1.5 0.5 1.58113883 2.5 2 2.5 1.833333333 3.5 1.900292375 2.5 1.5 1.58113883 2.5 2.5 1.58113883
3.5 0.5 3.535533906 2.5 2.5 2.915475947 1.5 2.5 1.58113883 2.5 1.5 1.58113883 3.166666667 2.166666667 1.178511302
3.5 0.5 3.535533906 1.5 2.5 1.58113883 -0.166666667 1.833333333 2.173067468 2.5 1.5 1.58113883 4.5 1.5 1.58113883
2 1 2.236067977 1 2 2.236067977 2 2 2.236067977 1.5 1.5 0.707106781 3.166666667 3.166666667 1.178511302
2 1.5 2.5 1.5 1.5 1.58113883 2 3.166666667 2.166666667 2.5 1.5 1.58113883 2 3.25 1.25
2 1.5 2.5 1.5 1.5 1.58113883 2 4 2 2.5 1.5 1.58113883 2 2.666666667 1.666666667
2 2 2.828427125 1.5 1.5 1.58113883 1.5 2.5 1.58113883 2.5 1.5 1.58113883 2.833333333 2.833333333 1.178511302
{"description":"Covering a grid with circles","endpoint":"","display":"svg","public":true,"require":[],"fileconfigs":{"inlet.js":{"default":true,"vim":false,"emacs":false,"fontSize":12},"circle-covers.csv":{"default":true,"vim":false,"emacs":false,"fontSize":12},"_.md":{"default":true,"vim":false,"emacs":false,"fontSize":12},"config.json":{"default":true,"vim":false,"emacs":false,"fontSize":12},"style.css":{"default":true,"vim":false,"emacs":false,"fontSize":12},"circle-covers-6.csv":{"default":true,"vim":false,"emacs":false,"fontSize":12}},"fullscreen":false,"play":false,"loop":false,"restart":false,"autoinit":true,"pause":true,"loop_type":"pingpong","bv":false,"nclones":15,"clone_opacity":0.4,"duration":3000,"ease":"linear","dt":0.01,"thumbnail":"http://i.imgur.com/zKbn8Ey.gif"}
var mesh = 20;
var offset = 90;
var tileHeight = 200;
var tileWidth = 200;
var columns = 9;
var gridSize = 6;
var numCircles = 6;
var scale = function(x) {return x*mesh + offset;};
var svg = d3.select("svg");
// var data = tributary["circle-covers"];
var data = tributary["circle-covers-6"];
var bind_data = function(data) {
var circle;
for (var i=0; i < data.length; i++) {
var g = svg.append("g")
.attr("transform","translate(" + ((i % columns)* tileWidth) + "," + (Math.floor(i/columns) * tileHeight) + ")");
var range = d3.range(numCircles);
g.selectAll("circle.solution").data(range).enter().append("circle").attr({
cx: function(d){ return scale(data[i]["x"+(d+1)]);},
cy: function(d){ return scale(data[i]["y"+(d+1)]);},
r: function(d){ return mesh * data[i]["r"+(d+1)];},
fill: "none",
stroke: "teal"
}).classed("solution", true);
range = d3.range(gridSize*gridSize);
g.selectAll("circle.dot").data(range).enter().append("circle").attr({
cx: function(d) { return scale(d % gridSize);},
cy: function(d) { return scale(Math.floor(d/gridSize));},
r: 3,
fill: "red"
}).classed("dot", true);
}
};
bind_data(data);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment