I would like to intersect 2 lines using PyVista, get the coordinates of this intersection and plot the result.
I tried the following code:
import pyvista as pv
line1 = pv.Line(pointa=(-1,0,0), pointb=(2,0,0))
line2 = pv.Line(pointa=(0,-1,0), pointb=(0,2,0))
intersection = line1.intersection(line2)
plotter = pv.Plotter()
plotter.add_mesh(line1)
plotter.add_mesh(line2)
plotter.add_mesh(intersection)
plotter.show()
But the problem is that I got a tuple of 3 empty PolyData
elements:
(PolyData (0x2634b15bee0)
N Cells: 0
N Points: 0
N Strips: 0
X Bounds: 1.000e+299, -1.000e+299
Y Bounds: 1.000e+299, -1.000e+299
Z Bounds: 1.000e+299, -1.000e+299
N Arrays: 0,
PolyData (0x2634b15bac0)
N Cells: 0
N Points: 0
N Strips: 0
X Bounds: 1.000e+299, -1.000e+299
Y Bounds: 1.000e+299, -1.000e+299
Z Bounds: 1.000e+299, -1.000e+299
N Arrays: 0,
PolyData (0x2634b14a100)
N Cells: 0
N Points: 0
N Strips: 0
X Bounds: 1.000e+299, -1.000e+299
Y Bounds: 1.000e+299, -1.000e+299
Z Bounds: 1.000e+299, -1.000e+299
N Arrays: 0)
And I can't plot a tuple in relation with the line: plotter.add_mesh(intersection)
. This made me think that there was no intersection but that's impossible.