0

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!

Pete
  • 15
  • 5
  • What do you mean by cubic curve? – YNK Jan 29 '22 at 09:50
  • Aha... is my description inaccurate? Blast... What would the curve that i have attached in the picture be referred to, as? I'll go ahead and update the post as soon as I know what is the proper terminology here... In a 3D program, the curve that forms by connecting the vertices by straight lines, is referred to as 'linear' or '1 degree' curve. The dark grey, smooth curve in the picture I attached, is formed by the same vertices, but is referred to as 'cubic' or '3 degree'. What would be the correct term to use in mathematics? – Pete Jan 29 '22 at 10:00
  • Have you heard of the term cubic spline? A cubic spline is a curve constructed of piecewise third-order polynomials which pass through a set of points. I think your curve is a collection of such splines, where each spline connects three adjacent points. – YNK Jan 29 '22 at 10:18
  • Aha! We do indeed call them splines too. Appreciate the help, good sir! I'll leave this up, but try googling against that term instead, and see if i get any results. I have updated the term in my original question. Thank you! – Pete Jan 29 '22 at 10:42
  • From your picture, it does not look like a cubic spline. Cubic splines go through their support points, but the picture and your description appear to be that of a Bezier curve, which (other than the linear first order curves) do not go through the support points, The arclength formula for Bezier curves will be different from that of a cubic spline. – Paul Sinclair Jan 30 '22 at 04:44
  • See here for length calculations for Bezier curves. But note that the conclusion is you are better off using numerical methods to calculate it rather than formulae. – Paul Sinclair Jan 30 '22 at 04:50
  • @PaulSinclair I see... I did come across this suggestion in my google searches, but I only know bezier curves (again, from a 3D program) as curves who's control points have definable tangents which i can move separately from the control point. This made me think that I am not necessarily dealing with a bezier curve. Should I change the title in order to minimize confusion? – Pete Jan 30 '22 at 04:53
  • Thanks Paul, let me give that a read and try my best at deciphering it, haha – Pete Jan 30 '22 at 04:54
  • Bezier curves are formed by layers of linear interpolation. Cubic splines ("spline" is a general term for an interpolating curve) simple interpolate between the support points using cubics instead of lines, with the added condition that the entire curve has a continuous derivative (no sharp corners). They are not hard to calculate, but tend to look a little wonky, with odd twists to line up with the next support point. Visually, Bezier curves look much nicer, and thus are generally preferred for graphics. – Paul Sinclair Jan 30 '22 at 05:16
  • To me, your curve looks like a cubic spline expressed in b-spline form. The "vertices" in your picture have a few different names: control points, control vertices (CV's), deBoor points, poles, etc. – bubba Jan 30 '22 at 12:07
  • See https://math.stackexchange.com/a/61796/589 – lhf Jan 30 '22 at 12:21

1 Answers1

0

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.

bubba
  • 43,483
  • 3
  • 61
  • 122
  • Thanks for the write up, this looks great! I'll look into understanding it a bit. I do not know how to read any of the equations that have been mentioned here in the first place, haha. Though, I'm not opposed to learning, so if #1 would give me preferable results, I'm inclined to learn what's necessary. Though - there's a reason I want to build myself a function that works just by passing it a list of points defined by only world x, y and z coords. I wonder if there's is something that is just plug-and-play, so that I could reverse engineer my understanding of it... – Pete Jan 30 '22 at 12:06
  • I don't think the results from option #1 would be any better than option #2. – bubba Jan 30 '22 at 12:11
  • Even for option #2, you'll have to learn a bit about splines to write a function that calculates a point on the curve (if you don't already have that function). – bubba Jan 30 '22 at 12:13
  • The list of (x,y,z) coordinates of the vertices is not enough info to completely define the curve. You also need the curve's knot values. – bubba Jan 30 '22 at 12:14
  • Thanks bubba! In the 3D app I'm using, I don't define the knots myself though. All I as the user do, is define the control points positions, so I assume the app is doing some automatic setting of their position (Is there possibly an algorithm that does this, that would be fair to assume the app is using?). Further more, am I correct to assume that a knot is defined as a point along a curve? Therefore defined by a u value? In my app, the u value of a curve ranges from 0 to 1. Is this the value I'm looking for? In this example, is it the purple cross? – Pete Feb 01 '22 at 00:10
  • Yes, knot values are the parameter values of the locations where adjacent cubic segments together. So, if the curve's parameter range is normalized in the usual way, the knot values will be in the range 0 to 1. The purple crosses that you drew look like the points corresponding to the knot values. – bubba Feb 03 '22 at 10:33
  • And yes, there are a few common ways to fabricate knot values. The simplest is to make the interior knots equally spaced, so the knots for your second curve would be 0,0,0,0, 1/3, 2/3, 1,1,1,1. More sophisticated approaches make the knot spacing proportional to the distances between control points somehow. There are many options. None is universally best. – bubba Feb 03 '22 at 10:35
  • Thanks bubba, very much appreciate the help! – Pete Feb 05 '22 at 08:51