Created
November 3, 2015 15:02
-
-
Save LukeChannings/5b3e0c6fd35e4ad6b47c to your computer and use it in GitHub Desktop.
Rotate 2D points
This file contains hidden or 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
/** | |
* rotate points around an origin | |
* @param {Array<object>} ps a list of points | |
* @param {Number} a angle in degrees | |
* @param {Object} o origin object | |
* @return {Array<object>} a list of rotated points | |
*/ | |
function rotatePoints(ps, a, o) { | |
return ps.map(function(p) { | |
return { | |
x: Math.cos(a) * ( p.x - o.x ) - Math.sin(a) * ( p.y - o.y ) + o.x, | |
y: Math.sin(a) * ( p.x - o.x ) + Math.cos(a) * ( p.y - o.y ) + o.y | |
}; | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment