3
$\begingroup$

How can I work with tables/lists of Locators under manipulate?

Note this is very similar to this question:

https://mathematica.stackexchange.com/a/51956/2079

The closest I've come is this:

 n = 3
 Manipulate[
    Graphics[{Circle[{0, 0}], Line[{{0, 0}, a[1]}]}],
    Sequence @@ 
      Map[{{a[#], RandomReal[{-1, 1}, {2}]}, Locator} & ,
           Range[n]] // Evaluate]

enter image description here

However any attempt to referece a by a variable index fails:

 n = 3
 Manipulate[
 Graphics[{Circle[{0, 0}], Map[Line[{{0, 0}, a[#]}] &, Range[n]]}],
 Sequence @@ 
   Map[{{a[#], RandomReal[{-1, 1}, {2}]}, Locator} & ,
     Range[n]] // Evaluate]

"coordinate a[1] should be a pair of numbers.. "

My best attempt at following the approach in the linked answer also fails:

 n = 3
 Manipulate[
    Graphics[Circle[{0, 0}]],
    {{data, RandomReal[{0, 1}, {n, 2}]}, ControlType -> None},
 Sequence @@ 
    Map[{{Dynamic[data[[#]]], RandomReal[{-1, 1}, {2}]}, Locator} & , 
    Range[n]] // Evaluate]

"Manipulate argument {{data[[1]],{-0.864708,0.897225}},Locator} does not have the correct form for a variable specification."

This came up working on this: https://mathematica.stackexchange.com/a/80099/2079 by the way.

$\endgroup$

closed as off-topic by m_goldberg, Jens, Dr. belisarius, ciao, Bob Hanlon Apr 21 '15 at 0:49

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question arises due to a simple mistake such as a trivial syntax error, incorrect capitalization, spelling mistake, or other typographical error and is unlikely to help any future visitors, or else it is easily found in the documentation." – m_goldberg, Jens, Dr. belisarius, ciao, Bob Hanlon
If this question can be reworded to fit the rules in the help center, please edit the question.

  • 1
    $\begingroup$ First you should read the section on locators in this Documentation Center article. It discusses using multiple locator in a Manipulate expression. Second, you should consider whether a simple LocatorPane will be a better solution than Manipulate expression as solution to your problem. $\endgroup$ – m_goldberg Apr 20 '15 at 15:22
  • $\begingroup$ ah! thanks @m_goldberg. The answer lies in creating a single locator call of the form { pts , list_of_initial_points }, Locator}, rather than a sequence of separate Locator calls { { point1 ,init1} , Locator } ,{ { point2 ,init2} , Locator } .. .. $\endgroup$ – george2079 Apr 20 '15 at 18:51
5
$\begingroup$
n = 3;
Manipulate[Graphics[{Circle[{0, 0}],Line[{{0, 0}, a[[#]]} & /@Range[Length@a]]}],
 {{a, RandomReal[{0, 1}, {n, 2}]}, Locator, LocatorAutoCreate -> True}]

enter image description here

Alternatively,

Manipulate[Graphics[{Circle[{0, 0}], Line[Tuples[{{{0, 0}}, a}]]}],
 {{a, RandomReal[{0, 1}, {n, 2}]}, Locator, LocatorAutoCreate -> True}]
$\endgroup$
1
$\begingroup$

for completeness here is the LocatorPane version suggested by @m_goldberg comment.

 DynamicModule[{pt = RandomReal[{-1, 1}, {3, 2}]},
   LocatorPane[Dynamic@pt,
     Graphics[{Circle[],
        Line[{{0, 0}, Dynamic@pt[[#]]}] & /@ Range@Length@pt}]]]
$\endgroup$

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