I have this square div in the page. I need to get the $x,y$ coords (left/top) of the box based on rotation 0 even when the box is rotated at a different angle. Is there a formula to calculate the the $x,y$ coords of a square with rotation angle of $0$.
Here is a demo - http://jsfiddle.net/blessenm/XrVTp/
You can see the rectangle is rotated to $22$ degree. And I get the value $'x: 208, y: 234'$. Where $x$ is bottom left corner and $y$ is top left corner.
If the angle is at a rotation $0$. The value I get is $'x: 208, y: 234'$. This exactly what want irrespective of the rotation.
I know this question has a bit programming but I think strong math people might be able to solve it.
Btw, I get can get the following values as input.
- The distance between the left most point in the rotated rect and the left of the container.
- The distance between the top most point in the rotated rect and the top of the container.
- The distance between the right most point in the rotated rect and the left of the container.
- The distance between the bottom most point in the rotated rect and the top of the container.
- Angle of rotation
Note that the centre of the red square will not change when rotated. So we can find its coordinates first (by taking averages), then figure out the top left corner (based off the fact that the size of the red square is given beforehand; in this case, it was $256\times 256$). Here's a simple implementation: