distance along poly line (spline)

When you have a spline (many points, one poly line cell), is it possible to compute the distance along the spline for each point?

If this is possible when creating the spline, that’d be best but I have attached an example spline here: spline.vtp (15.6 KB)

I created this with (pseudocode)

spline_function = vtk.vtkParametricSpline()

para_source = vtk.vtkParametricFunctionSource()
para_source.SetUResolution(n_points - 1)

spline = para_source.GetOutput()

Please note that this originated in this PyVista issue

You can compute the distance along the curve once and store the distance values in point data. You could then find a particular distance value in the array very quickly (as the distance values are inherently sorted).

However, we found that simple on-the-fly computation of sum of Euclidean distances between curve points are fast enough for interactive use (e.g., for sliding a marker point along the curve by a specific distance). We usually have less than 1000 points in the curve - probably if we had hundreds of thousands of points then we would need to precompute, store, and look up distances.

So I’d have to compute the euclidean distances between each point and consecutively sum them to get the distance. This isn’t exactly what I was hoping for but I suppose it will approximate the distance.For some reason, I was thinking that vtk.vtkParametricFunctionSource would have an implicit function that could represent a smooth version of the line in 3D space for me to compute distances on… now realizing it doesn’t have that.

Computing distance from linear segments is not necessarily a limitation but often preferable, because it guarantees that the curve that the user can see (which is always made up of linear segments, as required by the renderer) is the same model that is used for computations.

Ah, I’m realizing this now… I don’t work with poly lines often so I didn’t realize they were always linearly segmented. I had been working with very high resolution lines so my eyes couldn’t tell

@banesullivan you may find vtkAppendArcLength helpful for this task.


Ah thanks, @cory.quammen! vtkAppendArcLength is exactly what I needed!