Consider that your rectangle drawn with perspective (using a vanishing point) forms a triangle when the sides are extended to the vanishing point. If you move your rectangle closer to the vanishing point the resulting triangle is similar to the original one. So the "rectangle" after moving it will be similar to the original. The distance from the front edge of the rectangle to the back edge will change as the rectangle moves based on the similar triangle calculation.
So the distance from the vanishing point scales things. Let $\left(x_v,y_v\right)$ be the screen coordinates of the vanishing point. Let your first (blue) rectangle have vertices $A_1,B_1,C_1,D_1$ and the second rectangle have vertices $A_2,B_2,C_2,D_2$ where $A_1$ corresponds to $A_2$ and so on. If you set the screen coordinates of $A_1$ to $\left(x_{a1},y_{ab1}\right)$, $B_1$ to $\left(x_{b1},y_{ab1}\right)$, $C_1$ to $\left(x_{c1},y_{cd1}\right)$, and $D_1$ to $\left(x_{d1},y_{cd1}\right)$ and if you choose the screen coordinates of $A_2$ to be $\left(x_{a2},y_{a2}\right)$ then calculate the screen coordinates of $B_2$ like this:
$x_{b2}=x_v+\left(x_{b1}-x_v\right)\frac{y_{a2}-y_v}{y_{a1}-y_v}$
$y_{b2}=y_{a2}$
The coordinates of $C_2$:
$x_{c2}=x_v+\left(x_{c1}-x_v\right)\frac{y_{a2}-y_v}{y_{a1}-y_v}$
$y_{c2}=y_v+\left(y_{cd1}-y_v\right)\frac{y_{a2}-y_v}{y_{a1}-y_v}$
And the coordinates of $D_2$:
$x_{d2}=x_v+\left(x_{d1}-x_v\right)\frac{y_{a2}-y_v}{y_{a1}-y_v}$
$y_{d2}=y_v+\left(y_{cd1}-y_v\right)\frac{y_{a2}-y_v}{y_{a1}-y_v}$
If you prefer to start with $\left(x,y\right)$ coordinates in the "real" $x$-$y$ plane and project them onto your screen coordinates then the problem is to find 2 functions that take $\left(x,y\right)$ to the screen coordinates $\left(x_s,y_s\right)$. That is a problem in differential equations.
Clearly from the similar triangle analysis:
$\frac{dy_s}{dy}=k_y\left(y_s-y_v\right)$
$y_s=y_v+C_ye^{k_yy}$
and:
$\frac{dx_s}{dx}=k_x\left(y_s-y_v\right)$
$x_s=C_x+k_xC_ye^{k_yy}x$
To make this work you must choose the screen coordinates of the vanishing point $\left(x_v,y_v\right)$ and the screen coordinates of the origin of your "real" $x$-$y$ plane $\left(x_0,y_0\right)$.
When $x=0$:
$x_s=C_x=x_v+\left(x_0-x_v\right)k_xC_ye^{k_yy}$
To make $x_s=x_0$ when $y=0$ we set:
$k_x=\frac{1}{C_y}$
So:
$C_x=x_v+\left(x_0-x_v\right)e^{k_yy}$
When $y=0$:
$y_s=y_0=y_v+C_y$
$C_y=y_0-y_v$
So the final formulas are:
$x_s=x_v+e^{k_yy}\left(x_0+x-x_v\right)$
$y_s=y_v+\left(y_0-y_v\right)e^{k_yy}$
Where $k_y$ is a scale factor that you can adjust to make the coordinates in the "real" $x$-$y$ plane map to the screen coordinates so everything fits on the screen.
Best Answer
Suppose that the unknown width and height are $x$ and $y$, and you’re given a diagonal $d$ and a ratio $m:n$ of width to height. That ratio means that the width is $\frac{m}{n}$ times the height, so you know that $x=\frac{m}{n}y$. You get a second relationship between $x$ and $y$ from the Pythagorean theorem: $x$, $y$, and $d$ are the lengths of the two legs and the hypotenuse of a right triangle, so $x^2+y^2=d^2$.
Now substitute $\frac{m}{n}y$ for $x$ in this second equation to get $\displaystyle\left(\frac{m}{n}y\right)^2 + y^2 = d^2$. Simplifying this, you get in turn: $$\frac{m^2}{n^2}y^2 + y^2 = d^2,$$ $$\left(\frac{m^2}{n^2}+1\right)y^2 = d^2,$$ $$\left(\frac{m^2+n^2}{n^2}\right)y^2=d^2,$$ and $$(m^2+n^2)y^2=d^2n^2.$$ Finally, solve for $y$: $\displaystyle y^2 = \frac{d^2n^2}{m^2+n^2}$, so $y=\displaystyle\frac{dn}{\sqrt{m^2+n^2}}$.
Once you have a numerical value for $y$, you can plug it into $x=\frac{m}{n}y$ to get a value for $x$.
(Or you can do that symbolically: $\displaystyle x=\frac{m}{n}\cdot \frac{dn}{\sqrt{m^2+n^2}} =$ $\displaystyle\frac{dm}{\sqrt{m^2+n^2}}$.)