Formula for the distance between two squares.

1.1k Views Asked by At

Picture two squares, both of side length $l$, located in a plane. I know the coordinates for both of their centers, $\vec r_i$, and the angle, $\theta_i$, between a vector pointing to an equivalent point on each one's perimeters from the center, and the $x$-axis. How can I calculate the distance between the points in each of their perimeters that are the closest?

So far I've tried to do:

$$ d^2=\min_{\phi_1,\phi_2}\left(\lvert\vec r_1-\vec r_2+\vec\rho_1(\phi_1)-\vec\rho_2(\phi_2)\rvert^2\right) $$

Where $\phi_i$ is a parameter describing the $i$-th square's perimeter, and

$$ \vec\rho_i(\phi_i)=l\left[\frac{1-\Theta(\phi_i)}{\lvert\cos\phi_i\rvert}+\frac{\Theta(\phi_i)}{\lvert\sin\phi_i\rvert}\right]\left(\begin{array}{c} \cos(\phi_i+\theta_i)\\ \sin(\phi_i+\theta_i)\end{array}\right)\\ \Theta(\phi)=\left\{\begin{array}{cc} 0&&\left(0<\phi<\frac{\pi}{4}\right) \vee \left(\frac{3\pi}{4}<\phi<\frac{5\pi}{4}\right)\vee \left(\frac{7\pi}{4}<\phi<2\pi\right)\\1&&\left(\frac{\pi}{4}<\phi<\frac{3\pi}{4}\right) \vee \left(\frac{5\pi}{4}<\phi<\frac{7\pi}{4}\right)\end{array}\right. $$

Up to this point, I have the partial derivatives of $d^2$, but solving for the parameters has proven to be incredibly difficult, and even Mathematica is refusing to do it.

Any suggestion will be much appreciated.