1
$\begingroup$

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?

1 Answers 1

1

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.

  • 0
    Thanks for you response @fang. Before asking, I had already tried the polyline method, but it's so imprecise. I need an accurate measure. In the definition that you provide me, I don't understand what "t" or "u" are and how can I get them from the data I have. According to what I searched on the internet, those "t" and "u" involve a parametric curve, but I don't know how to get a parametric curve with the control points.2017-02-22
  • 0
    The "t" is indeed the parameter. The "u" is the parameter value you want to integrate to. In your case where the knot vector ranges from 0 to 6560.23, then the value of "u" would be 6560.23 so that you can evaluate the length of the entire curve.2017-02-22
  • 0
    Since you already have the degree, knot vector and the control points, your B-spline curve is fully defined and you should be able to evaluate any point or derivative from the B-spline curve. If you don't know how, please google "Cox DeBoor" recursive formula or try to find an existing library that does that for you.2017-02-22
  • 0
    Thank you so much for your guidance, I'll try the De Boor algorithm2017-02-22