2

I have 6 corner points coordinate of 3d surface like Figure 1. I want to generate and plot 3d surface like Figure 2. I need to find the distance of midpoint of each meshed area from the origin.
Figure 1

Figure 2

Please suggest me, which module will be better for meshing and also for plotting?

2 Answers2

1

You can use vedo:

from vedo import *

pts = [(-5.795555, -4, 1.55291), (-4.829629, -2, 1.294095),
       (-5.795555, 1, 1.552914), (-5.536736, -4, 2.51884),
       (-4.57081, -2, 2.260021), (-5.536736,  1, 2.51884)]

faces = [(0,3,4,1), (1,4,5,2)]

mesh = Mesh([pts, faces]).color('red').alpha(0.3).lineWidth(2)
labels = [Text(i, pos=pts[i], s=.2, c='k') for i in range(len(pts))]

show(mesh, labels)

script result

mmusy
  • 1,292
  • 9
  • 10
1

PyVista and vtkplotter are very similar and both are built on top of VTK but have pretty different APIs/design choices. For your use, either would be great! Here is the equivalent with PyVista for completeness.

Typically with simple geometries like this, Matplotlib, PyVista, or vtkplotter would all do well. If you start to create more sophisticated meshes and 3D scenes, then that's where PyVista and vtkplotter will excel as they are built for 3D while MPL is really awesome at 2D.

PyVista will especially excel at data management if you start making complex meshes.... shameless plug ;)

import pyvista as pv
import numpy as np

# Define the nodes
pts = np.array([(-5.795555, -4, 1.55291), (-4.829629, -2, 1.294095),
       (-5.795555, 1, 1.552914), (-5.536736, -4, 2.51884),
       (-4.57081, -2, 2.260021), (-5.536736,  1, 2.51884)])
# Define the quads
faces = np.array([(4,0,3,4,1), (4,1,4,5,2)])

# Instantiate a mesh
mesh = pv.PolyData(pts, faces)

# Create a plotting window and display!
p = pv.Plotter()

# Add the mesh and some labels
p.add_mesh(mesh, show_edges=True)
p.add_point_labels(mesh.points, ["%d"%i for i in range(mesh.n_points)])

# A pretty view position
p.camera_position = [(-11.352247399703748, -3.421477319390501, 9.827830270231935),
 (-5.1831825, -1.5, 1.9064675),
 (-0.48313206526616853, 0.8593146723923926, -0.16781448484204659)]

# Render it!
p.show()

enter image description here