Skip to content

Instantly share code, notes, and snippets.

@bq1990
Created November 18, 2016 02:11
Show Gist options
  • Save bq1990/2aec41e485e1f2e1ea2d22bd66ca0bb8 to your computer and use it in GitHub Desktop.
Save bq1990/2aec41e485e1f2e1ea2d22bd66ca0bb8 to your computer and use it in GitHub Desktop.
Plot a circle
function plotCircle(points, radius, x0, y0) {
coords = [];
var slice = 2 * Math.PI / points; //calculate the slice of the pie
for(var i = 0; i < points; i++) {
var angle = slice * i;
var x = x0 + radius * Math.cos(angle);
var y = y0 + radius * Math.sin(angle);
coords.push({x: x, y: y});
}
return coords;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment