3

I'm trying to have a point in the plane which can be manipulated both using Locator as well as inserting its $x$ and $y$ coordinates. My attempts at doing this are:

Manipulate[Graphics[Point[p], PlotRange -> 1], {{p, {1, 1}}, Locator},  
 {p[[1]], -1, 1}, {p[[2]], -1, 1}]

which doesn't even run, as well as

Manipulate[Graphics[Point[p], PlotRange -> 1], {{p, {1, 1}}, Locator}, 
 {p[1], -1, 1}, {p[2], -1, 1}]

which runs, but fails to see that p[1], p[2] should be the coordinates of p.

I've managed to use a 2DSlider:

Manipulate[Graphics[Point[p], PlotRange -> 1], {{p, {1, 1}}, Locator}, 
 {p, {-1, -1}, {1, 1}}]

but even here, I can't input the exact coordinates.

My question is:

How can one give the exact coordinates of the point p in Manipulate, as well as control its position using a Locator?

Karsten7
  • 27,448
  • 5
  • 73
  • 134
user1337
  • 1,068
  • 6
  • 13

2 Answers2

4

One can add the option Appearance -> "Labeled" to a Slider2D to have the current values shown as an editable label.

Manipulate[
 Graphics[{PointSize[Large], Point[p]}, 
  PlotRange -> 1], {{p, {1, 1}}, {-1, -1}, {1, 1}, 
  Appearance -> "Labeled"}]

GIF


Using two 1D Slider

Manipulate[
 Graphics[{PointSize[Large], Point[{px, py}]}, 
  PlotRange -> 1], {{px, 1}, -1, 1, Slider, 
  Appearance -> "Labeled"}, {{py, 1}, -1, 1, VerticalSlider, 
  Appearance -> "Labeled", ControlPlacement -> Left}]

GIF2


Having several interconnected control types:

point = Graphics[{PointSize[Large], Point[{0, 0}]}, PlotRange -> 1];

Manipulate[
 Graphics[{}, PlotRange -> 1, Frame -> True], {{p, {1, 1}}, Locator, 
  Appearance -> point, TrackingFunction -> (p = #; {px, py} = p; &)},
 {{p, {1, 1}}, {-1, -1}, {1, 1}, Appearance -> "Labeled", 
  TrackingFunction -> (p = #; {px, py} = p; &)},
 {{px, 1}, -1, 1, Slider, Appearance -> "Labeled", 
  TrackingFunction -> (px = #; p[[1]] = px; &)},
 {{py, 1}, -1, 1, VerticalSlider, Appearance -> "Labeled", 
  ControlPlacement -> Left, 
  TrackingFunction -> (py = #; p[[2]] = py; &)},
 {{px, 1}, InputField, ControlPlacement -> Bottom, 
  TrackingFunction -> (px = #; p[[1]] = px; &)},
 {{py, 1}, InputField, ControlPlacement -> Bottom, 
  TrackingFunction -> (py = #; p[[2]] = py; &)}]

UltimateMess

Karsten7
  • 27,448
  • 5
  • 73
  • 134
1

What about the InputField:

    Manipulate[
 Graphics[Point[p], PlotRange -> 1], {{p, {1, 1}}, 
  Locator}, {p, {-1, -1}, {1, 1}, InputField}]

??

Alexei Boulbitch
  • 39,397
  • 2
  • 47
  • 96