-
-
Notifications
You must be signed in to change notification settings - Fork 210
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Controlling the knots for non-uniform spline interpolation #98
Comments
The knot vector is scaled to the default domain of [0, 1] where each internal knot describes the bounds of the Bezier curve B_n. For instance, the knot vector of a spline which has been interpolated of four points looks like this:
where:
Arranging the knot vector like this makes perfectly sense since To be honest, I never heard or read about an interpolation algorithm which allows one to specify the points to interpolate as well as the knot vector to create. Maybe you have a reference for such an algorithm? However, what you can do is to insert particular knots values using
Unfortunately, TinySpline does not provide a function to remove a particular knot value from a spline. This operation is specified for splines but not easy to implement though, see #11. If you find some code which allows you to remove a knot value from a spline you could use |
One of the things i find stimulating about splines is that everyone who writes or codes about them seems to use slightly different terminology. For example, you see a cubic B-spline as being a series of Bézier curves, which i hadn't come across before. I originally learned cubic splines as being a series of cubics, but without the idea that those cubics were Béziers. Meanwhile, most of the more mathematical treatments of B-splines i see are all about the basis functions. Some genius at the University of Edinburgh has an interactive demonstration of non-uniform B-splines, where the knots can be dragged around the axis of the parametric coordinate: http://www.inf.ed.ac.uk/teaching/courses/cg/d3/nonbspline.html Einspline has an implementation: http://einspline.sourceforge.net/NUBinterface.shtml I can't imagine anyone wanting to use them for graphics. However, they are quite useful for interpolating functions, where you don't necessarily have samples of the function at evenly-spaced points. |
A series of cubics and a series of cubic Bezier curves, actually, are the same since cubic Bezier curves can be written as cubic functions, see https://wikimedia.org/api/rest_v1/media/math/render/svg/504c44ca5c5f1da2b6cb1702ad9d1afa27cc1ee0. I do not see B-Splines as sequences of Bezier curves in general. Only
Hmm, I can't find any function which allows you to interpolate a spline with given points and given knot vector. Maybe I misunderstood your question. It looks like you just want to interpolate NURBS. TinySplines handles NURBS as well and, of course, supports to interpolate cubic NURBS by using homogeneous coordinates.
As shown by your example, the shape of a B-Spline changes if its knot vector gets modified. You can of course set the knot vector of a spline using |
You firstly call
What the example shows is that a B-spline can be interpolated through a set of data points regardless of what its knot vector is. It is indeed true that the fit changes as the knot vector is changed. In any case, i don't want to modify the knot vector of an existing spline, i want to fit a spline using a specified knot vector. The example was meant to show that a B-spline with a non-uniform knot vector is possible. It's quite likely i've phrased my question wrongly, and quite possible that i've misunderstood some terms. I'll step back a bit and try to explain what i'm trying to achieve. I have some samples of a function which i believe to be continuous and smooth:
I would like to interpolate values between those samples. If i pass the y values alone to if i pass both the x and y values to Is there any way to do this using TinySpline? |
Now I see what you are trying to do and it looks like you are mixing up how einspline and TinySpline define the term That being said, in terms of TinySpline you want to interpolate a two-dimensional spline because your data points consist of two components, x and y respectively.
TinySpline, unlike einspline, supports only splines, not surfaces and... seriously, how do you call a surface in 3D? Anyhow, splines are exactly what you need because you want to interpolate a cubic function like this: As explained above, Now, let's have a look at the knot vector thing. You want to extrapolate data using the knot vector, for instance, like this: tsBSpline spline;
ts_bspline_interpolate_cubic(points, n, // <-- your data
2, // <-- we need a two-dimenstional spline
&spline);
tsDeBoorNet net;
ts_bspline_evaluate(&spline,
10, // <-- this is your lowest x-value
&net); but this is not how the knot vector is working, regardless of how you set its values up. The knot vector describes the domain of a spline, for instance [0, 1]. That is, you can extract a point laying on a spline by evaluating it at a given knot value for (int u = 0; u <= 1.0; u += 0.0001)
{
ts_bspline_evaluate(&spline, u, &net);
} you could draw the spline point by point. The smaller the incrementation of Now, how do we extract a certain y-value for a given x-value? What we need is called the bisection method which, basically, is binary search in continuous space (which our domain is). To put it in an algorithm, you need something like this:
The idea is to interactively find the knot value Why is this working? Your input data is strictly monotonically increasing in
If you sort your input values according to x and pass it to Unfortunately, TinySplien does not provide a ready to use function for the bisection method. However, a PR would be welcome :). I already thought about implementing this function but other things are more important yet. I hope I could clear some things up. |
@tomwhoiscontrary, could I help you with your issue? |
I close this issue for now. Don't hesitate to reopen. |
Apologies for not replying sooner. I'm certainly happy for this to be closed! I think the answer to my original question of "is there any way to interpolate values using a non-uniform spline with specific knots?" is "no", and the follow-up to that is the suggestion to treat one-dimensional functions as two-dimensional curves, which will work in practice. Oh, and i think the generic name for a line/surface/etc is a "manifold", but i'm not a mathematician! |
I would like to use a one-dimensional spline to approximate a function, by interpolation. However, i would like to pick specific x values for the knots, creating a non-uniform spline.
It looks to me like ts_bspline_interpolate_cubic always spaces the knots evenly. Is there any way to interpolate values using a non-uniform spline with specific knots?
The text was updated successfully, but these errors were encountered: