Last active
December 18, 2020 23:48
-
-
Save stuller/20f54e9c9066bf09e5c930ef951fce97 to your computer and use it in GitHub Desktop.
rotate point around origin
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
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