1

Given a line $r$ from $a$ to $b$ and a point $c$, how can I find the point $d$ in $r$ whose distance to $c$ is minumum?

I know how to find the minimum distance between $r$ and $c$, but I'm struggling extending that equation to find $d$.

I think there must be a faster way to find $d$ than generating a sphere centered in $c$ with radius equals to the minimum distance between $r$ and $c$ and then checking the intersection point between this sphere and $r$. I'm also doing this in a programming language.

Daniel
  • 732
  • 1
    Is it a line or a line segment between point $a$ and $b$? Makes a difference. – Math Lover Jan 11 '21 at 16:49
  • This kind of problem has been addressed here many times before, such as here in two dimensions and even earlier there in three dimensions. This current Question fails to provide enough details to determine in what dimension the problem is posed. – hardmath Jan 11 '21 at 17:03
  • It's a segment but I think it doesn't matter. It's guaranteed that the minimum distance is inside the segment. – Daniel Jan 11 '21 at 17:12

2 Answers2

1

In order to find the point $d$, you can compute the gradient of the line r and find the coordinates on the line where the line carried by the gradient intersects c

NHL
  • 1,045
1

First project the vector $\vec{ac}$ onto the vector $\vec{ab}$, and then the minimizing point is located at $\vec{a} + \vec{ac}_\parallel$. Here $\vec{ac}_\parallel$ is the component of $\vec{ac}$ in the direction of $\vec{ab}$.

Sam Freedman
  • 3,989