Calculate length of a cubic spline, given it’s vertices in 3d space

bezier-curvecurvesspline

Given a cubic spline defined by $n$ number of vertices in a 3d space, how would one calculate the length of this spline?

(Attached picture is just for illustration, to explain what I mean by vertices, since I don't know whether in mathematics, that term refers to points directly on the curve or not.)

In the 2d example below, I know the positions of the points connecting the straight lines (chords? I'm terribly sorry, all this is new to me in English and I lack the proper terminology..), and am trying to calculate the length of the spline.

I assume some vector math is involved, but wouldn't know where to start. Googling suggests that this is not a common question. I have found some information about art length, but afaik, that is not what I can use here, or have absolutely no clue how I would/could.

illustration of a cubic curve defined by 9 vertices in 2d space

Ac actual example of my splines from the 3D app I'm using

Any help is appreciated!

Best Answer

Your curve looks like a cubic b-spline. This is essentially just a string of cubic Bezier curves joined together in a clever way.

There are (at least) two options ...

Option 1:
Decompose your spline curve into its constituent Bezier curves. To do this, you have to insert knots until each one has multiplicity three. Then the b-spline control points will immediately give you the Bezier control points of each cubic segment. You can look up "knot insertion" to find out how to do this. The standard algorithm is called Boehm's algorithm. Then, once you have the Bezier curves, you can calculate the arclength of each of them and add them up. If you search for "arclength of Bezier curve" you'll find plenty of advice. I think this is very good, for example.

Note that there is no closed-form formula for the arclength of a cubic Bezier curve, so whatever method you choose will necessarily use some sort of numerical integration.

Option 2:
Just approximate your spline curve by a polyline, and calculate the arclength of the polyline, which is easy. To construct the polyline, just calculate a large number of points on the curve (I assume you have a software function to do this), and then join these points by straight lines. The only difficulty is choosing a suitable number of points. I'd suggest starting with $n$ points where $n$ equals the number of spline control points multiplied by 100 or so. Obviously, using more points will give you better accuracy, but worse performance.

I recommend option 2, especially if you're not familiar with the concepts I mentioned in option 1.

Reading the answers here should be helpful, but note that some of the discussion there is about quadratic curves (degree 2), and your curve appears to be cubic (degree 3).

If you just want to re-use existing code (which is usually a good idea), then this package claims to provide arclength calculations. I've never used it, so no idea how well it works.

Related Question