[Math] Given a line and a point in 3D, how to find the closest point on the line

3dgeometry

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

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.

Related Question