1

I want to intersect 2 planes using PyVista and visualize the result but I got an error.

I tried the following code:

import pyvista as pv

p1 = pv.Plane(center=(0, 0, 0), direction=(0, 0, 1))

p2 = pv.Plane(center=(0, 0, 0), direction=(1, 0, 0))

intersection = p1.intersection(p2)

But I have the following error:

2023-03-23 16:19:35.916 (   0.291s) [                ]    vtkPointLocator.cxx:868    ERR| vtkPointLocator (000001D4ED1030E0): No points to subdivideERROR:root:No points to subdivide
2023-03-23 16:19:35.921 (   0.296s) [                ]vtkIntersectionPolyData:2410  WARN| No Intersection between objects

How can I perform this intersection?

1 Answers1

1

It seems that this filter doesn't play nicely with non-triangle faces. I don't know how general an issue this is, because I didn't see any warnings in the VTK docs. Perhaps we should add some to PyVista.

Here's your original setup:

import pyvista as pv

p1 = pv.Plane(center=(0, 0, 0), direction=(0, 0, 1))
p2 = pv.Plane(center=(0, 0, 0), direction=(1, 0, 0))

# original meshes
(p1 + p2).plot(show_edges=True)

two intersecting planes with square faces

Note the square-shaped faces. It's especially unfortunate that the intersection line overlaps with edges from both meshes, but I tried shifting the planes by half a face and it didn't change the outcome.

What helps is triangulating your meshes:

p1 = pv.Plane(center=(0, 0, 0), direction=(0, 0, 1)).triangulate()
p2 = pv.Plane(center=(0, 0, 0), direction=(1, 0, 0)).triangulate()
(p1 + p2).plot(show_edges=True)

two intersecting planes with triangle faces

Now the intersection works as you'd expect:

intersection = p1.intersection(p2, split_first=False, split_second=False)[0]

plotter = pv.Plotter()
plotter.add_mesh(p1, show_edges=True)
plotter.add_mesh(p2, show_edges=True)
plotter.add_mesh(intersection, color='red', line_width=5, render_lines_as_tubes=True)
plotter.show()

two intersecting perpendicular planes with a red line along the intersection line