I used pv.StructuredGrid
to create a Plotter with multiple paraboloid shapes (exemplary shown code below). However, now I would like to make a Boolean difference with another shape (e.g. a plane - see below), but this does not seem to work (as I always get this error: AttributeError: 'Plotter' object has no attribute 'boolean_difference'). Could anybody help me?
How my meshes are generated:
import pyvista as pv
import numpy as np
from numpy import random
radii = [414.0967188966002, 422.2479102262, 401.8741938358064, 412.8652471941591, 405.30327025128963]
x_m = [2048.3060572964573, 4607.447344005181, 2295.9114801453684, 1394.6630041507797, 4676.283314271765]
y_m = [2474.4502714162686, 6689.97825049905, 4208.099918674929, 1452.7963458653007, 4317.46410459845]
planeheight = 100
height = 350
def parabola(z,radius,height):
a = height/radius**2
return np.sqrt(1/a *(-z+(height)))
plotter = pv.Plotter()
# Create fungiform
for i in range(len(x_m)):
theta = np.linspace(0,2*np.pi,80)
z_ = np.linspace(0,500,80)
r = parabola(z_,radii[i],height)
z_, theta = np.meshgrid(z_,theta)
x = x_m[i]+ r * np.cos(theta)
y = y_m[i]+ r * np.sin(theta)
z = z_ + planeheight
grid = pv.StructuredGrid(x,y,z)
plotter.add_mesh(grid, color='tan')
plotter.show()
#Definition of a Plane
plane = pv.Plotter()
x_p, y_p, z_p = np.meshgrid(np.linspace(0,10000,2), np.linspace(0,10000,2), np.linspace(planeheight,planeheight+10,2))
grid= pv.StructuredGrid(x_p,y_p,z_p)
plane.add_mesh(grid, color = [1,0,0])
Now I would like to make a boolean difference between the plotter and plane, something like this (as checked in Pyvista documentation)
The Boolean difference should work like this:
result = plotter.boolean_difference(plane)
pl = pv.Plotter()
_ = pl.add_mesh(plotter, color='r', style='wireframe', line_width=3)
_ = pl.add_mesh(plane, color='b', style='wireframe', line_width=3)
_ = pl.add_mesh(result, color='tan')
pl.camera_position = 'xz'
pl.show()