I want to design a box in which I can move a set of items. Specifically, there should be N items (e.g. little balls with numbers inside). Items can be arranged with the mouse inside a box, and, in real time, I want the program that computes a matrix with the distance between every pair of objects and its eigenvectors. I want the distance matrix to have the items as image-labels in each axis. I would really appreciate some help here, I have been using Mathematica for statistical analysis, but never for graphical processing.


Thanks to the very generous help of J. M. , I found a way to do exactly what I wanted. Here is the code.

n = 10; (*Number of objects*)

DynamicModule[{pt = RandomReal[{-1, 1}, {n, 2}]}, 
LocatorPane[Dynamic[pt], Framed@Graphics[{}], 
 Appearance -> Flatten[Table[{"" <> ToString[i]}, {i, n}]]]], 
  MatrixForm /@ With[{d = Outer[EuclideanDistance, pt, pt, 1]},
    {MatrixPlot[d, PlotLabel -> "Distances"], 
      PlotLabel -> "Eigenvectors (Sorted)"], 
     Abs[Eigenvalues[d]]}], 4]]]}, Spacer[12]]]
  • $\begingroup$ What have you tried? If you don't know where to start, I'd recommend looking at LocatorPane. $\endgroup$
    – C. E.
    Oct 3, 2018 at 15:27
  • $\begingroup$ I looked at this post and I am trying to do something similar stackoverflow.com/questions/6299569/…. They use Manipulate[] $\endgroup$
    – statguy789
    Oct 3, 2018 at 15:30
  • $\begingroup$ It depends on what kind of UI you want. If you want to drag the pictures around then it's easiest to use LocatorPane. $\endgroup$
    – C. E.
    Oct 3, 2018 at 15:34

1 Answer 1


As a starting point:

DynamicModule[{pt = RandomReal[{-1, 1}, {5, 2}]}, 
                                     Graphics[{}, PlotRange -> 1], 
                                     Appearance -> "\[EmptyCircle]"]], 
                   NumberForm[Column[MatrixForm /@ 
                   With[{d = DistanceMatrix[pt]}, {d, Eigenvectors[d]}]], 4]]]},

movable points and their distance matrix

Here is a slight modification of the OP's version:

DynamicModule[{pt = RandomReal[{-1, 1}, {10, 2}]}, 
                                     Framed[Graphics[{}, PlotRange -> 1]], 
                                     Appearance -> Array[IntegerString, Length[pt]],
                                     LocatorAutoCreate -> True]], 
                           With[{d = DistanceMatrix[pt]}, 
                                Grid[{{MatrixPlot[d, PlotLabel -> "Distances"], 
                                                  PlotLabel -> "Eigenvectors (Sorted)"]},
                                      {NumberForm[Abs[Eigenvalues[d]], 4],
                                       SpanFromLeft}}]]]]}, Spacer[12]]]

new version

  • $\begingroup$ Thank you so much for your answer, it is super helpful. $\endgroup$
    – statguy789
    Oct 3, 2018 at 16:05
  • $\begingroup$ I posted my final code, just in case you want to see it :) Thank you again! $\endgroup$
    – statguy789
    Oct 3, 2018 at 17:04
  • 1
    $\begingroup$ I modified your code a bit; hopefully it's an improvement. $\endgroup$ Oct 3, 2018 at 17:19

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.