簡體   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