Created
October 24, 2012 20:42
-
-
Save ashblue/3948735 to your computer and use it in GitHub Desktop.
Detects if the vertex point's x and y are inside of a circle
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
/** | |
* Detects if the vertex point's x and y are inside of a circle. Only works with | |
* plain symetrical circles, not ovals | |
* @link Adapted from http://stackoverflow.com/questions/2212604/javascript-check-mouse-clicked-inside-the-circle-or-polygon#answer-2212678 | |
* @param {array|number} point Point to test, formatted as [x, y] | |
* @param {array|number} circleCenter Center of the circle formatted as [x, y] | |
* @param {number} radius Radius of the circle, which calculates as half its with or height | |
* @returns {boolean} True if the point is contained in the circle | |
*/ | |
function pointInCircle (point, circleCenter, radius) { | |
var xDif = point[0] - circleCenter[0]; | |
var yDif = point[1] - circleCenter[1]; | |
return xDif * xDif + yDif * yDif <= radius * radius; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment