Given a 2D parametric curve $(x(s), y(s))$ and a rectangle where each of the four vertices is parameterized $(x_i(t), y_i(t))$, $i \in \{1,2,3,4\}$, how can Mathematica compute the distance function $d$ where $d(t)$ is the distance of the rectangle at $t$ to the parametric curve with $s \in [a,b]$? The algorithm should yield $d(t) = 0$ if the rectangle and the curve share a common point.
Here is an example of a parametric curve {xc, yc}
(parameter s
) and a rectangle {{xr1, yr1}, {xr2, yr2}, {xr3, yr3}, {xr4, yr4}}
(parameter t
).
{xc, yc} = {x[s], y[s]} /.
NDSolve[{theta'[s] == 1, x'[s] == Cos[theta[s]],
y'[s] == Sin[theta[s]], theta[0] == 0, x[0] == 0,
y[0] == 0}, {theta, x, y}, {s, 0, 10}][[1]];
{xr1, yr1, theta} = {x[t], y[t], theta[t]} /.
NDSolve[{theta'[t] == 1 + Sin[12 t], x'[t] == Cos[theta[t]],
y'[t] == Sin[theta[t]], theta[0] == 0, x[0] == 0,
y[0] == 0}, {theta, x, y}, {t, 0, 10}][[1]];
{xr2, yr2} = {xr1, yr1} + 0.05 Normalize[{-Sin[theta], Cos[theta]}];
{xr3, yr3} = {xr2, yr2} + 0.05 Normalize[{-Cos[theta], -Sin[theta]}];
{xr4, yr4} = {xr1, yr1} + 0.05 Normalize[{-Cos[theta], -Sin[theta]}];
Manipulate[
Show[ParametricPlot[{xc, yc}, {s, 0, 4}],
Graphics[Polygon[{{xr1, yr1}, {xr2, yr2}, {xr3, yr3},
{xr4, yr4}} /. {t -> T}]]], {T, 0.01, 4}]