Calculate the average distance from segment to line segment and line segment to segment

I am looking for an algorithm to calculate the average distance between a point and a line segment in 3D. Therefore, there are two points A (x1, y1, z1) and B (x2, y2, z2) that represent the segment AB, and the third point C (x3, y3, z3), what is the average distance between each point on AB on the point C ?

I am also interested in the average distance between two segments of the line. So, given the segment AB and CD, what is the average distance from each point on AB to the nearest point on CD?

I was not lucky with the internet searches I tried, so any suggestions would be appreciated.

Thank.

+5
source share
3 answers

, , , "" ( "", L2, ), , , , , dot(A,B), .

// given vectors (points) A, B, C
K1 = dot(A-C,A-C)
K2 = 2*dot(B-A,A-C)
K3 = dot(B-A,B-A)
L1 = sqrt(K3*(K1+K2+K3))
L2 = sqrt(K3*K1)
N = 4*K3*L1 + 2*K2*(L1-L2) + (K2*K2-4*K1*K3)*log((K2+2*L2)/(2*K3+K2+2*L1))
D = N / (8*K3^1.5)

, , D .

, Mathematica. - , , . ( , , )

- AB, C, D, , , (, , ). - CD AB , , .

CD AB... , , , .

+1

-, . (, (0,0,0) (1,1,1) sqrt (3), .) l2-norm ( L) . (A, B) A B.

... ( , . , , , .)

C AB, A B, (1-k) A + kB, k 0 1. (C, (1-k) A + kB). , k = 0 1 (C, (1-k) A + kB).

Mathematica A, B C.

Mathematica:

avgd[A_,B_,C_] :=  Integrate[Sqrt@Dot[(1-k)*A+k*B-C, (1-k)*A+k*B-C], {k, 0, 1}]

Norm[(1-k)*A+k*B-C]. , Mathematica , , , -, -. :

> avgd[{0, 0, 0}, {4, 0, 0}, {4, 3, 0}] // N

3.73594

, , , :

avgd[A_,B_,C_,D_] := Integrate[Norm[(1-k)A+k*B - (1-j)C - j*D], {k,0,1}, {j,0,1}]

Mathematica, , , .

+2

, , , ...

Mathematica. , , 2D . , {0,0} {1,0} {0,1}. , , , {0.0} . , , , , 10. Mathematica

Mean[Table[EuclideanDistance[{0, 0}, {1 - k, 0 + k}], {k, 0, 1, 10.0^-1}]]]

0.830255. , . , , 10.0 ( !). Mathematica:

Table[Mean[Table[EuclideanDistance[{0, 0}, {1 - k, 0 + k}], {k, 0, 1, 
10.0^-i}]], {i, 0, 6}]

:

{1, 0.830255, 0.813494, 0.811801, 0.811631, 0.811615, 0.811613}

, @Dave ( ):

Table[Mean[Table[EuclideanDistance[{0, 0}, {4, 0 + 3 k}], {k, 0, 1, 
10.0^-i}]], {i, 0, 6}]

:

{9/2, 4.36354, 4.34991, 4.34854, 4.34841, 4.34839, 4.34839}

, @dreeves , @Dave .

EDIT: , . , , , ​​ {0,0} {0,1} {1,0}, Mathematica ( ), :

fun2[k_] := EuclideanDistance[{0, 0}, {0 + k, 1 - k}]

. Mathematica :

   In[13]:= Integrate[fun2[k], {k, 0, 1}]

   Out[13]= 1/4 (2 + Sqrt[2] ArcSinh[1])

, , :

In[14]:= NIntegrate[fun2[k], {k, 0, 1}]
Out[14]= 0.811613

, .

Now I will return to work and leave it to everyone to generalize this to an arbitrary triangle defined by a point and end points of a segment.

+1
source

All Articles