I am rotating an object in html5 canvas around a variable point of origin.
If a user clicks on a given point in the newly rotated rectangle, I need the returned mouse coordinates to be rotated back around the same point of origin.
I have made a very quick drawing to hopefully illustrate better:
I essentially need a function that will take the actual clicked mouse coordinates as x and y and transform them to the objects position BEFORE it was rotated.
var origin = {
x: 100,
y: 100
};
var angle = 45;
function transformCoordinates(x,y){
//Perform calculation to transform coordinates
return {
x : newx,
y : newy
};
}
The variables available will be the transformation origin of the rotation and the angle. As well as the mouse click coordinate on the canvas (relative to the canvas itself, with 0,0 being the top left point etc)
Unfortunately math is not my strong point. Hopefully someone can help.