Created
May 1, 2014 22:26
-
-
Save anderssonfilip/f4d4fb562d659e4633c8 to your computer and use it in GitHub Desktop.
Javascript rotation in a plane
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
var rotate = function(x, y){ | |
var rx = 0; | |
var ry = 0; | |
var quarter = end/(Math.PI/2) | |
console.log("rotation: " + end) | |
if(end === 0) | |
{ | |
rx = x; | |
ry = y; | |
} | |
else if(quarter - Math.PI/2 < 0.001) | |
{ | |
if(quarter - Math.PI/2 < 0.001) | |
{ | |
rx = centerX; | |
ry =centerY + radius; | |
} | |
else if(quarter - Math.PI < 0.001) | |
{ | |
rx = centerX - radius; | |
ry = centerY; | |
} | |
else if(quarter - 1.5 * Math.PI < 0.001) | |
{ | |
rx = canvas.width/2 - centerX; | |
ry = canvas.height/2 - centerY; | |
} | |
else if(quarter - 2 * Math.PI/2 < 0.001) | |
{ | |
rx = centerX; | |
ry = radius, centerY; | |
} | |
} | |
else{ | |
rx = Math.abs(x*Math.cos(end) - y*Math.sin(end)); | |
ry = Math.abs(y*Math.cos(end) + x*Math.sin(end)); | |
} | |
return [rx,ry] | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment