Closed williamsnider closed 2 years ago
When doing reparametrization as you are asking for here, you will enter the realm of approximations so you will for sure have to make some compromises here. With that out of the way, let's look at some of your alternatives. You can find all functions discussed here in the curve_factory
class and it has a number of curve-fitting tools
Cubic spline approximation is the industry standard if you don't have any particular needs. The splipy implementation also results to arc-length parametrization unless specifically told to do otherwise. Simply evaluate your curve at a number of points and feed it to cubic_curve
. Uniform sampling of the evaluation points can be done in this particular case, but in general it is better to use the greville absiccae or knot averages as they guarantees existence of solution when doing interpolation
t = basis.greville() # evaluation points
x = curve(t)
curve2 = curve_factory.cubic_curve(x)
You've specifically created the quadratic knot vector and if this choice was important to you then you can call the more general interpolate
-function which fits your curve on a particular basis. When using this you will need to know the arclength between different points, and this can be done by calling length()
t = basis.greville() # interpolation parametric points
x = curve(t) # interpolation geometric points
s = [curve.length(0,t0) for t0 in t] # parametric values on new (arc-length parametrized) knot vector
basis.reparam(0, curve.length()) # rescale the knot vector so it goes from [0, 5.8] instead of [0,1]
curve2 = curve_factory.interpolate(x, basis, s) # do the actual interpolation
There is also a quite flexible fit
-function which will do adaptive knot insertion to ensure that your approximation stays within tolerance requirements, but for your application here, I don't think you will need to resort to using this.
Thank you! This is very helpful.
I'm generating a quadratic b-spline curve from a set of controlpoints and a knot vector. How can I reparametrize the curve so that it is parameterized according to the arc / curve length? For example, if the curve is parameterized for t=0 to t=1, inputting t=0.2 should give the curve coordinate that occurs when the distance along the curve is 20% of it's total length.
Basically, how do I generate a second B-Spline that is parameterized according to its length? I am OK with a solution that is reasonably approximate.
This code example illustrates my issue - the resulting red asterisks on the plot are not equally spaced, even though the parametric values (u) were.