Created
October 9, 2012 17:12
-
-
Save ashblue/3860114 to your computer and use it in GitHub Desktop.
Move point at an angle
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
/** | |
* Moves a vertex at an angle for a specific distance, 0 degrees points up and 180 degrees points down | |
* @param {array} point Location on a cartesian graph formatted as [x, y] | |
* @param {number} angle Angle at which a point should move in radians | |
* @param {number} distance How far should the point move at the given angle in pixels? | |
* @returns {array} Newly moved point formatted as [x, y] | |
*/ | |
function movePointAtAngle (point, angle, distance) { | |
return [ | |
point[0] + (Math.sin(angle) * distance), | |
point[1] - (Math.cos(angle) * distance) | |
]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Like like like! :))