# Perpendicular on a line from a given point that works in a 3rd Dimention.

Need help to find the perpendicular on a line segment within a 3-dimensional space from a given point? My line segment is defined as $(x_1, y_1,z_1), (x_2, y_2,z_2)$.

An answer I'd seen earlier Looked something like this but I am unsure as to how I would go about converting it to work with a 3-dimensional vector or if I'd even have to consider a completely different formula. $$k = \frac{(y_2-y_1)(x_3-x_1) - (x_2-x_1)(y_3-y_1)}{(y_2-y_1)^2 + (x_2-x_1)^2}\\ x_4 = x_3 - k(y_2-y_1)\\ y_4 = y_3 + k(x_2-x_1)$$

• I edited your question to be more readable, especiaally the math parts. Click the "edit" button on your question to see what I've done, or see this post for more guidance on how we format mathematics on this site. Also, please look through and see that I haven't introduced any mistakes during my edit. – Arthur Nov 2 '17 at 11:24

To echo J. Sadek’s sentiment, instead of memorizing formulas like this, you’d be better off understanding how they are derived. In this case, what you’re looking for is the perpendicular projection of a point $P_3$ onto the line through $P_1$ and $P_2$. This is usually accomplished via a dot product.

First, translate everything so that $P_1$ becomes the origin and the other two points become the vectors $\mathbf v = P_2-P_1$ and $\mathbf w = P_3-P_1$. For the projection of $\mathbf w$ onto $\mathbf v$ you want a vector with unit length parallel to $\mathbf v$, so set $\mathbf u={\mathbf v\over\|\mathbf v\|}$. The projection is then $$(\mathbf u\cdot\mathbf w)\mathbf u = \left({\mathbf v\over\|\mathbf v\|}\cdot\mathbf w\right){\mathbf v\over\|\mathbf v\|} = {\mathbf v\cdot\mathbf w\over\|\mathbf v\|^2}\mathbf v.$$ To get the point on the line, translate back by adding $P_1$ to this, i.e., $$P_1 + {(P_2-P_1)\cdot(P_3-P_1) \over(P_2-P_1)\cdot(P_2-P_1)}(P_2-P_1).$$ This works for any number of dimensions. It would be a good exercise for you to go back to the 2-D formula that you looked up and see how it’s derived from this projection.

• Thanks for this but the reason as to why I do like it out in a formula as shown, is because it's easier for me to understand. When people use the Symbols to simplified the expression of what is being explained I become lost. I'm also not trying to create a proof for something, but more so something I could convert into a program I'm making to return the desired point. – Dave Nov 2 '17 at 23:14
• @Dave It’s a simple matter to convert the general formula above into however many dimensions you’re working with. Just plug in the coordinate tuples and separate all of the parallel computations for $x$, $y$, $z$, ... etc. The ability to go from the general to the specific and the ability to generalize will make your writing programs a lot easer. The latter is what underlies abstraction and program factoring, after all. – amd Nov 2 '17 at 23:37

To find a vector on your line -scalar product -and the fact that sai vector should be in the plane foemed by the segment and the third point

Once you have this vector find the equation of the line by remembering that it passes through your third point

Don't memorize long formulas, it's useless.

• do you think you could expand on that explanation for me? I'm greatly interested. – Dave Nov 2 '17 at 23:15