find closest point of a line to another point

250 Views Asked by At

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.

2

There are 2 best solutions below

0
On

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

0
On

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}$.