# Will this method for finding perpendicular distance from point to 3D line work?

I'm trying to model a process by, and to do so I need to work with a 3 Dimensional line - I'm trying to come up with a method to both define it and find the perpendicular distance from the line to a given point $(P,Q,R)$. The line passes through the point $(a,b,c)$ - in the $XY$ plane, it makes an angle of $\theta$ with the normal, and in the $XZ$ plane is makes an angle of $\phi$ with the normal. These two angles I should be able to experimentally measure and the point is known. Firstly, can I use these pair of simple line equations to characterise my 3D line, so that I get the two equations;

$y = \tan(\theta)(X - a) + b$

$z = \tan(\phi)(X - a) + c$

Now, If this approach works (and I'm fully open to possibility it is wrong!) then can I find the perpendicular distance $D_{P}$ to the line by finding the perpendicular distances to both lines above (Let's call these distances $D_{1}$ and $D_{2}$) and then treating them like adjacent and opposite of right angled triangle so that $D_{p} = \sqrt{D_{1}^2 + D_{2}^2}$ ?

Please do let me know if this approach makes any sense and if it would work before I kill myself coding it up :)

I actually answered my own question. The first part is true; you can indeed define the 3D-Line with two 2D line equations. However, it's a little trickier to get the perpendicular distance. To do this, you re-arrange your line equations in symmetric form, or the form $$\frac{x - a}{A} = \frac{y - b}{B} = \frac{z - c}{C}$$ and define the line vector $S = (A,B,C)$. If $M_{0}$ is a point on the line, and $M_{1}$ is the point you wish to measure the perpendicular distance to, then $M_{0} M_{1}$ is the vector between these points, and the perpendicular distance is then given by $$D_{\operatorname{perp}} = \frac{|M_{0} M_{1} \times S|}{|S|}$$ Hope this helps!
Another way to define the perpendicular distance from your line $P_0+\langle \vec S\rangle$ (where $P_0$ is any point on the line, for instance $(0,b,c)$ in the question, and $\vec S$ is a vector giving the direction of the line) to a point $M_1$ is to write $M_0=P_0+t\vec S$ for an unknown scalar $t$, solve this $t$ from the equation $\vec S\perp\overrightarrow{M_0M_1}$ so that $M_0$ is now the orthogonal projection of $M_1$ on the line, and take $|\overrightarrow{M_0M_1}|$ as the distance. The equation to solve is equivalent to $\vec S\cdot\overrightarrow{P_0M_1}=t(\vec S\cdot\vec S)=t|\vec S|^2$.