How to find a rectangle's rotation amount that is inscribed inside an axis-aligned rectangle?

252 Views Asked by At

We have a rotated rectangle (the shaded shape) whose dimensions are determined through the parameters of $m$ and $n$. The rectangle is then enclosed inside an axis-aligned rectangle whose dimensions are represented through the $W$ and the $H$ parameters (the dashed box).

How may we calculate the rectangle's rotation amount with respect to the specified parameters? (named $\alpha$ in the figure below.)

How to find the rotation amount of an inscribed rectangle that is inside an axis-aligned rectangle


P.S.: The parametric dimensions of the shaded rectangle are considered after @dxiv's wise comment; indicating that without the further information, the issue if facing with insufficiency of information to uniquely determine the $\alpha$.

1

There are 1 best solutions below

5
On BEST ANSWER

(Too long for a comment.)  The problem is now overdetermined, after the latest edit. For solutions to exist, it is necessary that the projections onto the axes-aligned rectangle add up:

$$ \begin{align} n \cos(\alpha)+m\sin(\alpha)=W \\ n \sin(\alpha)+m\cos(\alpha)=H \end{align} $$

The first equation is equivalent to $\,\sin(\varphi+\alpha)= \dfrac{W}{\sqrt{m^2+n^2}}\,$, where $\,\varphi=\operatorname{arctan}\left(\dfrac{n}{m}\right)\,$. If this equation has solutions i.e. $\,\dfrac{W}{\sqrt{m^2+n^2}} \le 1\,$, and if the solutions also satisfy the second equation, then the answer is $\,\alpha = \arcsin\left({\dfrac{W}{\sqrt{m^2+n^2}}}\right)-\arctan\left(\dfrac{n}{m}\right)\,$ normalized to the $1^{st}$ quadrant.


[ EDIT ]  Regarding the question "could the problem be solved when having only m in hand (but not the n) or vice-versa", the answer is affirmative but the solution amounts to solving a quartic equation. With the Weierstrass substitution in $\,t = \tan(\alpha / 2)\,$, the equations become:

$$ \begin{align} n (1-t^2)+2mt=W(1+t^2) \\ 2n t+m(1-t^2)=H(1+t^2) \end{align} $$

Eliminating $\,n\,$ between the equations gives the quartic in $\,t\,$:

$$\require{cancel} 2t \big(\cancel{n (1-t^2)}+2mt\big) - (1-t^2)\big(\cancel{2n t}+m(1-t^2)\big) = 2t(1+t^2)W-(1-t^2)(1+t^2)H $$