Distance of closest approach of ellipse and line segment

Similarly to the definition of the distance of closest approach (DCA) for two arbitrary ellipses1 we define the DCA for an arbitrary ellipse and a line segment.

This distance is used in some models to calculate the repulsive force between a pedestrian and a wall2.

The quantity we are looking for is $$l$$ with:

$l = \parallel \vec{OP} \parallel − r − d$

$$P$$ is the nearest point on $$[AB]$$ to the ellipse. See also notes of P. Bourke3.

Knowing $$\alpha$$ we can easily calculate $$r$$. To solve the above mentioned equation
one has to find the quantity $$d$$, which would be the necessary amount to translate $$[AB]$$ along the direction of $$OP$$ such that it becomes tangential to the ellipse.

We have

$x_{R^\prime} = x_R − d \cdot \cos(\alpha) \;\; \rm{and} \;\; y_{R^\prime} = y_R − d \cdot \sin(\alpha).$

The parametric definition of the line segment $$[AB]$$ is:

$x_R = x_A +u\cdot(x_B −x_A)\;\; \rm{and}\;\; y_R = y_A + u\cdot(y_B −y_A); u \in [0, 1].$

$$x_{R^\prime}$$ is on the ellipse, which implies

$\frac{\Big(x_R − d \cdot cos(\alpha)\Big)^2}{a^2} + \frac{\Big(y_R − d \cdot sin(\alpha)\Big)^2}{b^2} = 1, \;\;\;\;\;\;\;\;\;\; [1]$

or

$p \cdot d^2 +q \cdot d+s=0, \;\;\;\;\;\;\;\;\;\; [2]$

with

$$$\begin{cases} p = cos(\alpha)^2 + sin(\alpha)^2 > 0,\\ q = −2\cdot \Big(\frac{x_R \cdot \cos(\alpha)}{a^2} + \frac{y_R \cdot \sin(\alpha)}{b^2}\Big),\; \rm{and}\\ s = \frac{x_R^2}{a^2} + \frac{y_R^2}{b^2}− 1.\\ \end{cases}$$$

In case the point $$R$$ is known the solution of Eq. (2) is

$d = \frac{-q - \sqrt{\Delta}}{2p},\;\; \rm{and}\;\; \Delta = q^2 - 4p\cdot s.$

However, in general $$R$$ is not known. Developing Eq. (1) with respect to $$u$$ yields

$p_1\cdot u^2 + q_1\cdot u + s_1 = 0,$

with

$$$\begin{cases} p_1 = \frac{x_{BA}^2}{a^2} + \frac{y_{BA}^2}{b^2} \ge 0,\\ q_1 = 2\cdot \Big(\frac{x_A - d\cdot \cos(\alpha)}{a^2}\cdot x_{BA} + \frac{y_A - d \cdot \sin(\alpha)}{b^2}\cdot y_{BA}\Big),\; \rm{and}\\ s_1 = \Big(\frac{x_A - d\cdot \cos(\alpha)}{a}\Big)^2 + \Big(\frac{y_A - d\cdot \cos(\alpha)}{b}\Big)^2− 1,\\ \end{cases}$$$

with the substitutions $$x_{BA}=x_B-x_A$$ and $$y_{BA} = y_B - y_A$$.

Since the line $$(AB)$$ is tangential to the ellipse we get

$\Delta = q_1^2 - 4\cdot p_1\cdot s_1 = 0,$

$q_1^2 = 4\cdot p_1\cdot s_1. \;\;\;\;\;\;\;\;\;\; [3]$

Supposing that $$P, A$$ and $$B$$ are not collinear, we solve (3) and get

$d_{1,2} = \frac{\pm a\cdot b\cdot \sqrt{p_1} - x_{BA} \cdot y_B + y_{BA}\cdot x_A}{y_{BA}\cdot \cos(\alpha) - x_{BA}\cdot \sin(\alpha)}$

and

$d = \min(|d_1|, |d_2|).$

For $$d$$ we calculate $$u$$ as

$u = \frac{-q_1}{2\cdot p_1}.$

If the inequality $$0 \le u \le 1$$ does not hold or $$P, A$$ and $$B$$ are collinear, then this would mean the point $$R$$ is an end point of $$[AB]$$, i.e. $$A$$ or $$B$$. In that case we solve (2) twice with $$R:=A$$ and $$R:=B$$ and get $$d= \min(|d_A|, |d_B|)$$.

References: