import vtk
cube1 = vtk.vtkCubeSource()
cube1.SetXLength(1.1)
cube1.SetYLength(10)
cube1.SetZLength(10)
cube1.Update()
tri_filter1 = vtk.vtkTriangleFilter()
tri_filter1.SetInputData(cube1.GetOutput())
tri_filter1.Update()
cube2 = vtk.vtkCubeSource()
cube2.SetXLength(1)
cube2.SetYLength(18)
cube2.SetZLength(27)
cube2.Update()
tri_filter2 = vtk.vtkTriangleFilter()
tri_filter2.SetInputData(cube2.GetOutput())
tri_filter2.Update()
boolean_operation = vtk.vtkBooleanOperationPolyDataFilter()
boolean_operation.SetOperationToDifference()
boolean_operation.SetInputConnection(0, tri_filter2.GetOutputPort())
boolean_operation.SetInputConnection(1, tri_filter1.GetOutputPort())
boolean_operation.Update()
mapper = vtk.vtkPolyDataMapper()
mapper.SetInputData(boolean_operation.GetOutput())
actor = vtk.vtkActor()
actor.SetMapper(mapper)
ren = vtk.vtkRenderer()
ren_win = vtk.vtkRenderWindow()
ren_win.AddRenderer(ren)
iren = vtk.vtkRenderWindowInteractor()
iren.SetRenderWindow(ren_win)
ren.AddActor(actor)
ren.SetBackground(1.0, 1.0, 1.0)
ren_win.Render()
iren.Start()
This issue was originally raised in PyVista project
Issue: Incorrect result of boolean_difference · Issue #4843 · pyvista/pyvista · GitHub