Given two functions: $F(x)$ and $G(x)$ is there is a way to find out the shortest distance between $F(x)$ and $G(x)$ provided we know that they do not intersect. I tried to consider parametric points on the two curves and applied the distance formula.The obvious step was then to minimize the function. However there are two problems: one is that it is quite tedious to differentiate the distance function and the foremost problem is that the function does is not a single variable function. Given these issues could anyone provide some insight into this problem?
Calculus – Shortest Distance Between Two General Curves Using MATLAB
calculus
Related Solutions
Let $\mathrm{x} := (x_1, x_2, x_3)$ and $\mathrm{y} := (y_1, y_2, y_3)$ be two free points in $\mathbb{R}^3$. The Euclidean distance between them is $\|\mathrm{x} - \mathrm{y}\|_2$. If we impose the constraint that each of these two points lie on each of the given lines, then we have the linear equality constraints
$$\begin{bmatrix} 1 & -1 & 0\\ 1 & 0 & -1\end{bmatrix} \mathrm{x} = \begin{bmatrix} 0\\ 0\end{bmatrix}$$
$$\begin{bmatrix} 1 & 1 & 0\\ 0 & 0 & 1\end{bmatrix} \mathrm{y} = \begin{bmatrix} 0\\ 2\end{bmatrix}$$
We want to minimize $\|\mathrm{x} - \mathrm{y}\|_2^2$ subject to these linear equality constraints. Thus, we have an equality-constrained quadratic program. The Lagrangian is the following
$$\mathcal{L} (\mathrm{x}, \mathrm{y}, \lambda, \mu) = \frac{1}{2} \|\mathrm{x} - \mathrm{y}\|_2^2 + \lambda \left(\begin{bmatrix} 1 & -1 & 0\\ 1 & 0 & -1\end{bmatrix} \mathrm{x}\right) + \mu \left(\begin{bmatrix} 1 & 1 & 0\\ 0 & 0 & 1\end{bmatrix} \mathrm{y} - \begin{bmatrix} 0\\ 2\end{bmatrix}\right)$$
There doesn't seem to be a nice closed-form solution to this, but the following might be helpful..
For an ellipse $\frac {x^2}{a^2}+\frac {y^2}{a^2}=1$, the equation of the normal at point $P(a \cos\theta, b\sin\theta)$ on the ellipse is
$$\frac {a\sin\theta}{b\cos\theta}x-y=a\left(\frac{a^2-b^2}{ab}\right)\sin\theta\tag{1}$$
A hyperbola which just touches or does not intersect at all with the ellipse above has the equation $xy=\frac {mab}2$ where $m\ge 1$. The equation of the normal at point $Q (v,\frac {mab}{2v})$ on the hyperbola is $$\frac {2v^2}{mab}x-y=v\left(\frac {2v^2}{mab}-\frac {mab}{2v^2}\right)\tag{2}$$
The minimum distance between the ellipse and hyperbola is the distance $PQ$ when $(1)=(2)$, i.e. both normals are the same line.
As the coefficients of $y$ are the same in both $(1),(2)$, equating coefficients of $x$ in $(1),(2)$ gives $$v=a\sqrt \frac{m\tan\theta}{2}\tag{3}$$ This relationship ensures that the tangents and normals at $P,Q$ are parallel to each other respectively (but the normals are not necessarily the same line).
Putting $(3)$ in $(2)$ gives
$$\left(\frac ab \tan\theta\right)x-y=a\sqrt{\frac{m\tan\theta} 2}\left(\frac ab\tan\theta-\frac ba\cot\theta\right)\tag{4}$$
To ensure that both normals are the same line, we need to equate RHS of $(1),(4)$. This gives $$\left(\frac{a^2-b^2}{ab}\right)\sin\theta=\sqrt{\frac{m\tan\theta}2}\left(\frac ab \tan\theta-\frac ba\cot\theta\right)$$ which is equivalent to $$(a^2-b^2)\sin\theta=\sqrt{\frac{m\tan\theta}2}\left(\frac{a^2\sin^2\theta-b^2\cos^2\theta}{\sin\theta\cos\theta}\right)\tag{4}$$
Solve numerically $\theta$ in $(4)$, find corresponding value $v$ in $(3)$, then calculate $PQ$. This should give the minimum distance between the ellipse and hyperbola.
See desmos implementation here.
In the trivial case where $a=b$ (i.e. ellipse is a circle), then $\theta=\frac \pi 4$ and $v=a\sqrt{\frac m2}$ . This gives $P=\left(\frac a{\sqrt{2}}, \frac a{\sqrt{2}}\right)$ and $Q=\left(a\sqrt{\frac m2}, a\sqrt{\frac m2}\right)$ and the distance $PQ=a(\sqrt m-1)$.
Best Answer
To answer, I assume $F(x)$ and $G(x)$ are continuous in $I \in \mathbb{R}, I = [a,b]$. For simplicity, let $F(x)=f, G(x) = g, H(x) = h = f-g$. By symmetry I can assume $f \ge g$. Now consider the function $h(x)$: