Skip to content

Instantly share code, notes, and snippets.

@ashblue
Created October 9, 2012 17:12
Show Gist options
  • Save ashblue/3860114 to your computer and use it in GitHub Desktop.
Save ashblue/3860114 to your computer and use it in GitHub Desktop.
Move point at an angle
/**
* 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)
];
}
@hirasso
Copy link

hirasso commented Jul 24, 2019

Like like like! :))

@weeklyd3
Copy link

Thanks, this really helped!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment