# How to Dynamically Locate (get coordinates) of a point, inside a Manipulate?

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?

-

  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}]


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]

-
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! – jrojasqu Jan 22 '13 at 14:20

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:

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!

-
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! – jrojasqu Jan 23 '13 at 21:23

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 :

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!

-