3
$\begingroup$
Manipulate[
 Graphics[Rotate[Line[{{0, 0}, p}], \[Theta], {0, 0}], 
  PlotRange -> 2], {{p, {1, 1}}, Locator}, {\[Theta], 0, 2 \[Pi]}]

I want to rotate a graph including a locator. The line rotated as expected, but the locator didn't rotate with the line. How can I do to rotate the whole graph?

enter image description here

$\endgroup$
5
  • $\begingroup$ Rotate a graph? What graph? $\endgroup$ Commented Nov 17, 2017 at 20:00
  • $\begingroup$ @David, I drew a line with Locator, when I rotated the graph, the locator didn't move. I want to rotate the graph including the locator. Is there anyway to do it? Thanks for your help. $\endgroup$
    – pmzhu
    Commented Nov 19, 2017 at 2:36
  • $\begingroup$ Again: Rotate a graph? WHAT graph? $\endgroup$ Commented Nov 19, 2017 at 16:38
  • $\begingroup$ @David I post code in my question to show what I want $\endgroup$
    – pmzhu
    Commented Nov 20, 2017 at 13:26
  • $\begingroup$ But your title says "graph" and there is no graph whatsoever. Please fix your title (at the very least). $\endgroup$ Commented Nov 20, 2017 at 17:46

2 Answers 2

5
$\begingroup$

(1) You can use Locator as a graphics primitive and rotate all the graphics primitives, and
(2) use Experimental`AngularSlider to control the angle:

Manipulate[Graphics[Rotate[{Line[{{0, 0}, p}], Locator[Dynamic[p]]}, θ, {0, 0}], 
   PlotRange -> 2, ImageSize -> Small],
 {{p, {1, 0}}, None},
 {{θ, 0, ""}, 0, 2 π, Labeled[Experimental`AngularSlider[#, {0, 2 Pi}, 
     Experimental`BoundaryAction -> None], Row[{"θ = ", #}], Top] &}, 
 Deployed -> True]

enter image description here

To prevent the locator from going out of plot area after rotation, we can use the second argument of Dynamic to restrict the locator to stay within a disk of radius 2:

Manipulate[Graphics[Rotate[{Line[{{0, 0}, p}], 
    AbsolutePointSize[10], Red, Point[p], 
    Locator[Dynamic[p, (p = If[Norm[#] < 2, #, 2 Normalize[#]];) &], None]}, 
    θ, {0, 0}], PlotRange -> 2,  ImageSize -> Small],
 {{p, {1, 0}}, None}, 
 {{θ, 0, ""}, 0, 2 π, Labeled[Experimental`AngularSlider[#, {0, 2 Pi}, 
     Experimental`BoundaryAction -> None], Row[{"θ = ", #}], Top] &}, 
 Deployed -> True]

enter image description here

Update: If you want the two controls linked so that the angle is updated as the locator moves, change Locator[...] to

Locator[Dynamic[p, (p = If[Norm[#] < 2, #, 2 Normalize[#]]; θ = ArcTan @@ p) &], None]
$\endgroup$
4
  • $\begingroup$ +1 for the usage of ExperimentalAngularSlider` wow!! Why does it turn black at certain points? $\endgroup$ Commented Mar 4, 2020 at 21:02
  • 1
    $\begingroup$ @CATrevillian, i think it is an artifact of the screen shot image (I use ScreenToGif gif generator). $\endgroup$
    – kglr
    Commented Mar 4, 2020 at 21:14
  • $\begingroup$ I've never heard of ExperimentalAngularSlider` before, that's solve my problem perfectly which I had gave up long time ago, thank you very much. $\endgroup$
    – pmzhu
    Commented Mar 5, 2020 at 12:32
  • $\begingroup$ @pmzhu, my pleasure. Thank you for the accept. $\endgroup$
    – kglr
    Commented Mar 5, 2020 at 12:38
3
$\begingroup$
Manipulate[
 Rotate[Graphics[Plot[x^2, {x, 0, 5}]], r = ArcTan[r1[[1]]/r1[[2]]]],
 {{r1, {1, 1}}, Locator}]
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.