[Math] Find distance between 3d point and 3d curve

multivariable-calculusvectors

I have a 3 dimensional curve given by the equation:

$$\begin{bmatrix}x_0 \\ y_0 \\ z_0 \end{bmatrix} +t\begin{bmatrix}a \\ b \\ c \end{bmatrix}+t^2\begin{bmatrix}0 \\ 0 \\ g \end{bmatrix}$$

How do I find the smallest distance between this curve and a vector like$\begin{bmatrix}x \\ y \\ z \end{bmatrix}$. I tried to calculate distance in terms of t and take the derivative but it got very complex very quickly. Is there a simpler way of doing this or do I need to just keep plugging away at the derivative?

Best Answer

Let's say you have $$\vec{p}_0 = \left [ \begin{matrix} x_0 \\ y_0 \\ z_0 \end{matrix} \right ], \quad \vec{p}_1 = \left [ \begin{matrix} x_1 \\ y_1 \\ z_1 \end{matrix} \right ], \quad \vec{p}_2 = \left [ \begin{matrix} x_2 \\ y_2 \\ z_2 \end{matrix} \right ], \quad \vec{q} = \left [ \begin{matrix} x \\ y \\ z \end{matrix} \right ]$$ and a curve $\vec{p}(t)$, $$\vec{p}(t) = \vec{p}_0 + t \vec{p}_1 + t^2 \vec{p}_2 = \left [ \begin{matrix} x_0 + t x_1 + t^2 x_2 \\ y_0 + t y_1 + t^2 y_2 \\ z_0 + t z_1 + t^2 z_2 \end{matrix} \right ]$$ The squared length of the vector from point $\vec{q}$ to point $\vec{p}(t)$ is $$\begin{aligned} s(t) &= (\vec{p}(t) - \vec{q}) \cdot (\vec{p}(t) - \vec{q}) \\ \; &= (t^2 x_2 + t x_1 + x_0 - x)^2 + (t^2 y_2 + t y_1 + y_0 - y)^2 + (t^2 z_2 + t z_1 + z_0 - z)^2 \end{aligned}$$ If you expand the above, you get $$s(t) = C_4 t^4 + C_3 t^3 + C_2 t^2 + C_1 t + C_0$$ where $$\begin{aligned} C_4 &= x_2^2 + y_2^2 + z_2^2 \\ C_3 &= 2 x_1 x_2 + 2 y_1 y_2 + 2 z_1 z_2 \\ C_2 &= x_1^2 + y_1^2 + z_1^2 + 2 x_2 (x_0 - x) + 2 y_2 (y_0 - y) + 2 z_2 (z_0 - z) \\ C_1 &= 2 x_1 (x_0 - x) + 2 y_1 (y_0 - y) + 2 z_1 (z_0 - z) \\ C_0 &= (x_0 - x)^2 + (y_0 - y)^2 + (z_0 - z)^2 \end{aligned}$$ i.e. $$\begin{aligned} C_4 &= \vec{p}_2 \cdot \vec{p}_2 \\ C_3 &= 2 \vec{p}_1 \cdot \vec{p}_2 \\ C_2 &= \vec{p}_1 \cdot \vec{p}_1 + 2 \vec{p}_2 \cdot (\vec{p}_0 - \vec{q}) \\ C_1 &= 2 \vec{p}_1 \cdot (\vec{p}_0 - \vec{q}) \\ C_0 &= (\vec{p}_0 - \vec{q}) \cdot (\vec{p}_0 - \vec{q}) \end{aligned}$$ $s(t)$ reaches an extremum (minimum or maximum value) when its derivative is zero, i.e. $$\frac{d\,s(t)}{d\,t} = 4 C_4 t^3 + 3 C_3 t^2 + 2 C_2 t + C_1 = 0$$ This is a cubic equation in $t$, and has zero, one, two, or three real roots $t \in \mathbb{R}$. The algebraic solutions are known.