Skip to content

Instantly share code, notes, and snippets.

@brianmcallister
Created August 15, 2016 20:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brianmcallister/0bcb40af4c0387357e8183f30a1d72a3 to your computer and use it in GitHub Desktop.
Save brianmcallister/0bcb40af4c0387357e8183f30a1d72a3 to your computer and use it in GitHub Desktop.
Get the position of a point on a circle.
/**
* Get the position of a point on a circle.
*
* @param {number} radius - Radius of the circle.
* @param {number} angle - Angle of the point to calculate.
* @param {number} offset - How far outside the circle the point should fall.
* @param {number} dotSize - Adjust for the size of the dot.
*
* @returns {object} results for top and left coords.
*/
const coords = (radius, angle, offset = 0, dotSize = 0) => {
const rad = angle / 180 * Math.PI;
const offsetRadius = radius + offset;
const center = radius - (dotSize / 2);
return {
top: offsetRadius * Math.sin(rad) + center,
left: offsetRadius * Math.cos(rad) + center,
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment