2
$\begingroup$

I've been searching all around the "Documentation Center" and other forums and just can't get to solve this issue. I'd like to dynamically locate a point (get it's coordinates) inside a Manipulate. This point is in fact a function of another parameter (hence the Manipulate).

Here's the setup. First I create the functions that will provide with the points coordinates :

T01[q1_] = {{Cos[q1 Degree], 0, Sin[q1 Degree], 0}, {0, 1, 0, 
0}, {-Sin[q1 Degree], 0, Cos[q1 Degree], 0}, {0, 0, 0, 
1}}; (*Matrice de passage de R0 à R1*) 

T12[q2_, l1_] = {{Cos[q2 Degree], 0, Sin[q2 Degree], 0}, {0, 1, 0, 
    0}, {-Sin[q2 Degree], 0, Cos[q2 Degree], -l1}, {0, 0, 0, 
    1}}; (*Matrice de passage de R1 à R2*)

T02[q1_, q2_, l1_] = 
  T01[q1].T12[q2, l1]; (*Matrice de passage de R0 à R2*)

E2[l2_] = {0, 0, -l2, 1}; (*position de l'effecteur dans le repère R2*)

E0[q1_, q2_, l1_, l2_] = 
  T02[q1, q2, l1].E2[l2]; (*position de l'effecteur dans R0*)

O22 = {0, 0, 0, 1};(*position du centre articulaire O2 dans R2*)

O20[q1_, q2_, l1_] = T02[q1, q2, l1].O22;(*position de 02 dans R0*)

O11 = {0, 0, 0, 1};(*position de O1 dans R1*)

O10[q1_, q2_] = T01[q1].O11;(*position de O1 dans R0*)

I'm in fact interested in showing the $E_0$ coordinates dynamically if possible inside the manipulate window...

So then I create the Manipulate environment which shows a double pendulum parameterized by the $q_1$ and $q_2$ variables :

Manipulate[
 ListLinePlot[
  {
   {O10[q1, q2][[1]], O10[q1, q2][[3]]}, {O20[q1, q2, 400][[1]], 
    O20[q1, q2, 400][[3]]}, {E0[q1, q2, 400, 300][[1]], 
    E0[q1, q2, 400, 300][[3]]}
   }, PlotRange -> {{-710, 710}, {-710, 710}}, 
  AspectRatio -> Automatic, PlotMarkers -> Automatic, Ticks -> None
  ], {{q1, 5, "\!\(\*SubscriptBox[\(q\), \(1\)]\)"}, -170, 
  170}, {{q2, 5, "\!\(\*SubscriptBox[\(q\), \(2\)]\)"}, -170, 170}
 ]

I tried the Locator function without success, also I tried the Dynamic function but I just couldn't get to make it work for the $E_0$ variable...

Does anybody has any idea that might help?

Thanks in advance.

$\endgroup$

3 Answers 3

4
$\begingroup$
  Manipulate[ListLinePlot[
  Tooltip@ {{O10[q1, q2][[1]], 
  O10[q1, q2][[3]]}, {O20[q1, q2, 400][[1]], 
  O20[q1, q2, 400][[3]]}, {E0[q1, q2, 400, 300][[1]], 
  E0[q1, q2, 400, 300][[3]]}}, 
  PlotRange -> {{-710, 710}, {-710, 710}}, AspectRatio -> Automatic, 
  PlotMarkers -> Automatic,  Ticks -> None], 
  {{q1, 5, Subscript["q", 1]}, -170,  170}, 
  {{q2, 5, Subscript["q", 2]}, -170, 170}]

enter image description here

Update: Displaying the current value of E0

To display E0 outside Manipulate one can use the Manipulate option LocalizeVariables->False and put the label insideDynamic -- as the OP did in his answer. Displaying inside Manipulate can be done in several ways:

Using PlotLegends: Add the following option to ListLinePlot

 PlotLegends -> Placed[Row[{"E0  = ", 
  MatrixForm[ N@{E0[q1, q2, 400, 300][[1]], E0[q1, q2, 400, 300][[3]]}]}],  Above]
 (* or, if you like, Below, Left, Right ... instead of Above *)

Using PlotLabel: Use the option setting

 PlotLabel -> Row[{"E0  = ", 
  MatrixForm[ N@{E0[q1, q2, 400, 300][[1]], E0[q1, q2, 400, 300][[3]]}]}]

Using Column: Change the first argument of Manipulate to

 Column[{Row[{"E0  = ", 
  MatrixForm[ N@{E0[q1, q2, 400, 300][[1]], E0[q1, q2, 400, 300][[3]]}]}], 
 ListLinePlot[ Tooltip@{{O10[q1, q2][[1]],  O10[q1, q2][[3]]}, {O20[q1, q2, 400][[1]], 
  O20[q1, q2, 400][[3]]}, {E0[q1, q2, 400, 300][[1]],  E0[q1, q2, 400, 300][[3]]}}, 
 PlotRange -> {{-710, 710}, {-710, 710}}, AspectRatio -> Automatic, 
 PlotMarkers -> Automatic, Ticks -> None]}, Center]
$\endgroup$
1
  • $\begingroup$ Well, that was helpful! Thanks a lot! Now, I was wondering if perhaps, it would be possible to actually $display$ those coordinates dynamically on top of the manipulate screen... It's ok if it is not possible, I still find the Tooltip option very useful! Thanks again! $\endgroup$
    – Meclassic
    Jan 22, 2013 at 14:20
3
$\begingroup$

In addition to the code supplied by kguler I would like to answer your slightly hidden question at the end of your own answer. Manipulate is a very powerful concept in Mathematica. You can put nearly everything inside a Manipulate. For your problem, I created a Column consisting of the ListLinePlot and a Row containing the current E0 vector.

Manipulate[
 Column[{ListLinePlot[Tooltip@{{O10[q1, q2][[1]], 
       O10[q1, q2][[3]]}, {O20[q1, q2, 400][[1]], 
       O20[q1, q2, 400][[3]]}, {E0[q1, q2, 400, 300][[1]], 
       E0[q1, q2, 400, 300][[3]]}}, 
       PlotRange -> {{-710, 710}, {-710, 710}}, AspectRatio -> Automatic,
       PlotMarkers -> Automatic, Ticks -> None],
   Spacer[4],
   Row[{"\!\(\*SubscriptBox[\(E\), \(0\)]\)=", {E0[q1, q2, 400, 300][[1]], 
   E0[q1, q2, 400, 300][[3]]} // MatrixForm}]}, 
 Alignment -> Center], 
{{q1, 5, Subscript["q", 1]}, -170, 170}, 
{{q2, 5, Subscript["q", 2]}, -170, 170}, 
LocalizeVariables -> False]

This gives you:

enter image description here

As a tip: putting your stuff into Manipulate is an easy and fast way to create interactive code you can play with. Hope it helps!

$\endgroup$
1
  • $\begingroup$ OK, that is exactly what I was looking for! Thanks a lot, this is going to do a little revolution in my simple simulations! Thanks again! $\endgroup$
    – Meclassic
    Jan 23, 2013 at 21:23
1
$\begingroup$

@kguler : Ok, thanks a lot for your answer kguler!

Also, I may look like an idiot answering my own question but here it is...

So, I continued my little research on how to properly localize the variables I needed to localize and here's what I found :

{
 Manipulate[
  ListLinePlot[
   Tooltip@{{O10[q1, q2][[1]], 
      O10[q1, q2][[3]]}, {O20[q1, q2, 400][[1]], 
      O20[q1, q2, 400][[3]]}, {E0[q1, q2, 400, 300][[1]], 
      E0[q1, q2, 400, 300][[3]]}}, 
   PlotRange -> {{-710, 710}, {-710, 710}}, AspectRatio -> Automatic, 
   PlotMarkers -> Automatic, 
   Ticks -> None], {{q1, 5, Subscript["q", 1]}, -170, 
   170}, {{q2, 5, Subscript["q", 2]}, -170, 170}, 
  LocalizeVariables -> False], "\!\(\*SubscriptBox[\(E\), \(0\)]\)="
  Dynamic[{E0[q1, q2, 400, 300][[1]], E0[q1, q2, 400, 300][[3]]} // 
    MatrixForm]}

This provides me with a neat dynamical display of the variable I wanted to watch over for : $E_0$.

Here's what I obtained :

enter image description here

Now, what would be really great would be to somehow integrate this display inside the manipulate zone...

I hope this can be useful to others!

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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