if(!d3.geo2circle) d3.geo2circle = function(coordinates, radius) { radius = (radius) ? radius : Math.sqrt(Math.abs(area) / Math.PI) var circle = [] var length = 0 var lengths = [length] var p0 = coordinates[0] var p1 var x var y var i = 0 var n = coordinates.length while (++i < n) { p1 = coordinates[i] x = p1[0] - p0[0] y = p1[1] - p0[1] lengths.push(length += Math.sqrt(x * x + y * y)) p0 = p1; } var centroid =d3.polygonCentroid(coordinates) var angle var i = -1 var k = 2 * Math.PI / lengths[lengths.length - 1]; while (++i < n) { angle = lengths[i] * k; circle.push([ centroid[0] + radius * Math.cos(angle), centroid[1] + radius * Math.sin(angle) ]); } return circle; };