This question has been asked before in reference to 2D. This question extends it to 3D. How do I find the perpendicular intersected point on a line from a point in 3D space?
I did the calculation for the answer marked as Best Answer:
let alpha = [(x3-x1)(x2-x1) + (y3-y1)(y2-y1) + (z3-z1)(z2-z1)] / [(x2-x1)(x2-x1) + (y2-y1)(y2-y1) + (z2-z1)(z2-z1)]
point of intersection = (x1+alpha*(x2-x1), y1+alpha*(y2-y1), z1+alpha*(z2-z1)).