Determining best angle of rotation to fit a rectangle inside a rectangle

1k Views Asked by At

I have two rectangles, inner shown in red and outer shown in blue. I'm trying to find the smallest angle to fit the inner box into the outer box, so that the red inner rect is rotated to the orientation of the green rect:

enter image description here

At first I made the center line of the inner box colinear to the outer box's diagonal:

$inner_\theta=atan2(outer_w,outer_l)$

But, this proved incorrect because the inner rect needs to be slightly off from colinear to fit correctly if the outer rect is not square.

I've noticed for an outer rect with a 1.5:1 aspect ratio, it appears that subtracting $atan2(inner_w/2,inner_l)$ lines things up correctly as in the above image, but I'm not sure a) if this is correct or b) why, and this also doesn't hold for other aspect ratios.

What is a correct solution to find $inner_\theta$?

1

There are 1 best solutions below

3
On BEST ANSWER

If $(l,b),(L,B)$ are length and breadth dimensions of small and big rectangles respectively , then resolving components along $(x,y)$ axes

$$ l \cos \theta + b \sin \theta = L $$ $$ l\sin \theta + b \cos \theta = B $$

Using the first equation the rotation of inner strip can be solved

$$\theta_{best-fit}= \cos^{-1}\frac{L}{\sqrt{l^2+b^2}}+ \tan^{-1}\frac{b}{l}$$ EDIT1:

The second equation could as well be used to yield same result as the two equations are coupled.

Restrictions $ l> L,\, b<B $ should be followed.