Intersection of meshes generated by numpy (pyvista)

37 Views Asked by At

I'm trying to create from scratch some 3D geometry from some points in the plane that are rotated around the centre (0,0,0) and then this same geometry I move it 3 units in x,y,z respectively. I am using pyvista to modelate this geometries and try to find the intersection between geometry 1 and 2. I have wrote the following code.

import numpy as np 
import matplotlib.pyplot as plt
import pyvista as pv
plt.close("all")

corners = np.array([[0,0],[5,0],[5,10],[7,12],[7,15],[0,15]])
phi = np.linspace(0, 2*np.pi, 10)

#geometry 1
xx = np.outer(corners[:,0], np.cos(phi))
yy = np.outer(corners[:,0], np.sin(phi))
__, zz = np.meshgrid(phi, corners[:,1])

#geometry 2
xx_1 = xx+3
yy_1 = yy+3
zz_1 = zz+3

# =============================================================================
# Point cloud creation 
# =============================================================================
x = xx.flatten()
y = yy.flatten()
z = zz.flatten()

points = np.array([x,y,z]).T
points = np.unique(points, axis=0)

# =============================================================================
# PolyData body creation
# =============================================================================

point_cloud_1 = pv.PolyData(points)
point_cloud_2 = pv.PolyData(points+3)
# =============================================================================
# Testing mesh creation methods
# =============================================================================
# Generating meshes with diverse methods 
mesh_1 = point_cloud_1.delaunay_2d()
mesh_2 = point_cloud_2.delaunay_2d()

# mesh_1 = point_cloud_1.delaunay_3d(alpha = 6)
# mesh_2 = point_cloud_2.delaunay_3d(alpha = 6)

# mesh_1 = point_cloud_1.reconstruct_surface()
# mesh_2 = point_cloud_2.reconstruct_surface()

# mesh_1 = pv.StructuredGrid(xx,yy,zz)
# mesh_2 = pv.StructuredGrid(xx_1,yy_1,zz_1)

plotter = pv.Plotter()
plotter.add_mesh(mesh_1,show_edges=True,  color="red", point_size=5)
plotter.add_mesh(mesh_2,show_edges=True, color="blue", point_size=5)

Geometry obtained in matplotlib

Geometry obtained in matplotlib

Geometry obtained by delaunay_2d()

Geometry obtained by delaunay_2d()

Geometry obtained by delaunay_3d(alpha=6)

Geometry obtained by delaunay_3d(alpha=6

Geometry obtained by reconstruct_surface()

Geometry obtained by reconstruct_surface()

Geometry obtained by StructuredGrid

Geometry obtained by StructuredGrid

intersection = mesh_1.boolean_intersection(mesh_2)

The best approaches considering what I have achieved are the delaunay_3d and StructuredGrid. In my research maybe pymeshlab could be also an option, but the most similar question founded is this . In this case the meshes are already built up. Another aspect is the boolean operation is not possible because those geometries are not triangular meshes. I have been looking for information for some weeks and I have not been able to understand how can I perform this operation.

0

There are 0 best solutions below