Created
August 15, 2016 20:15
-
-
Save brianmcallister/0bcb40af4c0387357e8183f30a1d72a3 to your computer and use it in GitHub Desktop.
Get the position of a point on a circle.
This file contains hidden or 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
/** | |
* 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