简体   繁体   English

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

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

After showing some graphics objects with Graphics3D you can move the image by interactively changing the ViewPoint option, or by simply dragging, resizing or rotating the image. 使用Graphics3D显示某些图形对象后,您可以通过交互式更改ViewPoint选项或简单地拖动,调整大小或旋转图像来移动图像。 Does the latter change the ViewPoint internally? 后者是否会在内部更改ViewPoint? Can this be queried? 可以查询一下吗?

For example. 例如。

By program: 按程序:

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

By 'mouse' 通过'鼠标'

Graphics3D[
    Cuboid[]] 

Effects of by program above can be simulated. 可以模拟上述程序的效果。 Can I 'query' effect on ViewPoint as a result of ie the rotation? 我可以通过旋转来查询对ViewPoint的影响吗?

Try this code: 试试这段代码:

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]

Hope this helps come up with a solution to your problem. 希望这有助于为您的问题找到解决方案。

EDIT: You can also just copy and paste an already mouse-rotated graphic into ViewPoint /. Options[...] 编辑:您也可以将已经鼠标旋转的图形复制并粘贴到ViewPoint /. Options[...] ViewPoint /. Options[...]

Here is enhanced version of the code by Szabolcs. 这是Szabolcs的增强版代码。 The main difference is that usage of DynamicModule allows to avoid pink background of Graphics3D which indicates an error due to undefined symbols vp and vv . 主要区别在于DynamicModule使用允许避免Graphics3D粉红色背景,这表示由于未定义的符号vpvv导致的错误。 This output works right even after saving the notebook and restarting Mathematica without re-evaluating the code! 即使在保存笔记本并重新启动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}]]

This behavior is well-documented : "Values of local variables in a DynamicModule are by default automatically saved when a notebook containing the DynamicModule is saved, so that these values in effect persist across sessions of Mathematica ". 此行为已有详细记录 :“当保存包含DynamicModule的笔记本时,默认情况下会自动保存DynamicModule中的局部变量值,以便这些值在Mathematica的会话中保持有效”。

It can be done manually by selecting the cell containing your graphics and giving the menu command Cell > Show Expression (ctrl-shift-E). 可以通过选择包含图形的单元格并给出菜单命令Cell > Show Expression (ctrl-shift-E)来手动完成。 The graphics are replaced with the corresponding cell expression and the ViewPoint option setting is visible in plain text. 图形将替换为相应的单元格表达式, ViewPoint选项设置以纯文本形式显示。

Another possibility is: 另一种可能性是:

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}} *)

This finds all occurrences of ViewPoint in your notebook and outputs their coordinates. 这将在笔记本中查找所有出现的ViewPoint并输出其坐标。 You'll probably know which one you need. 你可能知道你需要哪一个。

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

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