根据 scikit-image 文档 中的示例,我使用 marching cubes 算法生成了一个球形表面网格。我希望将单位球壳居中放置在由 x、y、z 网格定义的原点上。然而,我无法做到这一点,因为我不知道如何将 x、y、z 信息与 mpl_toolkits.mplot3d.art3d.Poly3DCollection 结合使用。以下是代码:
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d.art3d import Poly3DCollection
from skimage import measure
import numpy as np
x, y, z = np.ogrid[-4:4:20j, -4:4:20j, -4:4:20j]
r = np.sqrt(x ** 2 + y ** 2 + z ** 2)
verts, faces, normals, values = measure.marching_cubes_lewiner(r,level=1)
fig = plt.figure(figsize=(10, 10))
ax = fig.add_subplot(111, projection='3d')
mesh = Poly3DCollection(verts[faces])
mesh.set_edgecolor('k')
ax.add_collection3d(mesh)
plt.show()
问题在于
marching_cubes_lewiner
函数没有考虑x,y,z
。我该如何将生成的球体置于0,0,0处,与网格暗示的位置一致?
measure.marching_cubes_lewiner
,它需要两个参数。 - ImportanceOfBeingErnestmarching_cubes
。但是现在的代码应该可以工作;你遇到了什么问题? - ImportanceOfBeingErnest