2
$\begingroup$
data = Sort[RandomReal[{0, 1}, {100, 2}]];
Manipulate[pt, {pt, data}, ControlType -> Slider2D]

I get a error message:

Manipulate::vstype: ControlType -> Slider2D is not supported for the variable specification

Is there a workaround?

What I'm trying to achieve is something like this

{Slider2D[Dynamic[pt1], {{0, 0}, {1, 1}, {0.5, 0.5}}], Dynamic[pt1]}

here pt1 can take from

{{0, 0}, {0, 0.5}, {0, 1}, {0.5, 0}, {0.5, 0.5}, {0.5, 1}, {1, 0}, {1,0.5}, {1, 1}}

. Now I want to use my own data, which may contain points that are not equally space.

$\endgroup$
6
$\begingroup$

Perhaps this is the workaround you ask for?

SeedRandom[1];
data = RandomReal[{0, 1}, {100, 2}];
nf = Nearest[data];
Manipulate[
 Graphics[{Point[data], Red, PointSize[Large], Dynamic@Point[pt]}],
 {{pt, First@data}, Slider2D[Dynamic[pt, (pt = First@nf[#]) &]] &}]

Mathematica graphics

$\endgroup$
  • $\begingroup$ Yes that's exactly what I'm looking for. Thanks a lot. $\endgroup$ – xslittlegrass Sep 21 '13 at 17:14
2
$\begingroup$

I'm not sure what you are really asking because the question does not seem internally self-consistent, but perhaps this is what you are looking for.

SeedRandom[42];
data = Sort[RandomReal[{0, 1}, {100, 2}]];
data = Partition[data, 10];
data = SortBy[#, Last] & /@ data;

Manipulate[
 {pt, Extract[data, pt]}, 
 {pt, {1, 1}, {10, 10}, {1, 1}}]

enter image description here

$\endgroup$
1
$\begingroup$

You can let pt take on values corresponding to a position in data and Extract the value there:

data = Sort[RandomReal[{0, 1}, {100, 2}]];
Manipulate[
 {pt, Extract[data, pt]},
 {pt, {1, 1}, Dimensions[data], {1, 1}},
 ControlType -> Slider2D
 ]

manipulate

$\endgroup$
  • 1
    $\begingroup$ Isn't that out of scale if the points aren't equally spaced? $\endgroup$ – Dr. belisarius Sep 21 '13 at 0:51
  • $\begingroup$ @ssch In your example the y of the 2d slider seems only have two value, but what I'm aiming for is allowing the 2d slider to represent the position of the point, whereas your 2d slider seems to represent the point index. $\endgroup$ – xslittlegrass Sep 21 '13 at 1:32

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.