Basically I have two rectangles. ABCD and EFGH
EFGH is rotated around it's centre point (X)
ABCD has centre point (W)
I also know for the sake of this example that EFGH is rotated counter clockwise at 45°
I am trying to do this for all corners but basically
What I am trying to figure out is how much do I need to translate ABCD by such that when rotated at 45° around its centre point (W), the corner B will be equal to point F. (See blue square as a rough example)
Basically Im trying to solve for what coordinates does the centre W have to be such that after rotation around it B is equal to F

I've spent ages trying to figure this out and I can't come up with anything. I'm not too familiar with matrices.
I tried calculating the distance and angle of WB, and since I know what F is i could say
x = WB * cos (WB°+45°)
y = WB * sin (WB°+45°)
But Fx = x + x2(origin)
And Fy = y + y2(origin)
x2 = Fx - x
y2 = Fy-y
Trying to solve for new 'origin' of ABCD, but to no avail..
Let $X=(0,0)$ and let $W=(a,b)$. Call $S_X, S_W$ the respective squares, $S_X', S_W'$ after rotation.
$$S_X : (a\pm EF/2, b\pm EF/2)$$
$$S_W : (\pm AB/2, \pm AB/2)$$
After rotation:
$$S_X' : (a, b\pm \sqrt{2}/2EF),(a\pm \sqrt{2}/2EF, b)$$
$$S_W' : (0, \pm \sqrt{2}/2AB), (\pm \sqrt{2}/2AB,0)$$
(you can get this by multiplying the coordinates by the rotation matrix.)
If you want to line up $B$ and $F$ then you want real numbers $s,t$ such that
$$(s, \sqrt{2}/2AB+t)=(a, b+ \sqrt{2}/2EF)$$
So $$(s,t)= (a,b+\sqrt{2}/2(EF-AB))$$
Edit
Here is an interactive plot I made for you. First both squares of specified length are rotated by 45 degrees. Then the square centered at the origin is translated by the amount specified above.
For rectangles, rather than go through a whole 'nother derivation, the value of $s,t$ you seek is:
$$\left[\begin{matrix}s\\ t\end{matrix}\right]=\left[\begin{matrix}a\\ b\end{matrix}\right]+\left[\begin{matrix}\cos\theta & -\sin\theta\\ \sin\theta & \cos\theta\end{matrix}\right]\left[\begin{matrix}F_x-B_x-a\\ F_y-B_y-b\end{matrix}\right]$$
Another example for rectangles, rotating $270^o$