Find bounding box dimensions around rotated object

1.3k Views Asked by At

Consider the following rectangle with dimensions 320 by 130.

After rotating the rectangle 10 degrees clockwise from the center (x: 160, y: 65), it looks like this.

enter image description here

My question is: How do I determine the bounding box dimensions?

I'm talking about the dimensions needed to surround the box, such as:

The answer is 346 by 232 but I only found that out because of the program I am using to make this image.

I've also done an example with programming such as:

rotate(10)
width = x1 - x3 + x2
height = y2 - y1 + y4

But, I'd like to solve this without programming. Where should I start with this?

2

There are 2 best solutions below

0
On

Let four corners of rectangle be $(x_1,y_1),(x_2,y_2),(x_3,y_3),(x_4,y_4)$.

Assume $(x_4,y_4) = (0,0)$

Now the box is rotated by an angle $\theta$ degrees, hence corner of box after rotation becomes $R[x_1,y_1]^T = (a_1,b_1),R[x_2,y_2]^T = (a_2,b_2),R[x_3,y_3]^T = (a_3,b_3),R[x_4,y_4]^T = (a_4,b_4)$.

where

$$R = \begin{bmatrix} \cos(\theta) & - \sin(\theta)\\ \sin(\theta) & \cos(\theta) \end{bmatrix}$$

Now that you know the corners of the rotated rectangle or box, you can find the rectangle bounding the box.

0
On

Well, let's say $X=\{x_1,x_2,x_3,x_4\}$ being the set of all unordered vertices, and similarly $Y=\{y_i\}$. Then the bounding box would be:

$P_{tl} \gets \{min(X),min(Y)\}$

$P_{br} \gets \{max(X),max(Y)\}$

$P_{tr} \gets \{max(X),min(Y)\}$

$P_{bl} \gets \{min(X),max(Y)\}$

($r$: right, $l$:left, $b$: bottom, $t$: top).