1
$\begingroup$

I have a Manipulate that uses LocatorPane on a ContourPlot to move some a Sphere around a Plot3D.

If I specify that a Locator control should be used for the pane variable p it the sphere moves around. However, I can not rotate the 3d plot.

If I specify a None for the pane variable p then I can rotate the 3d plot but the sphere is not linked to the locator on the contour plot.

Below is a minimal example. I am uses the Column as I have some dynamic tables sharing the space of the controls (not included).

Manipulate[
 Row[{
   LocatorPane[p,
    ContourPlot[x y z, {x, 0, 1}, {y, 0, 1},
     PlotRange -> {0, 1}, ImageSize -> Medium
     ]],
   Show[{
     Plot3D[ x y z,  {x, 0, 1}, {y, 0, 1},
      MeshFunctions -> {#3 &},
      PlotRange -> {0, 1}, ImageSize -> Medium],
     Graphics3D[{Yellow, 
       Sphere[{First@p, Last@p, z First@p Last@p + .05}, .05],
       InfiniteLine[{First@p, Last@p, z First@p Last@p + .05}, {0, 0, 1}]}]
     }]
   }],
 Column[{
   Control@{{z, .5}, 0 + $MachineEpsilon, 1},
   Control@{{p, {0.5, 0.5}}, Locator}
   }]
 ]

I would like the interactivity to both move the sphere from the contour plot and rotate the 3d plot. Ideas?

10.3 Win 7 Pro 64 bit.

PS: I also noticed that when I move the locator both of the plots recalculate. I thought my code would result in the plots only recalculating when z is updated. I can ask a separate question if this is too out of scope for a paired answer.

$\endgroup$
2
$\begingroup$

Is this what you're after?

Manipulate[
 Row[{LocatorPane[Dynamic@p, 
    ContourPlot[x y z, {x, 0, 1}, {y, 0, 1}, PlotRange -> {0, 1}, 
     ImageSize -> Medium]], 
   Show[{Plot3D[x y z, {x, 0, 1}, {y, 0, 1}, 
       MeshFunctions -> {#3 &}, PlotRange -> {0, 1}, 
       ImageSize -> Medium], 
      Graphics3D[{Yellow, 
        Sphere[{First@p, Last@p, z First@p Last@p + .05}, .05], 
        InfiniteLine[{First@p, Last@p, z First@p Last@p + .05}, {0, 0, 1}]}]}]}], 
 {{z, .5}, 0 + $MachineEpsilon, 1},
 {{p, {0.5, 0.5}}, ControlType -> None}]

The OP's declaration Control@{{p, {0.5, 0.5}}, Locator} causes Manipulate effectively to wrap the whole output with a LocatorPane[Dynamic[p], <body>], which controls the variable p. This locator pane captures all mouse-clicks on the output. By changing the type to None, there is no automatically created control; rather, p is changed by the explicit Dynamic@p I added inside the LocatorPane in the body of the OP's Manipulate. This restricts the scope of the ClickPane/EventHandler used by LocatorPane to be just the ContourPlot instead of the whole output. Thus mouse-clicks outside the ContourPlot are passed to other handlers, like the FE one that rotates 3D graphics.

$\endgroup$
  • $\begingroup$ Yes, very much! What did you do? $\endgroup$ – Edmund Feb 17 '16 at 23:40
  • $\begingroup$ I see you added some Dynamics but don't understand why they are needed in Manipulate for this particular problem. May you elaborate in your answer. $\endgroup$ – Edmund Feb 17 '16 at 23:44
  • $\begingroup$ That does help explain things. Manipulate is a mysterious tool at times. I'll let this sit for a bit just in case. $\endgroup$ – Edmund Feb 18 '16 at 0:10
  • $\begingroup$ @Edmund You can see the two locators by adding Appearance -> Style["\[MathematicaIcon]", Large, Red] to the LocatorPane or the control spec. (It's easier to see if you add it to the LocatorPane as the locator created by Manipulate sits on top. I think there may be an explanation on site about why the first graphics is chosen to constrain the locator. I'll see if I can find it.) $\endgroup$ – Michael E2 Feb 18 '16 at 0:16
  • $\begingroup$ @Edmund Related: mathematica.stackexchange.com/questions/6009/… $\endgroup$ – Michael E2 Feb 18 '16 at 0:21

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.