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$
  • $\begingroup$ What have you tried? If you don't know where to start, I'd recommend looking at LocatorPane. $\endgroup$ – C. E. Oct 3 '18 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$ – user41667 Oct 3 '18 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 '18 at 15:34
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$
  • $\begingroup$ Thank you so much for your answer, it is super helpful. $\endgroup$ – user41667 Oct 3 '18 at 16:05
  • $\begingroup$ I posted my final code, just in case you want to see it :) Thank you again! $\endgroup$ – user41667 Oct 3 '18 at 17:04
  • 1
    $\begingroup$ I modified your code a bit; hopefully it's an improvement. $\endgroup$ – J. M. is slightly pensive Oct 3 '18 at 17:19

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.