Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Plot Trimesh object like with Axes3D.plot_trisurf()

I have a Trimesh object and I can't figure out how to plot it. My goal is something like the Axes3D.plot_trisurf() function from mplot3d would produce (see below). The Trimesh object even has an attribute containing the faces, but I don't know where to get the coordinates of the grid points.

Thanks for any idea!

trisurf plot from mplot3d

like image 458
vanessaxenia Avatar asked Jul 27 '26 16:07

vanessaxenia


1 Answers

You can just do this, where mesh is your Trimesh object:

import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.plot_trisurf(
    mesh.vertices[:, 0], 
    mesh.vertices[:, 1], 
    mesh.vertices[:, 2],
    triangles=mesh.faces, 
) 
plt.show()

messy trimesh plotted with plot_trisurf

You may have to play with the scale, aspect, rotation, etc.

like image 142
wwwslinger Avatar answered Jul 29 '26 04:07

wwwslinger



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!