Question

I have two rectangles that are equivalent and lie on top of each other. We might imagine them as a picture and a frame with the exact same dimensions. Now I rotate the picture (around it's middle) while keeping the frame fixed, so that the vertices of the picture slides outside the frame. I would like to calculate how much vertical and horizontal space I need to add to the frame in order to make it big enough to show the rotated picture. I know how much the rectangle is rotated (in degrees) and I know the dimensions of the rectangles.

Here is an illustration (bad drawing, sorry).

rectangles

The red and the yellow lines are the lengths that I would like to calculate.

The application of all this is an Android program, where I cannot rotate the view itself (due to version problems), but I can rotate the image inside the view. I would still very much like to keep the view exactly large enough to display the image after the rotation.

Thank you.

Was it helpful?

Solution

Let your half sides be a and b.

If you rotate by alpha, the rectangle vertex moves from (a,b) to

(a*cos(alpha)-b*sin(alpha),a*sin(alpha)+b*cos(alpha))

(this is, basically, the complex multiplication).

Thus the red line is

a*sin(alpha)+b*(cos(alpha)-1)

and the yellow line is

a*(cos(alpha)-1)+b*sin(alpha)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top