3
$\begingroup$

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?

$\endgroup$
3
$\begingroup$

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

$\endgroup$
4
  • $\begingroup$ Thanks, but I prefer controlling the coordinates separately. $\endgroup$
    – user1337
    Jul 7 '15 at 8:15
  • $\begingroup$ I'm having difficulties doing that. Could you please elaborate? $\endgroup$
    – user1337
    Jul 7 '15 at 8:18
  • $\begingroup$ Sorry, but I don't think you can move the point using locator as well. $\endgroup$
    – user1337
    Jul 7 '15 at 8:39
  • $\begingroup$ @user1337 I added a version with several different interconnected controllers. You can keep the ones you want and remove the others from the code. $\endgroup$
    – Karsten 7.
    Jul 7 '15 at 9:05
1
$\begingroup$

What about the InputField:

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

??

$\endgroup$
1
  • $\begingroup$ I'd like to have two input fields for the two coordinates. $\endgroup$
    – user1337
    Jul 7 '15 at 7:09

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.