I need to retain coordinate information following a rotation and am struggling with the necessary math.
I have an image, with certain crop coordinates. These coordinates are given as the following object:
{
h: 139.68333435058594,
w: 139.68333435058594,
x: 60.31666564941406,
x2: 200,
y: 80,
y2: 219.68333435058594
}
I am then rotating this image (it is a canvas element) but I would like the new coordinates to accurately reflect the rotation, leaving the original crop intact.
e.g. if the top left quarter of a 400x400 image is selected the returned coordinates would be x:0, y:0, x2:200, y2:200. When rotated -90 degrees to the left, the new coordinates should be : x:0, y:200, x2:200, y:400.
How would I write a function to calculate these new coordinates?
Many thanks.
To help visualize this question properly I have included a quick image:
EDIT: The large square in the image above is the photo that I am rotating. It is being rotated around its midpoint and the crop coordinates are relative to the image itself. Upon rotation the actual coordinate plane is reset prior to recalculating the new coordinates meaning that the top left point of the image/container will always be 0,0.