Distance from a Point to a Line in R3

Distance From a Point to a Line in R3
Suppose that r=r0+tm is a line in R3and Q(x0, y0)is a point on this line.
The shortest distance between a point P(x1, y1) and this line is d=∣∣m∣∣QP×m or d=∣∣QP∣∣sinθ.

Example
Find the shortest distance between the point (1, 0, −1) annd the line r=[1, 1, 2]+t[0, −1, −1]
A point on the line is Q=(1,1,2), the point we are given is P(1,0,−1)
QP=[1,0,−1]−[1,1,2]=[0,−1,−3]
The direction vector is m=[0,−1,−1].
Using the formula:
d=∣∣[0,−1,−1]∣∣∣∣[0,−1,−3]×[0,−1,−1]∣∣
d=02+(−1)2+(−1)2∣∣[−2, 0, 0]∣∣
d=222+02+02
d=22
d=22×22
d=222
d=2

Example: Closest Point on a Line
a) Find the coordinates of the point on the line r=[1,0,−1]+t[−1,1,−1] that is closest to the point P(0,2,1).
b) Find the shortest distance between the point P(0,2,1) and the line.
a) Let Q(x0,y0,z0) be the point on the line that is closest to P.
First, let's rewrite the line into parametric form:
x=1−ty=tz=−1−t
So, Q is of the form (1−t,t,−1−t) for some value of t∈R.
We know that the position vector QP is perpendicular to the line:
The position vector is QP=[0,2,1]−[1−t,t,−1−t]=[−1+t,2−t,2+t]
Since this is perpendicular to the line, the dot product between this position vector and the line's direction vector should be 0:
QP⋅m=0
[−1+t,2−t,2+t]⋅[−1,1,−1]=0
1−t+2−t−2−t=0
1−3t=0
t=31
Therefore, the point on the line closest to the point P is (1−31, 31, −1−31), which is (32, 31, −34)
b) The shortest distance is QP
QP=[0,2,1]−[32, 31, −34]=[−32, 35, 37]
∣∣QP∣∣=(−32)2+(35)2+(37)2=94+25+49=326
Practice: Reflection of a Point
Find the coordinates of the point obtained by reflecting the point P(1, 2, −3) along the line r=[0, 1, 0]+t[1,0, −1].