# How can I find distance from a point to a straight line by using projection of the point to the line?

I have a point A(1,2,3) and a line having parametric equation x = 1 + 2t, y = 3t, z = -4+6t. I want to find distance from A to the line. I tried with anotther way.

Clear["Global*"]
pA = {1, -2, -3};
f[t_] = {1 + 2 t, 3 t, -4 + 6 t};
pB = f[1];
pC = f[2];
d = InfiniteLine[pB, pC];
RegionDistance[d, pA]

Sqrt[14/5]

How can I find projection pH of the point A to the line and use EuclideanDistance[pA, pH]?

• RegionNearest ? Commented Mar 13 at 3:19
• …Isn't this essentially the same as your previous question?: mathematica.stackexchange.com/q/300322/1871 Or you're not aware of ParametricRegion? Commented Mar 13 at 3:20
• Clear[d]; pA = {1, -2, -3}; f[t_] = {1 + 2 t, 3 t, -4 + 6 t}; pB = f[1]; pC = f[2]; d = InfiniteLine[{pB, pC}]; RegionDistance[d, pA]; {EuclideanDistance[RegionNearest[d]@pA, pA], EuclideanDistance[RegionNearest[ParametricRegion[f[t], {t}]]@pA, pA]} , We note that d = InfiniteLine[{pB, pC}] or d = InfiniteLine[pB, pC-pB] instead of d = InfiniteLine[pB, pC] Commented Mar 13 at 3:53
• @cvgmt Thank you very much. Commented Mar 13 at 4:26

Clear["Global*"]

f[t_] := {1 + 2 t, 3 t, -4 + 6 t};

This line passes through {1, 0, -4}, but this information is not useful at this point. The direction of this line is:

dir = Coefficient[f[t], t] (* {2, 3, 6} *)

The vector from f[t] to pA is f[t]-pA and at the point of minimum distance the dot product of these vectors should be zero.

sol = (f[t] - pA) . dir == 0 // Solve[#, t] & // First

{t -> 0}

nearestpt = f[t] /. sol  (* {1, 0, -4} *)

EuclideanDistance[nearestpt, pA]

Sqrt[5]

Using @xzczd's suggestion in the comment:

reg = ParametricRegion[f[t], t] (* check RegionQ[reg] *)

{RegionNearest[reg, pA], RegionDistance[reg, pA]}

{{1, 0, -4}, Sqrt[5]}

Use an extra set of braces in your Line command.

pB = f[0];
pC = f[1];
d = InfiniteLine[{pB, pC}]
RegionDistance[d, pA]

Sqrt[5]

If you want to use Projection:

Projection[f[t] - pA, dir] == {0, 0, 0} // Solve[#, t] & // First

{t -> 0}

from which the same result follows.