If one uses a stand-alone locator and needs it to only be movable along a curve, say, defined by a function f[x]
, one can use a simple construct:
Graphics@Locator[Dynamic[pt, (pt = {#[[1]], f[#[[1]]]}) &]]
If one, instead uses a Manipulate
statement with the Locator
as a control:
Manuipulate[expression,{{pt, {0.5, 0.5}, {0, 0}, {1, 1}}, Locator}]
where expression
is some graphics and the initial point {0.5,0.5} lies somewhere inside it, the locator may be moved unrestricted between the points {0, 0} and {1, 1}.
My question: how to restrict the motion of the Locator along the line, when using the Locator generated within the Manipulate statement?
To be precise, let it be the line f[x_]:=x
?
Comment: I understand that this may be easily done by means of a slider or alike. I would like, however, to have it controlled by a locator.
Comment 2: My question gave rise to a suspect of being a duplicate. Indeed, there were several related questions discussing how to restrict the locator behavior, and solutions are known. The difference is that those solutions always treated the Locators as stand-alone graphics objects. In contrast my question addresses the situation when Locator is fixed as a control in the Manipulate statement. Astonishingly it appears that in this case no solution was so far available.