Skip to content

Instantly share code, notes, and snippets.

@rbalazs
Created November 4, 2013 16:55
Show Gist options
  • Save rbalazs/7305636 to your computer and use it in GitHub Desktop.
Save rbalazs/7305636 to your computer and use it in GitHub Desktop.
Gets n number on a circle, calculated by the function parameters.
/**
* Returns with the required amount of points on the circle, caluclated by the center and radius parameter.
*
* @param {Object} center Center.
* @param {number} radius Radius.
* @param {number} numberOfPoints Number of point required.
*
* @returns {Array} An array, containing the point.
*/
getPointOnCircle = function (center, radius, numberOfPoints) {
var slice,
i,
angle,
points;
slice = (2 * Math.PI) / numberOfPoints;
points = [];
for (i = 0; i < numberOfPoints; i += 1) {
angle = slice * i;
points.push([parseFloat(center.X + radius * Math.cos(angle)), parseFloat(center.Y + radius * Math.sin(angle))]);
}
return points;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment