Given a line and a point in 3D, how to find the closest point on the line?

11.8k Views Asked by At

I have a point given by $P = (P_x, P_y, P_z)$, and a line give by the two points $Q = (Q_x, Q_y, Q_z)$ and $R = (R_x, R_y, R_z)$. I'd like to know a general formula to figure out the closest point to $P$ that resides on the line $\overleftrightarrow{QR}$. I know that this involves finding a perpendicular line to $\overleftrightarrow{QR}$, but I don't know where to go from there.

Edit: Based on Emilio's answer, I came up with this formula to derive the point; $$\hat{t}=\frac{(R-Q)\cdot(Q-P)}{(R-Q)\cdot(R-Q)}$$ Where $\hat{t}$ is a scalar magnitude that can be used in the following formula.

$$G=Q-\hat{t}(R-Q)$$

Where $G$ is the point residing on the line $\overleftrightarrow{QR}$ closest to point $P$.

2

There are 2 best solutions below

1
On BEST ANSWER

Hint:

find the plane orthogonal to the given line and passing thorough the point $P$. The intersection of this plane with the line is the searched point.

0
On

What you can do is: 1.Take any general point on the given line in terms of any parameter. Let it be S(x,y,z). (Basically write the equation in cartesian form and then take x,y,z in the form of any parameter (let it be 'l'))

2.Now you have the vector PS.

3.As PS is perpendicular to the given line, it must be perpendicular to the direction ratios of the vector that the given line is parallel to.

4.Take the dot product of vector PS with the direction ratios of the given line and equate it to 0.(Dot product of non-zero perpendicular vectors is 0).

5.Now you have the parameter 'l' in terms of which you wrote the co-ordinates of S.

6.You now have the co-ordinates of S, so simply use distance formula to find the reqd. distance.