This manipulate program below allows the user to enter points on a LocatorPane and then draws a line through the points.
The Manipulate has an Initialization, where the programmer can define initial values for the points. The initial values are the variable ipts in the code below. What I observe is that the definition of the Manipulate must be evaluated twice before the modified values are displayed. Suspect that I am misunderstanding some fundamental concept about how initialization works. Could someone point out how to revise the code?
On a possibly related note, what must be done so that the variables, ipts, xMin and xMax in the code below have a scope local to the Manipulate?
Steps to reproduce the problem:
- Action: evaluate the cell; Response: the manipulate will appear
- Action: edit the code; change the value of ipts (e.g. change the first point to {0.15, 0.05}
- Action: evaluate the cell; Response, the manipulate will appear, the first point will have the original value {0.15, 0.35}
- Action: evaluate the cell; Response: the manipulate will appear, the first point will have the revised value {0.15, 0.05}
Question: what must change so that manipulate will display the revised value after step 3?
myTest2 = Manipulate[
(*User points*)
posSorted = Sort[pos];
xMin = Min[posSorted[[All, 1]] ];
xMax = Max[posSorted[[All, 1]] ];
gvfuncUser = Interpolation[posSorted, InterpolationOrder -> 1];
myPlot =
Plot[gvfuncUser[x], {x, xMin, xMax},
PlotRange -> {{0, 1}, {0, 1}}, Frame -> True, ImageSize -> 400];
Grid[{
{LocatorPane[Dynamic@pos, myPlot, LocatorAutoCreate -> True,
ContinuousAction -> False] }
}]
,
(*list of controls*)
{{pos, ipts}, ControlType -> None}
(*Initialization*)
, TrackedSymbols :> {pos, ipts}
, Initialization :> (
ipts = {{0.15, 0.35}, {0.25, 0.15}, {0.50, 0.17}, {0.75,
0.18}, {1, 1}};
posSorted = {}; (*do this so that posSorted is local to this Manipulate (?) *)
gvfuncUser = {};
)
, SynchronousUpdating -> False
];
myTest2
Attachments: