3

I am new to Mathematica so the answer to this question is probably easy.

I have a list of 2D-points in the form {{x1, y1}, {x2, y2}, ...} Then I have a function that will take two points and test some condition based on their distance. I want to test all points against each other, without duplicates.

How can you do that?

LCarvalho
  • 9,233
  • 4
  • 40
  • 96
user41279
  • 31
  • 1

1 Answers1

4

Based on comment from yode

Let us suppose a list:

list = {{1, 1}, {2, 1}, {7, 8}, {8, 9}}

$\left( \begin{array}{cc} 1 & 1 \\ 2 & 1 \\ 7 & 8 \\ 8 & 9 \\ \end{array} \right)$

With this function you can calculate the distances of each point without repetitions:

EuclideanDistance @@@ Subsets[list, {2}]

$\left\{1,\sqrt{85},\sqrt{113},\sqrt{74},10,\sqrt{2}\right\}$

Here below only a presentation of the steps

EuclideanDistance[list[[2]], list[[1]]]

$1$

EuclideanDistance[list[[3]], list[[1]]]

$\sqrt{85}$

EuclideanDistance[list[[4]], list[[1]]]

$\sqrt{113}$

EuclideanDistance[list[[2]], list[[3]]]

$\sqrt{74}$

EuclideanDistance[list[[2]], list[[4]]]

$10$

EuclideanDistance[list[[3]], list[[4]]]

$\sqrt{2}$

LCarvalho
  • 9,233
  • 4
  • 40
  • 96