# How to create a discrete 2d slider using existing 2d data?

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.

-

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[#]) &]] &}]


-
Yes that's exactly what I'm looking for. Thanks a lot. – xslittlegrass Sep 21 '13 at 17:14

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
]


-
Isn't that out of scale if the points aren't equally spaced? – Dr. belisarius Sep 21 '13 at 0:51
@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. – xslittlegrass Sep 21 '13 at 1:32

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}}]


-