python - 给定顶点 i 在 pylab 中绘制 3d 曲面

标签 python matplotlib 3d geometry

我有 6 个点,它们都位于球体的表面,并且是八面体的顶点。我怎样才能在 3d 轴上探索球体内的这个八面体的表面?

我有以下代码,但它没有达到我的预期:

from mpl_toolkits.mplot3d import Axes3D
from mpl_toolkits.mplot3d.art3d import Poly3DCollection
import matplotlib.pyplot as plt

Points=[[ 0.17770898,  0.72315927,  0.66742804],
       [-0.65327074, -0.4196453 ,  0.63018661],
       [ 0.65382635,  0.42081934, -0.62882604],
       [-0.17907021, -0.72084723, -0.66956189],
       [-0.73452809,  0.5495376 , -0.39809158],
       [ 0.73451554, -0.55094017,  0.39617148]]

fig=plt.figure()
ax =fig.add_subplot(1, 1, 1, projection='3d', aspect=1)

ax.add_collection3d(Poly3DCollection([Points]))

u = np.linspace(0, np.pi, 30)
v = np.linspace(0, 2 * np.pi, 30)

x = np.outer(np.sin(u), np.sin(v))
y = np.outer(np.sin(u), np.cos(v))
z = np.outer(np.cos(u), np.ones_like(v))

ax.plot_wireframe(x, y, z, alpha=0.3)

plt.show()

感谢您的帮助。

最佳答案

补充一下 HYRY 的回答;一个体积是由几个多边形面的列表构建的,而每个面又是由一个点列表构建的。 (因此,如果面相邻,则每个点在列表列表中多次出现)。考虑以下片段,其中标记了点:

from mpl_toolkits.mplot3d import Axes3D
from mpl_toolkits.mplot3d.art3d import Poly3DCollection
import matplotlib.pyplot as plt
fig = plt.figure ()
ax = fig.add_subplot (1, 1, 1, projection = '3d', aspect = 1)

# octahedron
A = [ 0.17770898,  0.72315927,  0.66742804]
B = [-0.65327074, -0.4196453 ,  0.63018661]
C = [ 0.65382635,  0.42081934, -0.62882604]
D = [-0.17907021, -0.72084723, -0.66956189]
E = [-0.73452809,  0.5495376 , -0.39809158]
F = [ 0.73451554, -0.55094017,  0.39617148]
OCTO = [[E, A, B],
        [E, B, D],
        [E, D, C],
        [E, C, A],
        [F, A, B],
        [F, B, D],
        [F, D, C],
        [F, C, A],
]
ax.add_collection3d (Poly3DCollection (OCTO))

# sphere
u = np.linspace (0, np.pi, 30)
v = np.linspace (0, 2 * np.pi, 30)
x = np.outer (np.sin (u), np.sin (v))
y = np.outer (np.sin (u), np.cos (v))
z = np.outer (np.cos (u), np.ones_like (v))
ax.plot_wireframe (x, y, z, alpha = 0.3)

plt.show ()

关于python - 给定顶点 i 在 pylab 中绘制 3d 曲面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23228703/

相关文章:

python - Python 中的溢出错误 : (34, 'Result too large' )

python - 在 matplotlib 中的嵌套字典的数据上创建图形(绘图)

python - 对于python,如何将变量传递给JSON?

python - Pip3 不会更新 Tensorflow

python - 将 'curl -F' 转换为 Python 请求

javascript - 如果发生碰撞,如何使用光线转换防止变换控制移动对象?

graphics - 在 Vulkan 中,您如何将每个单独的视频卡与它们直接连接的显示器相关联

python - DataFrame iterrows() 和 .to_csv : Writing row by row

python - 将 PNG 格式的 networkx 图形绘制到 stdout/http 响应

python-3.x - 根据 CityGML 数据绘制建筑表面