定位器超出图形区域

发布于 2024-10-26 22:15:05 字数 1262 浏览 1 评论 0原文

当我运行以下代码

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}
]

Mathematicagraphics

我希望定位器控件位于第一个图形的范围内,但相反可以在整个 GraphicsGrid 区域中移动。我的代码有错误吗?

我也尝试

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

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

但它的行为完全错误。

更新

感谢大家,这是我的最终解决方案:

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}
 ]

Mathematicagraphics

更新

现在的问题是我无法调整和旋转下部 3d 图形的 。有谁知道如何解决这个问题? 我回到了带有两个 Slider2D 对象的解决方案。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

各空 2024-11-02 22:15:05

如果您检查 InputForm,您会发现 GraphicsGrid 返回一个 Graphics 对象。因此,定位器确实在整个图像中移动。

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

如果您只是将 GraphicsGrid 更改为 Grid,定位器将被限制在第一部分,但结果看起来仍然有点奇怪。你的 PlotRange 规范有点奇怪;它似乎不符合文档中心指定的任何格式。也许你想要类似下面的东西。

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}]

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}]
我很坚强 2024-11-02 22:15:05

LocatorPane[] 在将定位器限制在某个区域方面做得很好。

这是巫师先生使用的方法的一种变体。

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

locatorconfided

我假设您希望定位器与其控制的线路共享空间。其实就是“附”在一线。事实证明,这更容易实现。

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

线路定位器

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

七七 2024-11-02 22:15:05

我不确定你想实现什么目标。我看到了很多问题,但我不知道要解决什么。也许您只想要一个简单的 Slider2D 构造?

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}]}]

这是对有关 3D 图形旋转的更新问题的答复。

我相信 David 建议的 LocatorPane 是解决此问题的好方法。我只是输入了一个通用函数,因为您的示例无法在 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}]
 }]
]

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}]
 }]
]
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文