簡體   English   中英

Python:如果我將x,y和z作為某些參數的函數,如何繪制通用3D對象?

[英]Python: How can I plot a generic 3D object if I have x, y and z as functions of some parameters?

例如,對於單位球,

x = cos(phi)sin(theta)
y = sin(phi)sin(theta)
z = cos(theta)

我想簡單地繪制phi和theta分別在間隔[0, 2*pi][0, pi]

在一般情況下,有沒有辦法做到這一點,即指定

  • x,y,z作為某些參數的函數,並且
  • 這些參數的范圍

然后得到一個3D圖?

我認為,就Mayavi而言,您將始終會自己創建一些網格並繪制結果數據點。但是,使用numpy時,不必太麻煩:

from numpy import pi, sin, cos, mgrid
[phi,theta] = mgrid[0:2*pi:100j,0:pi:100j]  # 100 is the amount of steps in the respective dimension
x = cos(phi)*sin(theta)
y = sin(phi)*sin(theta)
z = cos(theta)

from mayavi import mlab
s = mlab.mesh(x, y, z)
mlab.show()

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM