I am a Python beginner. I am trying to use Mayavi to plot a cuboid and have provided the coordinates of its vertices and faces. However, when I use mlab.mesh to plot the surface, I encounter an issue where the surface appears distorted, as shown in the image. When I tried plotting it using Matlab, there were no issues. I have carefully checked the code and have not found any problems. Could you help me identify the issue?
I don't have enough reputation to post images.matlab plot mayavi plot
Thank you for taking the time.
Here is my code.
from mayavi import mlab
import numpy as np
vertices = 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]]])
# point
x_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)
# face
x_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()
I have made several attempts to modify it, but there has been no improvement.If you can help me solve this problem, I would be very grateful.