3
$\begingroup$

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.

EDIT

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}]}, 
Row[{Panel[
LocatorPane[Dynamic[pt], Framed@Graphics[{}], 
 Appearance -> Flatten[Table[{"" <> ToString[i]}, {i, n}]]]], 
Dynamic[Panel[NumberForm[
  MatrixForm /@ With[{d = Outer[EuclideanDistance, pt, pt, 1]},
    {MatrixPlot[d, PlotLabel -> "Distances"], 
     MatrixPlot[Eigenvectors[d], 
      PlotLabel -> "Eigenvectors (Sorted)"], 
     Abs[Eigenvalues[d]]}], 4]]]}, Spacer[12]]]
$\endgroup$
3
  • $\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

5
$\begingroup$

As a starting point:

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

movable points and their distance matrix


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

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

new version

$\endgroup$
3
  • $\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.