Search All of the Math Forum:
Views expressed in these public forums are not endorsed by
Drexel University or The Math Forum.



Re: Locators: Retrieve coordinates data to added locators
Posted:
Apr 4, 2013 10:30 PM


Hello,
I have a problem with the following issue. I want to add several locators to a graphic (I'm using LocatorAutoCreate > True in either Manipulate or DynamicModule+LocatorPane) and then retrieve a list with the coordinates of the locators for further analysis. I cannot do it. I tried using LocalizeVariables > False in Manipulate but for some reason I cannot add a locator (Alt+Click) when this option is chosen.
I would appreciate any help. Thanks!
Enrique Moreno Northeastern University
Hi, Enrique,
If I understand you correct you need to retrieve the list of points with the coordinates of (several) locators (not the coordinate of a single locator, just as added), right?
If so, one approach to do it may be to make a global variable which will be assigned to such a list after you decide that it is the good moment. The assignment can be done using a button. Here I show its realization within an example of a function with such a functionality. I wrote it to be able choose good initial conditions for a pde, in order to select trajectories for an illustration. The initial conditions are chosen with locators, and as soon as they have been chosen, one presses the button and the list of the coordinates is assigned to the global variable. The later may be evaluated outside of the Manipulate or LocatorPane.
Please find it below. The place where the operation in question is done is separated out by comments. The description of the function is given here:
Description
This function, set2DPhasePortrait, helps one to define good initial points of a 2D phase portrait.
Parameters: 1) Primary parameters. eq1 and eq2 are the ordinary differential equations; plotRangeX and plotRangeY are two lists (such as {0,2} and {1,1} ) defining the PlotRange in the X and Y directions. imageSize defines the ImageSize nrTraj defines the desired number of the trajectories
2) Secondary parameters. Specification of three following parameters may be omitted, when the function is in use.
tmax defins the maximal time of calculation, by default it is 30 goal defines both AccuracyGoal and PrecisionGoal to be equal. By default they are equal to 5. maxsteps defines the MaxSteps parameters equal to 10^3 by default.
The function draws the phase portrait with the number of trajectories equal to nrTraj. The initial points of these trajectories is set arbitrary but inside the range specified by plotRangeX and plotRangeY. Locators are placed in the initial points, so that one can move these points within the PlotRange. The dynamic list of initial conditions is shown under the plot.
There are two global parameters: initialConditions and phasePortrait. As soon as the parameters and initial conditions are settled, pressing the button "Set the initial conditions and phase portrait" the corresponding list can be called by the variable initialConditions and the plot is called by evaluating the input cell containing its name, phasePortrait.
Attention: if the trajectory goes away to infinity, or simply goes far out of the area specified by the PlotRange, the image plane turns red.
Clear[set2DPhasePortrait];
set2DPhasePortrait[eq1_, eq2_, plotRangeX_List, plotRangeY_List, imageSize_, nrTraj_, tmax_: 30, goal_: 5, maxsteps_: 10^3] := DynamicModule[{points = Table[{RandomReal[0.5*plotRangeX], RandomReal[0.5*plotRangeY]}, {nrTraj}], pp1, pp2, lst, pts}, Panel@Panel[Column[{ LocatorPane[Dynamic[points], lst[pt_, color_] := {ParametricPlot[ Evaluate[{x[t], y[t]} /. NDSolve[{eq1, eq2, x[0] == pt[[1]], y[0] == pt[[2]]}, {x, y}, {t, 1}, AccuracyGoal > goal, PrecisionGoal > goal, MaxSteps > maxsteps]], {t, 0, 1}, PlotRange > {plotRangeX, plotRangeY}, PlotStyle > color] /. Line > Arrow, ParametricPlot[ Evaluate[{x[t], y[t]} /. NDSolve[{eq1, eq2, x[0] == pt[[1]], y[0] == pt[[2]]}, {x, y}, {t, 1, 30}, AccuracyGoal > goal, PrecisionGoal > goal, MaxSteps > maxsteps]], {t, 1, tmax}, PlotRange > {plotRangeX, plotRangeY}, PlotStyle > color]}; Dynamic@ Show[Table[ lst[points[[i]], Hue[i/nrTraj]], {i, 1, nrTraj}], ImageSize > imageSize ] ], Spacer[5], pts = Dynamic@N[Round[1000.*points]/1000.], Spacer[5], Button["Set the initial conditions and phase portrait", Clear[initialConditions, phasePortrait];
(* Here the global variable, *) (* initialConditions is introduced and assigned *)
initialConditions = {}; initialConditions = N[Round[1000.*points]/1000.];
(* end *)
phasePortrait = Show[Table[ lst[points[[i]], Hue[i/nrTraj]], {i, 1, nrTraj}], ImageSize > imageSize ]; ] }, Alignment > Center], Background > White] ]
(* Here the function ends *)
To see how it all works evaluate this:
Clear[x, y]; eq1 = x'[t] == y[t] + x[t]  x[t]^3; eq2 = y'[t] == x[t]  y[t]^3;
set2DPhasePortrait[eq1, eq2, {2, 1}, {1, 1}, 450, 5, 30, 5]
Have fun, Alexei
Alexei BOULBITCH, Dr., habil. IEE S.A. ZAE Weiergewan, 11, rue Edmond Reuter, L5326 Contern, LUXEMBOURG
Office phone : +35224542566 Office fax: +35224543566 mobile phone: +49 151 52 40 66 44
email: alexei.boulbitch@iee.lu



