Validate movable $\Delta x$ and $\Delta y$ of outer rectangle ensuring inner rectangle still within the outer one? As in image below, both the green and red rectangle are rotated with the same angle. Now green rectangle is movable by user but the location of red rectangle is fixed. How do I validate the $\Delta x$ and $\Delta y$ move by user so that the green rectangle can honor user's move direction and distance, yet restrict the green rectangle bounds so that it cannot make the red one overlap with itself? Thanks.

 A: 
In $\mathrm{Fig.\space 1}$, we have given the necessary formulae needed for validating the movement of the green rectangle. There are four sets of equations and each set contains two equations for calculating the sizes of the displacements $w$ and $h$ of the green rectangle parallel to its sides. These two values are expressed in terms of $\Delta x$, $\Delta y$, and $\phi$ assuming you know their numerical values. By the way, $\phi$ is the angle between the $x$-axis and one of the sides of the rectangles. For a given displacement, only one set of equations should be used to calculate $w$ and $h$, the values of which can be then compared with certain values of the initial state to check whether the displacement of green rectangle has managed to keep the red rectangle within its boundary or not.
Deriving the formulae is a straightforward exercise. Still, we decided to show you how we did it by explaining below the three-step derivation of $w$ and $h$ for a move, which can be resolved in to a combination of a rightward displacement of $\Delta x$ and an upward displacement of $\Delta y$.
Assume that the vertex $A_o$ of the green rectangle has been moved to a point $A$. This can be resolved in to two components $\Delta x$ and $\Delta y$ parallel to the $x$- and $y$-axis respectively as shown in $\mathrm{Fig.\space 1}$. The same displacement can be resolved in to two components $w (=A_oF)$ and $h (=FA)$ parallel to the sides of the rectangles. Now we have,
$$ \measuredangle EAF = \measuredangle EA_oF = \phi.$$
Therefore,
$$w = \lvert\Delta x\rvert\cos \left(\phi\right) - \lvert\Delta y\rvert\sin \left(\phi\right)\quad \text{and}$$
$$\space h = \lvert\Delta x\rvert\sin \left(\phi\right) + \lvert\Delta y\rvert\cos \left(\phi\right).\enspace\qquad$$
Now, the conditions, which a shift of the green rectangle should be satisfy to keep the red rectangle within its boundary, can be expressed as
$$\left.\text{If}\quad
\begin{array}{l}
w \le w_r\\
h \le h_u
\end{array}
\right\}
\quad\text{the red rectangle lies within the boundary of the green rectangle.}$$
To make use of this test you should be aware of the values of $w_r$ and $h_u$. As you can see they are the coordinates of the vertex $A_i$ of the red rectangle with respect to a rotated Cartesian coordinate system, the origin of which is located at the vertex $A_o$ of the green rectangle.
As mentioned earlier only one set of equations should be used to calculate $w$ and $h$ needed for validating a given displacement of the green rectangle. But, how can we choose the appropriate set? It is simple. You only need to follow the rules and tests given below to do that.
$\underline{\text{Rules for selecting the formulae set}}$
(1.)$\enspace$ If the given displacement can be resolved in to a combination of
$\qquad\quad$ a rightward displacement of $\Delta x$ and an upward displacement of $\Delta y\quad \bf{or}$
$\qquad\quad$ a leftward displacement of $\Delta x$ and an downward displacement of $\Delta y,$
$\quad\enspace\space$ then use the set
$$w = \lvert\Delta x\rvert\cos \left(\phi\right) - \lvert\Delta y\rvert\sin \left(\phi\right)$$
$$\space h = \lvert\Delta x\rvert\sin \left(\phi\right) + \lvert\Delta y\rvert\cos \left(\phi\right).$$
(2.)$\enspace$ If the given displacement can be resolved in to a combination of
$\qquad\quad$ a rightward displacement of $\Delta x$ and an downward displacement of $\Delta y\quad \bf{or}$
$\qquad\quad$ a leftward displacement of $\Delta x$ and an upward displacement of $\Delta y,$
$\quad\enspace\space$ then use the set
$$w = \lvert\Delta x\rvert\cos \left(\phi\right) + \lvert\Delta y\rvert\sin \left(\phi\right)$$
$$\space h = \lvert\Delta y\rvert\cos \left(\phi\right) - \lvert\Delta x\rvert\sin \left(\phi\right).$$
$\underline{\text{Displacement validating tests}}$
(1.)$\enspace$ If the given displacement can be resolved in to a combination of a rightward displacement of$\qquad$ $\Delta x$ and an upward displacement of $\Delta y$, then the conditions to be satisfied are,
$$w \le w_r\qquad\text{and}\qquad h \le h_u.$$
(2.)$\enspace$ If the given displacement can be resolved in to a combination of a leftward displacement of$\qquad$ $\Delta x$ and an upward displacement of $\Delta y$, then the conditions to be satisfied are,
$$w \le w_l\qquad\text{and}\qquad h \le h_u.$$
(3.)$\enspace$ If the given displacement can be resolved in to a combination of a leftward displacement of$\qquad$ $\Delta x$ and a downward displacement of $\Delta y$then the conditions to be satisfied are,
$$w \le w_l\qquad\text{and}\qquad h \le h_d.$$
(4.)$\enspace$ If the given displacement can be resolved in to a combination of a rightward displacement of$\qquad$ $\Delta x$ and a downward displacement of $\Delta y$then the conditions to be satisfied are,
$$w \le w_r\qquad\text{and}\qquad h \le h_d.$$
Here is the reason why this method works. For example, consider a shift of the green rectangle, which can be resolved in to combination of a rightward displacement of $\Delta x$ and an upward displacement of $\Delta y$. As long as this shift does not let the vertex $A_o$ of the green rectangle overstep $A_iT$ and $A_iM$, its sides $A_oB_o$ and $A_oD_o$ have no chance of encroaching upon the area occupied by the fixed red rectangle.
