3
$\begingroup$

How can I achieve that the points on a Graphics element could be manipulated both by Locators (clicking and moving) and on the Manipulate panel as well.

As you can see, only one of the methods work. In this example only pt1 appears on the Manipulate panel.

So any ideas?

Here's my code:

Manipulate[
    Graphics[{Polygon[{pt1, pt2, pt3}]}, PlotRangeClipping -> False, 
  Frame -> True, PlotRange -> {{0, 10}, {0, 10}}],

 {{pt1, {0, 0}}}, {{pt2, {0, 1}}, Locator}, {{pt3, {1, 1}}, Locator}] 

loc1

$\endgroup$
  • $\begingroup$ I missed the Locator statement to show that if I miss it, pt1 appears in the manipulate bar $\endgroup$ – balping May 10 '15 at 11:01
7
$\begingroup$

You can attach multiple controls to a variable:

Manipulate[Graphics[{Polygon[{pt1, pt2, pt3}]}, PlotRangeClipping -> False, 
  Frame -> True, PlotRange -> {{0, 10}, {0, 10}}], 
 {{pt1, {0, 0}}}, {{pt2, {0,  1}}}, {{pt3, {1, 1}}},
 Row[{Control@{{pt1, {0, 0}}, {0, 0}, {10, 10}, Slider2D}, 
   Control@{{pt2, {0, 1}}, {0, 0}, {10, 10}, Slider2D}, 
   Control@{{pt3, {1, 1}}, {0, 0}, {10, 10}, Slider2D}}, Spacer[5]],
 {{pt1, {0, 0}}, Locator}, {{pt2, {0, 1}}, Locator}, {{pt3, {1, 1}}, Locator}]

enter image description here

$\endgroup$
  • $\begingroup$ Recommend that you add Appearance -> "Labeled" to each Slider2D. $\endgroup$ – Bob Hanlon May 10 '15 at 12:41
  • $\begingroup$ @BobHanlon, from your comment, I gather Slider2D finally got the Appearance option in Version 10. In version 9, the option Appearance is not supported. I am using the free cloud version of Version 10, where neither Locator nor Slider2D works. I would be curious to see the how the Labeled Slider2D` looks/works. $\endgroup$ – kglr May 10 '15 at 12:54
  • $\begingroup$ demonstrated in my "extended comment" $\endgroup$ – Bob Hanlon May 10 '15 at 13:04
2
$\begingroup$

This is not an answer but rather an extended comment to @kguler to demonstrate Appearance -> "Labeled" with Slider2D in version 10.1

$Version

"10.1.0 for Mac OS X x86 (64-bit) (March 24, 2015)"

Using @kguler answer

Manipulate[
 Graphics[{Polygon[{pt1, pt2, pt3}]},
  PlotRangeClipping -> False,
  Frame -> True,
  PlotRange -> {{0, 10}, {0, 10}}],
 {{pt1, {0, 0}}},
 {{pt2, {0, 1}}},
 {{pt3, {1, 1}}},
 Row[{
   Control@{{pt1, {0, 0}}, {0, 0}, {10, 10},
     Slider2D, Appearance -> "Labeled"},
   Control@{{pt2, {0, 1}}, {0, 0}, {10, 10},
     Slider2D, Appearance -> "Labeled"},
   Control@{{pt3, {1, 1}}, {0, 0}, {10, 10},
     Slider2D, Appearance -> "Labeled"}},
  Spacer[5]],
 {{pt1, {0, 0}}, Locator},
 {{pt2, {0, 1}}, Locator},
 {{pt3, {1, 1}}, Locator}]

enter image description here

$\endgroup$

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.