Skip to content

Instantly share code, notes, and snippets.

@tsmsogn
Created October 5, 2012 05:15
Show Gist options
  • Save tsmsogn/3838221 to your computer and use it in GitHub Desktop.
Save tsmsogn/3838221 to your computer and use it in GitHub Desktop.
JavaScript: Position rotation
function getRotatedPosition(x, y, rotation, referenceX, referenceY) {
if (isNaN(referenceX)) referenceX = 0;
if (isNaN(referenceY)) referenceY = 0;
var radian = rotation * (Math.PI / 180);
return {
x:x * Math.cos(radian) - y * Math.sin(radian) + referenceX - referenceX * Math.cos(radian) + referenceY * Math.sin(radian),
y:x * Math.sin(radian) + y * Math.cos(radian) + referenceY - referenceX * Math.sin(radian) - referenceY * Math.cos(radian)
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment