[Math] How to calculate a spline’s length from its control points and knots vector

algorithmsapproximationinterpolationsplinevector analysis

I'm working in a C# program that reads *.dxf files and calculates each entity's length. At this moment I can get almost all entities' lengths except for the spline.

After reading the document, I get a list of spline control points, a knots vector and the degree of the curve, like below:

Control Points

(1209.38, 2349.97)
(981.23,  1786.57)
(1414.02, 1346.80)
(1927.99, 1475.88)
(2282.55, 2010.90)
(2855.24, 2176.91)
(3276.81, 1713.33)
(3101.50, 1170.94)
(2509.71, 1140.27)
(1944.97,  772.71)
(2547.01,  778.13)
(2762.70,  582.84)

Knots vector

 [0.00, 0.00, 0.00, 0.00, 648.95, 1468.25, 2588.90, 3362.22, 4111.19, 
  4863.87, 5446.02, 6369.53, 6560.23, 6560.23, 6560.23, 6560.23]

Degree: 3 / Order: 4

My question is, with that information, which algorithm or method should I use to get the length of the spline?

Best Answer

B-spline curve's length is computed as $L=\int_0^u|C'(t)|dt=\int_0^u\sqrt{x'(t)^2+y'(t)^2+z'(t)^2}dt$, which is typically done via numeric integration. There are tons of numeric integration methods to choose from. You can visit the Wiki page here for reference.

If you don't need a very accurate measurement for the curve's length and a rough value is good for you, then you can sample points along the curve and compute the length for the polyline formed by these sample points. The computed value will always be smaller than the actual curve length. Alternatively, you can also perform knot insertion to refine the control polygon and compute the length of the control polygon and the computed value will always be greater than the actual curve length.