4
$\begingroup$

In this code, I want to calculate distance between two lines SC and AB.

Clear["Global`*"]; assumptions = {a > 0, h > 0}; {aa, bb, cc} = SSSTriangle[a, a, a][[1]]; {pA, pB, pC} = PadRight[#, 3] & /@ {aa, bb, cc}; pS = {0, 0, h}; Simplify[ RegionDistance[InfiniteLine[{pS, pC}], InfiniteLine[{pA, pB}]], Assumptions -> assumptions] 

I only got enter image description here

How can I get the result?

PS. I work around

Clear["Global`*"]; assumptions = {a > 0, b > 0, c > 0, h > 0}; {aa, bb, cc} = SSSTriangle[a, a, a][[1]]; {pA, pB, pC} = PadRight[#, 3] & /@ {aa, bb, cc}; pS = {0, 0, h}; plane = InfinitePlane[pA, {pC - pS, pB - pA}]; Simplify[RegionDistance[plane, pC], Assumptions -> assumptions] 

and got

(Sqrt[3] a h)/Sqrt[3 a^2 + 4 h^2]

$\endgroup$
4
  • $\begingroup$ Second argument of RegionDistance should be a point. $\endgroup$ Commented May 8, 2024 at 11:40
  • 1
    $\begingroup$ RegionDistance not always work for two regions for symbolic. MinValue[ Norm[{x, y, z} - {u, v, w}], {x, y, z} ∈ InfiniteLine[{pS, pC}] && {u, v, w} ∈ InfiniteLine[{pA, pB}], {x, y, z, u, v, w}] $\endgroup$ Commented May 8, 2024 at 12:13
  • $\begingroup$ @azerbajdzan, please read the documentation for RegionDistance. The second usage case is RegionDistance[reg1,reg2]. $\endgroup$ Commented May 8, 2024 at 12:14
  • $\begingroup$ @Domen Mr. "I-know-It-All" please read documentation of RegionDistance for version 13. reference.wolfram.com/legacy/language/v13/ref/… $\endgroup$ Commented May 8, 2024 at 13:08

3 Answers 3

6
$\begingroup$

In 3D the minimum distance between the two lines can be expressed by the cross product as follows:

Abs[Dot[Normalize[Cross[pB - pA, pC - pS]], pS - pA]] 

Note, that this formula is only correct if Cross[pB - pA, pC - pS] is not the zero vector. If it vanishes, then the lines are either parallel and coplanar or identical.

$\endgroup$
5
$\begingroup$

You may define a point on a line from pS to pC and a second point on a line from pA to pB and minimize the distance between house points:

line1[t_] = pS + t (pC - pS); line2[t_] = pA + t (pB - pA); Minimize[{Norm[line1[t1] - line2[t2]], a > 0, h > 0}, {t1, t2}] 

enter image description here

As you can see, MMA gives a reasonable solution and a second one with an infinite distance. It is not clear to me, wherefrom this second solution comes.

$\endgroup$
4
$\begingroup$

It's slightly weird that it does not work, since it works if we rewrite RegionDistance for two regions as explained in the documentation:

RegionDistance[reg1,reg2] is effectively given by MinValue[Norm[p-q],{p∈reg1,q∈reg2}].

regionDistance[reg1_, reg2_] := MinValue[Norm[p - q], {p ∈ reg1, q ∈ reg2}] regionDistance[InfiniteLine[{pS, pC}], InfiniteLine[{pA, pB}]] 

enter image description here

$\endgroup$

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.