1
$\begingroup$

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]?

$\endgroup$
4
  • 2
    $\begingroup$ RegionNearest ? $\endgroup$
    – cvgmt
    Commented Mar 13 at 3:19
  • $\begingroup$ …Isn't this essentially the same as your previous question?: mathematica.stackexchange.com/q/300322/1871 Or you're not aware of ParametricRegion? $\endgroup$
    – xzczd
    Commented Mar 13 at 3:20
  • 1
    $\begingroup$ 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] $\endgroup$
    – cvgmt
    Commented Mar 13 at 3:53
  • $\begingroup$ @cvgmt Thank you very much. $\endgroup$ Commented Mar 13 at 4:26

1 Answer 1

5
$\begingroup$
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]}


Regarding your attempt:

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.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.