Continuing the discussion started in the thread here, I've tried to recreate the code from scratch. I thus looked to constrain the movement of a locator to the graph defined by
f[t_] := t {Cos[10 t], Sin[10 t]}
If the locator is at point pt, then
Table[{t,Norm[f[t] - pt]}, {t, 0, 2, 0.001}]
is a list of couple {t, distances}, which can be sorted with Sort
and the t-value can be found back using
First[First[Sort[Table[
{t, Norm[f[t] - pt]}
, {t, 0, 2, 0.001}], (#1[[2]] < #2[[2]]) &]]]
Changing the variable pt by #
to create a Pure Function used by the second argument of the Locator
command, I tried the code
Show[
ParametricPlot[f[t], {t, 0, 2}]
,
Graphics[{
Locator[ptt,
ptt =
(f[First[First[Sort[Table[
{t, Norm[f[t] - #]}
, {t, 0, 2, 0.001}], (#1[[2]] < #2[[2]]) &]]]]) &
]
}]
]
which doesn't work at all. I think there is an error due to expansions of some sorts, but don't know where. Any help with this? The answer found in the link above is working, of course, but I'm trying to find something "shorter", if possible.
All help, as always, very much appreciated!