LocatorPane in Manipulate blocks interaction with other graphics

1

1

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.

Edmund

Posted 2016-02-17T23:26:24.917

Reputation: 35 657

Answers

2

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.

Michael E2

Posted 2016-02-17T23:26:24.917

Reputation: 190 928

Yes, very much! What did you do? – Edmund – 2016-02-17T23:40:31.580

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. – Edmund – 2016-02-17T23:44:46.827

That does help explain things. Manipulate is a mysterious tool at times. I'll let this sit for a bit just in case. – Edmund – 2016-02-18T00:10:27.160

@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.) – Michael E2 – 2016-02-18T00:16:00.437