3
$\begingroup$

I am trying to use TrackingFunction with Locator inside Manipulate, and it works fine with a single Locator, but it fails as soon as I use multiple Locators. Here is a simplified example of what I am trying to achieve:

Suppose I want to have two Locators on a circle: one shall be restricted to the circle's boundary, the other one shall be restricted to the whole disk (i.e. boundary plus inside). Here is how I tried to solve that:

Manipulate[Graphics[Circle[],PlotRange ->2],
    {{pt,{0,1}},Locator,TrackingFunction->(pt=Normalize[#];&)},
    {{pt2,{1,0}},Locator,TrackingFunction->(pt2=#/Max[Norm[#],1];&)}]

The TrackingFunctions, however, seem to have no effect, as can be seen in the following image:

Output of Manipulate

If I delete one of the two locators, the TrackingFunction works. How can I use both Locators at the same time?

$\endgroup$
3
$\begingroup$

You can use a different construction to create multiple Locators:

Manipulate[
 Graphics[Circle[], PlotRange -> 2], {{pt, {{0, 1}, {1, 0}}}, 
  Locator,
  TrackingFunction -> (p |-> {
      pt[[1]] = Normalize[p[[1]]],
      pt[[2]] = p[[2]]/Max[Norm[p[[2]]], 1]}
    )}]

In this case, pt is a list of the locations of each Locator. Our TrackingFunction can then act on this list (called p in our function) and set different constraints for each point in the list.

The documentation doesn't appear to suggest that you can do multiple Locators any other way, so I'm assuming it's unsupported.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.