A line through a point meeting a given line at right angles, and the distance from a point to a line
Let A be a point and ℓ the line r = B + t d. Of all points of ℓ, one is closest to A: the foot of the perpendicular, C. The segment AC is perpendicular to ℓ, so AC · d = 0. Method 1. (1) Write a general point of ℓ as C = B + t d, with t still unknown. (2) Form AC = C − A, whose components contain t. (3) Put AC · d = 0: this is a linear equation in t. (4) Solve it, put t back to get C and AC. Then the distance from A to ℓ is ‖AC‖, and the line through A that meets ℓ at right angles is r = A + s·AC (in space there is just one line through A that meets ℓ at right angles; many other lines through A are perpendicular to ℓ in direction but never meet it). Method 2 uses the vector product and needs no unknown. Take any point B of ℓ. The parallelogram on BA and d has area ‖BA × d‖, and its base is ‖d‖, so its height, the distance from A to ℓ, is ‖BA × d‖/‖d‖. This gives the distance but not the foot. Check any answer by two tests: AC · d must be 0 and C must be on ℓ.
Shortest path. Put a pencil on a table as the line and a coin as the point A. Use a ruler to find the shortest distance from the coin to the pencil and notice where the ruler touches the pencil: that is the foot, and the ruler is perpendicular to the pencil.