This question already has an answer here:
I have rectangle with co-ordinates(x1,y1) and (x2,y2) and I have to rotate the rectangle an amount of θ about it centre using Rotation Matrix
| cosθ sinθ |
| -sinθ cosθ |
I need to find the co-ordinates of bounding rectangle after rotation.
Before rotation
0,0
|"""""""""""""""""""""""""""""""""""""""""""|
| |
| x1,y1 |
| |"""""""""""""| |
| | | |
| | | |
| | | |
| """""""""""""" x2,y2 |
| |
| |
""""""""""""""""""""""""""""""""""""""""""" W,H
After rotation
0,0
|"""""""""""""""""""""""""""""""""""""""""""|
| ?,? |
| |""""/\"""""| |
| | / \ | |
| | / \ | |
| | / /| |
| |/ / | |
| |\ / | |
| | \ / | |
| | \ / | |
| """"""""""" ?,? |
| |
| |
""""""""""""""""""""""""""""""""""""""""""" W,H
Is there any general equation for finding the co-ordinates of bounding rectangle?.
Thanks....
Haris.
Point (x1, y1) rotates to (x1 cos θ - y1 sin θ, x1 sin θ + y1 cos θ), while point (x2, y2) rotates to (x2 cos θ - y2 sin θ, x2 sin θ + y2 cos θ). The other two points can be calculated accordingly.
The coordinates of the bounding reactangle are (x3, y3) and (x4, y4), where x3 is the smallest of all new x coordinates, y3 the smallest of all new y coordinates, x4 the greatest of all new x coordinates and y4 the greatest of all new y coordinates.
Which of the corners produces the smallest x (and so on) depends on your angle or rotation. For angles from 0° to 90°, x3 will come from (x1, y1), so x3 = x1 cos θ - y1 sin θ. For angles from 90° to 180°, it will come from (x2, y1), and so on. So either you decide which points to use based on your angle of rotation, or you just take the smallest and greatest of all x's and y's.
But I think you should probably ask this on https://math.stackexchange.com/
Just mark all Fi angles on your drawing, and you can see that
Delphi test:
Output example: