Created
November 4, 2013 16:55
-
-
Save rbalazs/7305636 to your computer and use it in GitHub Desktop.
Gets n number on a circle, calculated by the function parameters.
This file contains 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
/** | |
* 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