Get the coordinates where the two rectangles meet First port here, don't hesitate in correcting me if I forgot to specify something essential in this post.
I have a little problem with some calculations I made, and I'm unable to solve this alone.
I'm using Optical Character Recognition (OCR) with Python to read some street signs. Most of the street signs are read correctly, but some of them are rotated, and so the OCR image frame and the street sign frame don't align with each other.
Image with the two rectangles - the black one being the OCR image frame, and the red one being the street sign

The width and height of the red rectangle (a, b) are in millimeters, and the width and height of the black rectangle (x, y) are in pixels.
Is there any way to know what which coordinates (in pixels) of the black rectangle, the red rectangle's vertexes touch? Is it actually even feasible?
Thank you for your help!
 A: If we call the small piece of the long side $w$ and the small piece of the vertical side $z$ we have
$$(x-w)^2+z^2=a^2\\(y-z)^2+w^2=b^2$$
and we are searching for $w,z$ if we know all the other variables.
$$x^2-2xw+w^2+z^2=a^2\\
y^2-2yz+z^2+w^2=b^2\\
x^2-y^2+2yz-2wx=a^2-b^2\\
w=\frac{x^2-y^2+2yz-a^2+b^2}{2x}$$
Plug this into one of the equations and you have a quadratic in $z$
A: If you really do have a rectangle within a rectangle, you could approach the problem as follows ...
Let $\theta$ be the small angle between $a$ and $x$ in your diagram.
I think that the ratio $r\equiv \frac xy$ is sufficient to calculate the angle $\theta$ , which is then sufficient to calculate the conversion factor between pixels and millimeters.
e.g. if we let $x_p$ represent the known length in pixels, then $x_p=cx$ ( $c$ has units of pixels per millimeter. )
In what follows, $x,y,a,b$ are all in millimeters
$$ \begin{eqnarray} 
x &=& b \sin \theta+a \cos \theta
\\ y &=& a \sin \theta+b \cos \theta
\\ \implies r= \frac xy &=& \frac{b +a\tan \theta}{a+b \tan \theta}
 \end{eqnarray} $$
which can be solved for $\theta$ ...
$$ \tan \theta=\frac{ b-ra}{rb-a }
$$
This can now be used to calculate $c$ ...
$$c=\frac{x_p}{x}=\frac{x_p}{b \sin \theta + a \cos \theta}
$$
Now your co-ordinates (in pixels) are things like $ac \cos \theta $ and $bc \sin \theta $
