Skip to content

Instantly share code, notes, and snippets.

@stuller
Last active December 18, 2020 23:48
Show Gist options
  • Save stuller/20f54e9c9066bf09e5c930ef951fce97 to your computer and use it in GitHub Desktop.
Save stuller/20f54e9c9066bf09e5c930ef951fce97 to your computer and use it in GitHub Desktop.
rotate point around origin
function rotate(x, y, angle) {
const originX = 0;
const originY = 0;
var radians = (Math.PI / 180) * angle,
cos = Math.cos(radians),
sin = Math.sin(radians),
nx = (cos * (x - originX)) + (sin * (y - originY)) + originX,
ny = (cos * (y - originY)) - (sin * (x - originX)) + originY;
return ({x: Math.round(nx), y: Math.round(ny)})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment