本帖最后由 hue 于 2023-11-7 15:08 编辑
我尝试使用 Mayavi 绘制一个长方体并提供其顶点和面的坐标。但是,当我用来mlab.mesh绘制面时,我遇到了面绘制错误的问题。使用 Matlab 时没有出现问题。
有没有懂的mjj教一下我啊
感谢感谢
绘图结果如图所示,绿色是matlab,蓝色是mayavi:
代码如下:
[ol]from mayavi import mlabimport numpy as npvertices = np.array([[0., 0., 0.], [0., 4.7124, 0.], [4.7124, 0., 0.], [4.7124, 4.7124, 0.], [0., 0., 2.], [0., 4.7124, 2.], [4.7124, 0., 2.], [4.7124, 4.7124, 2.]])faces = np.array([[[4, 6, 7, 5]], [[6, 7, 3, 2]], [[6, 2, 0, 4]], [[5, 4, 0, 1]], [[7, 5, 1, 3]], [[3, 1, 0, 2]]])# pointx_points = vertices[:, 0]y_points = vertices[:, 1]z_points = vertices[:, 2]mlab.points3d(x_points, y_points, z_points, color=(1, 0, 0), scale_factor=0.1)# facex_face = []y_face = []z_face = []for face in faces: face = face[0] x_face.append(vertices[face, 0]) y_face.append(vertices[face, 1]) z_face.append(vertices[face, 2])mlab.mesh(x_face, y_face, z_face, color=(0, 0, 1), opacity=1)mlab.show()[/ol]复制代码 |