Skip to content

Instantly share code, notes, and snippets.

@LukeChannings
Created November 3, 2015 15:02
Show Gist options
  • Save LukeChannings/5b3e0c6fd35e4ad6b47c to your computer and use it in GitHub Desktop.
Save LukeChannings/5b3e0c6fd35e4ad6b47c to your computer and use it in GitHub Desktop.
Rotate 2D points
/**
* 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