繁体   English   中英

是否可以查询Graphics3D的ViewPoint属性?

[英]Is it possible to query the ViewPoint property of Graphics3D?

使用Graphics3D显示某些图形对象后,您可以通过交互式更改ViewPoint选项或简单地拖动,调整大小或旋转图像来移动图像。 后者是否会在内部更改ViewPoint? 可以查询一下吗?

例如。

按程序:

 Manipulate [
 viewpoint->{x,y,y};
 Graphics3D[Cuboid[],ViewPoint->viewpoint],
 ,{x,-25,25}
 ,{y,-25,25}
 ,{z,-25,25}]

通过'鼠标'

Graphics3D[
    Cuboid[]] 

可以模拟上述程序的效果。 我可以通过旋转来查询对ViewPoint的影响吗?

试试这段代码:

gr = Graphics3D[Cuboid[], SphericalRegion -> True, Boxed -> False]

(* this is one way to extract the values: *)
vp = ViewPoint /. AbsoluteOptions[gr]
vv = ViewVertical /. AbsoluteOptions[gr]

(* the following is completely another way. try rotating the output of this: *)
Row[
 {Show[gr, ViewPoint -> Dynamic[vp], ViewVertical -> Dynamic[vv]],
  Show[gr, ViewPoint -> Dynamic[vp], ViewVertical -> Dynamic[vv]]}
]

(* values will dynamically update here: *)
Dynamic[vp]
Dynamic[vv]

希望这有助于为您的问题找到解决方案。

编辑:您也可以将已经鼠标旋转的图形复制并粘贴到ViewPoint /. Options[...] ViewPoint /. Options[...]

这是Szabolcs的增强版代码。 主要区别在于DynamicModule使用允许避免Graphics3D粉红色背景,这表示由于未定义的符号vpvv导致的错误。 即使在保存笔记本并重新启动Mathematica而无需重新评估代码之后,此输出仍可正常工作!

gr = Graphics3D[Cuboid[], SphericalRegion -> True, Boxed -> False];
DynamicModule[{vp = ViewPoint /. AbsoluteOptions[gr], 
  vv = ViewVertical /. AbsoluteOptions[gr]}, 
 Column[{Row[
    Table[Show[gr, ViewPoint -> Dynamic@vp, 
      ViewVertical -> Dynamic@vv], {3}]], Dynamic@vp, Dynamic@vv}]]

此行为已有详细记录 :“当保存包含DynamicModule的笔记本时,默认情况下会自动保存DynamicModule中的局部变量值,以便这些值在Mathematica的会话中保持有效”。

可以通过选择包含图形的单元格并给出菜单命令Cell > Show Expression (ctrl-shift-E)来手动完成。 图形将替换为相应的单元格表达式, ViewPoint选项设置以纯文本形式显示。

另一种可能性是:

Cases[ NotebookGet[EvaluationNotebook[]], (ViewPoint -> e_) -> e, Infinity]

(* Out[51]= {{1.73834, -2.29064, 1.78357}, {0.651043, -0.128738, 
  3.31807}, {-3.03116, -1.38541, 0.585417}} *)

这将在笔记本中查找所有出现的ViewPoint并输出其坐标。 你可能知道你需要哪一个。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM