vtkLine distanceToLine does not work as written in documentation?

Hi everyone,
I am using vtk for my project in python and I just found out the computation of distanceToLine does not work as written in the documentation. (Snippet below.)


Static Public Member Functions

static vtkLine * New ()

static double DistanceToLine (const double x[3], const double p1[3], const double p2[3], double &t, double closestPoint[3]=nullptr)
Compute the distance of a point x to a finite line (p1,p2).


So according to the documentation, it should compute distance to a finite line, but in my code, it treats the line as infinite.

def computeDistanceToLine(point, line1, line2):
    distance_squared = vtk.vtkLine.DistanceToLine(point, line1, line2)
    return np.sqrt(distance_squared)

points = np.array([ [1, 5, 3],  [2, 4, 6],  [7, 1, 3], [5, 9, 2], ....]) # example
distances = np.apply_along_axis(computeDistanceToLine, 1, points, line1=line1, line2=line2)
pointsThatAreFar = points[distances > 10]

If I run it on points in inside of meshes like on the figure below, it returns for the green line, result like that. I would expect that the blue ball will be filled with the red points (=pointsThatAreFar), but you can see that there is a part of the points missing in the direction of the green line.

Am I using the DistanceToLine function wrong? I can do a workaround, but it would be nice to use vtk functions, because of the speed.
Any tips? Did I oversee something?

Thanks a lot!

The different DistanceToLine() functions have different behaviors. For the one you are using, the documentation says this:

So instead, you can try using this one, which says that it’s for finite lines:

You should be able to call it like this:

    t = vtk.reference(0.0)
    distance_squared = vtk.vtkLine.DistanceToLine(point, line1, line2, t)