I have a boundary given ($xMin$, $yMin$, $xMax$, $yMax$) and the two points of a reference line of a rectangle. The begin point is at $(x_b, y_b)$ and the end point is at $(x_e, y_e)$. This reference line tells the rectangle's angle and length.
If we transform the reference line so that it is parallel to the x-axis and its begin point is on the left of the end point, the outer side is above the inner side.
I need to get the four corners of the rectangle. The parallel sides is then categorized as outer side or inner side. So the four sides is represented by:
- begin point of outer side: $(x_{ob}, y_{ob})$
- begin point of inner side: $(x_{ib}, y_{ib})$
- end point of outer side: $(x_{oe}, y_{oe})$
- end point of inner side: $(x_{ie}, y_{ie})$
The width can now be computed as distance between the two begin or end points.
The perpendicular sides' slope is negative reciprocal of the reference line's slope: $$m=-\frac{x_e-x_b}{y_e-y_b}$$
The begin side has equation of (eq1): $$y=-\frac{x_e-x_b}{y_e-y_b}(x-x_b)+y_b$$ which is the same for the end side (eq2): $$y=-\frac{x_e-x_b}{y_e-y_b}(x-x_e)+y_e$$
After this, I am lost to what to do next. I know that I need to use the boundary values to substitute from eq1 and eq2.


Lets define
The slopes of the segments $\overline{B_oE_o}$ and $\overline{B_iE_i}$ have to be equal
$$m = \dfrac{y_{oe} - y_{ob}}{x_{oe} - x_{ob}} = \dfrac{y_{ie} - y_{ib}}{x_{ie} - x_{oib}}$$
Both of these segments are parallel to the line $y=mx$.
Assuming that $m$ is a negative number, we want to rotate the points through the angle $\theta$ where
$$\cos \theta = \dfrac{1}{\sqrt{1 + m^2}} \qquad \sin \theta = \dfrac{-m}{\sqrt{1 + m^2}}$$
So the rotations can be represented by
$\begin{pmatrix} \cos \theta & -\sin \theta \\ \sin \theta & \cos \theta \end{pmatrix} \begin{pmatrix} x \\ y \end{pmatrix} = \dfrac{1}{\sqrt{1+m^2}} \begin{pmatrix} 1 & m \\ -m & 1 \end{pmatrix} \begin{pmatrix} x \\ y \end{pmatrix} $
So
$B_o \mapsto \dfrac{1}{\sqrt{1+m^2}} \begin{pmatrix} 1 & m \\ -m & 1 \end{pmatrix} \begin{pmatrix} x_{ob} \\ y_{ob} \end{pmatrix}$
$B_i \mapsto \dfrac{1}{\sqrt{1+m^2}} \begin{pmatrix} 1 & m \\ -m & 1 \end{pmatrix} \begin{pmatrix} x_{ib} \\ y_{ib} \end{pmatrix}$
$E_o \mapsto \dfrac{1}{\sqrt{1+m^2}} \begin{pmatrix} 1 & m \\ -m & 1 \end{pmatrix} \begin{pmatrix} x_{oe} \\ y_{oe} \end{pmatrix}$
$E_i \mapsto \dfrac{1}{\sqrt{1+m^2}} \begin{pmatrix} 1 & m \\ -m & 1 \end{pmatrix} \begin{pmatrix} x_{ie} \\ y_{ie} \end{pmatrix}$
In the image shown below, $m = -\dfrac 34$ The rotation matrix turned out to be $\begin{pmatrix} 0.8 & -0.6 \\ 0.6 & 0.8 \end{pmatrix}$