I have 2 sets of data of points in 3D space. What I want to do is to find the minimum distance of pair of points from each set (so basically how close the sets can get to each other). For example, say

fst = {{2.22673,0.59492,2.6842},{3.13408,0.16181,1.63544}, 
sec = {{9.22673,0.59492,2.6842},{10.1341,0.16181,1.63544},

What I did was to first create list of all pairs

perm = Outer[List, fst, sec]

Then I applied the list to function EuclideanDistance[]

Min[EuclideanDistance @@ perm]

This apparently didn't work, because the distance function doesn't know how to read the coordinates. Is there a way around this?

  • $\begingroup$ Welcome! I suggest the following: 1) As you receive help, try to give it too, by answering questions in your area of expertise. 2) Take the tour and check the faqs! 3) When you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge. Remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign! $\endgroup$ – user9660 Aug 31 '16 at 16:03
  • 2
    $\begingroup$ Min[Outer[EuclideanDistance, fst, sec, 1]] You need to specify the level (4th argument) in Outer. Check out the docs. $\endgroup$ – Quantum_Oli Aug 31 '16 at 16:05
  • 2
    $\begingroup$ For large point sets it is more efficient to work with Nearest, like so. In[22]:= nf1 = Nearest[fst]; candidates = nf1[sec][[All, 1]]; mindist = Min[MapThread[EuclideanDistance, {sec, candidates}]] Out[24]= 3.95815195623 $\endgroup$ – Daniel Lichtblau Aug 31 '16 at 16:25
  • $\begingroup$ Ah, good point. Thank you! $\endgroup$ – psimanjuntak Sep 1 '16 at 13:03
  • 1
    $\begingroup$ Alternatively: Min@DistanceMatrix[fst, sec]. $\endgroup$ – user31159 Sep 12 '16 at 23:53

Browse other questions tagged or ask your own question.