Finding the length of a cubic B-spline

Using the scipy interpolate.splprep function receives a parametric spline with respect to the parameter u , but the region u not a linear integral of the spline, it is a piecewise linear relationship of the input coordinates. I tried integrate.splint , but it just gives separate integrals over u . Obviously, I can integrate a bunch of Cartesian differential distances numerically, but I was wondering if there was a closed-form method to get the length of the spline or spline segment (using scipy or numpy) that I was looking at.

Edit: I'm looking for a solution with a closed form or a very quick way to reduce the answer to machine accuracy. I almost abandoned the numerical methods of finding roots and now, first of all, after the answer to the closed form. If someone has experience integrating elliptical functions, or may indicate a good resource (other than Wolfram), that would be great.

I will try Maxima to try to get an indefinite integral from what, in my opinion, is a function for one spline segment: I crossed this to MathOverflow

+7
python scipy interpolation
source share
2 answers

Since both x and y are cubic parametric functions, there is no closed solution in terms of simple functions. Digital integration is the way to go. Either integrating the expression for the length of the arc, or just adding the lengths of the line segment, depends on the accuracy you perform and how much effort you want to perform.

The exact and fast method "Adding the length of line segments":

Using recurvise subdivision (the de Castellau algorithm form) to create points, you can give an accurate representation with a minimum number of points. Only subdivide units if they do not meet the criteria. Typically, the criteria are based on the length connecting the control points (body or cage). For a cube, usually comparing the proximity of P0P1 + P1P2 + P2P3 with P0P3, where P0, P1, P2 and P3 are the control points that define your bezier.

Here you can find the Delphi code: link text

Relatively easy to convert to Python. It will generate points. The code already calculates the length of the segments to check the criteria. You can simply accumulate these lengths along the way.

+6
source share

You can integrate the sqrt(x'(u)**2+y'(u)**2) function over u , where you compute the x' and y' derivatives of your coordinates using scipy.interpolate.splev . Integration can be done using one of the routines from scipy.integrate ( quad is exact [Clenshaw-Curtis], romberg is usually faster). This should be more accurate and probably faster than adding up a large number of small distances (which is equivalent to integrating with the rectangle rule).

+4
source share

All Articles