Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Locator goes out of the graph region

When I run the following code

pMin = {-3, -3};
pMax = {3, 3};
range = {pMin, pMax};
Manipulate[
 GraphicsGrid[
  {
   {Graphics[Locator[p], PlotRange -> range]},
   {Graphics[Line[{{0, 0}, p}]]}
   }, Frame -> All
  ],
 {{p, {1, 1}}, Locator}
]

Mathematica graphics

I expect the Locator control to be within the bounds of the first Graph, but instead it can be moved around the whole GraphicsGrid region. Is there an error in my code?

I also tried

{{p, {1, 1}}, pMin, pMax, Locator}

instead of

{{p, {1, 1}}, Locator}

But it behaves completely wrong.

UPDATE

Thanks to everyone, this is my final solution:

Manipulate[
 distr1 = BinormalDistribution[p1, {1, 1}, \[Rho]1];
 distr2 = BinormalDistribution[p2, {1, 1}, \[Rho]2];
 Grid[
  {
   {Graphics[{Locator[p1], Locator[p2]}, 
     PlotRange -> {{-5, 5}, {-5, 5}}]},
   {Plot3D[{PDF[distr1, {x, y}], PDF[distr2, {x, y}]}, {x, -5, 5}, {y, -5, 5}, PlotRange -> All]}
   }],
 {{\[Rho]1, 0}, -0.9, 0.9}, {{\[Rho]2, 0}, -0.9, 0.9},
 {{p1, {1, 1}}, Locator},
 {{p2, {1, 1}}, Locator}
 ]

Mathematica graphics

UPDATE

Now the problem is that I cannot resize and rotate the lower 3d graph. Does anyone know how to fix that? I'm back to the solution with two Slider2D objects.

like image 278
Max Avatar asked Mar 29 '11 02:03

Max


3 Answers

If you examine the InputForm you'll find that GraphicsGrid returns a Graphics object. Thus, the Locator indeed moves throughout the whole image.

GraphicsGrid[{{Graphics[Circle[]]}, {Graphics[Disk[]]}}] // InputForm

If you just change the GraphicsGrid to a Grid, the locator will be restricted to the first part but the result still looks a bit odd. Your PlotRange specification is a bit strange; it doesn't seem to correspond to any format specified in the Documentation center. Perhaps you want something like the following.

Manipulate[
 Grid[{
   {Graphics[Locator[p], Axes -> True,
     PlotRange -> {{-3, 3}, {-3, 3}}]},
   {Graphics[Line[{{0, 0}, p}], Axes -> True,
     PlotRange -> {{-3, 3}, {-3, 3}}]}},
  Frame -> All],
 {{p, {1, 1}}, Locator}]
like image 108
Mark McClure Avatar answered Nov 04 '22 04:11

Mark McClure


LocatorPane[] does a nice job of confining the locator to a region.

This is a variation on the method used by Mr. Wizard.

Column[{ LocatorPane[Dynamic[pt3],
   Framed@Graphics[{}, ImageSize -> 150, PlotRange -> 3]],
   Framed@Graphics[{Line[{{-1, 0}, Dynamic@pt3}]}, ImageSize -> {150, 150}, 
     PlotRange -> 3]}]

locator confined

I would have assumed that you'd want the locator to share the space with the line it controls. In fact, to be "attached" to the line. This turns out to be even easier to implement.

Column[{LocatorPane[Dynamic[pt3],Framed@Graphics[{Line[{{-1, 0}, Dynamic@pt3}]},
 ImageSize -> 150, PlotRange -> 3]]}]

locator on the line

like image 22
DavidC Avatar answered Nov 04 '22 03:11

DavidC


I am not sure what you are trying to achieve. There are a number of problems I see, but I don't know what to address. Perhaps you just want a simple Slider2D construction?

DynamicModule[{p = {1, 1}}, 
 Column@{Slider2D[Dynamic[p], {{-3, -3}, {3, 3}}, 
    ImageSize -> {200, 200}], 
   Graphics[Line[{{0, 0}, Dynamic[p]}], 
    PlotRange -> {{-3, 3}, {-3, 3}}, ImageSize -> {200, 200}]}]

This is a reply to the updated question about 3D graphic rotation.

I believe that LocatorPane as suggested by David is a good way to approach this. I just put in a generic function since your example would not run on Mathematica 7.

DynamicModule[{pt = {{-1, 3}, {1, 1}}},
 Column[{
   LocatorPane[Dynamic[pt], 
     Framed@Graphics[{}, PlotRange -> {{-5, 5}, {-5, 5}}]],
   Dynamic@
    Plot3D[{x^2 pt[[1, 1]] + y^2 pt[[1, 2]],
           -x^2 pt[[2, 1]] - y^2 pt[[2, 1]]},
        {x, -5, 5}, {y, -5, 5}]
 }]
]
like image 37
Mr.Wizard Avatar answered Nov 04 '22 05:11

Mr.Wizard