The shortest route
A line is given by r = a + t d: it passes through the point A with position vector a and runs in the direction d. P is a point off the line. The distance from P to the line means the shortest distance from P to any point of it.
Drop a perpendicular from P to the line and call its foot F. For any other point Q of the line, the triangle PFQ has a right angle at F, so PQ is its hypotenuse and is longer than PF. The shortest route is the perpendicular.
The line through A in the direction d, and the arrow from A to P at the angle to it. The gold perpendicular PF meets the line square on at F.
From the angle to the vector product
In the right triangle AFP the hypotenuse is AP and PF is the side opposite , so PF = |AP.
The vector product has exactly that sine in its length: |AP × d| = |AP. Dividing by |d| leaves PF = |AP × d| ÷ |d|. Writing d̂ = d ÷ |d| for the unit vector along the line, this is PF = |AP × d̂|.
Any point A of the line and any direction vector d along it give the same answer, because the triangle is the same triangle.
A worked example
The line passes through A = (1, 0, 0) in the direction d = (2, 1, 2), and P = (1, 3, 3). Then AP = P − A = (0, 3, 3).
AP × d = (3 × 2 − 3 × 1, 3 × 2 − 0 × 2, 0 × 1 − 3 × 2) = (3, 6, −6), of length . And . So the distance is 9 ÷ 3 = 3.
The foot of the perpendicular
F is the point A + t d for some t. The length of AF is the shadow of AP along the line, AP · d ÷ |d|, and dividing that by |d| once more turns it into a number of copies of d: t = AP .
Here AP · d = 0 + 3 + 6 = 9 and , so t = 1 and F = (1, 0, 0) + (2, 1, 2) = (3, 1, 2). Then PF = F − P = (2, −2, −1), of length , which agrees, and PF · d = 4 − 2 − 2 = 0 confirms the right angle.
Two more ways to the same foot
Write the vector from P to a general point of the line: A + t d − P = t d − AP = (2t, t − 3, 2t − 3). It is perpendicular to the line when its dot product with d is 0: 4t + (t − 3) + 2(2t − 3) = 9t − 9 = 0, so t = 1 again.
Or make its length as small as possible. Its square is . That is least when t = 1, and the least value is 9, so the distance is .
The usual slips
Stopping at |AP × d|: unless d is a unit vector, that length is the distance multiplied by |d|.
Giving AP · d ÷ |d| as the distance: that is how far along the line F is from A, the shadow, not how far P is from the line.
Taking t = AP · d or t = AP · d ÷ |d| for the foot: t counts copies of d, so the dot product is divided by .