Skip to content
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

Simple question for C# usage #213

Closed
aharontaam opened this issue Sep 7, 2022 · 10 comments
Closed

Simple question for C# usage #213

aharontaam opened this issue Sep 7, 2022 · 10 comments

Comments

@aharontaam
Copy link

aharontaam commented Sep 7, 2022

Very simple question here:
How one can get the set of values of y's for arbitrary set of x's.
All I see is evaluate for knot values not for x's

@msteinbeck
Copy link
Owner

Hi @aharontaam,

Bisect is probably what you are looking for. There is a C++ example: https://github.com/msteinbeck/tinyspline/blob/master/examples/cxx/time_series.cpp

Please see the C documentation for more details: https://msteinbeck.github.io/tinyspline/tinyspline_8h.html#ab595c9894abafd308ed32bbf0e50656e

@Aharon-Tam
Copy link

That was quite helpful. Thanks.

I have another question.
Say I interpolate over 6-7 points of monotonously increasing curve;

  1. How do I get the first 5-7 coefficients of the fitting polynomial?
  2. How do I get the convexity values at a given sets of x's ?

@msteinbeck
Copy link
Owner

We need to clarify some terms first:

Say I interpolate over 6-7 points of monotonously increasing curve;

Do you mean Monotone Cubic Interpolation? TinySpline doesn't provide a function for this kind of interpolation (yet). Or do you mean that you interpolated a spline with one of TinySpline's interpolation functions where the x component of the points to be interpolated is monotonously increasing?

How do I get the first 5-7 coefficients of the fitting polynomial?

Please note that the coefficients of B-Splines are not the same as the coefficients of functions (y = f(x)). Converting a B-Spline to the latter seems to be quite messy and I couldn't find a general solution yet. If you need the former, please have a look at: https://pages.mtu.edu/~shene/COURSES/cs3621/NOTES/spline/B-spline/bspline-curve-coef.html If needed, I can add this to TinySpline's API.

How do I get the convexity values at a given sets of x's ?

I'm not sure what the convexity of a spline is. Do you mean the second derivative? I yes, you can derive the spline twice:

BSpline spline = ...;
BSpline convexity = spline.Derive(2);

and call Bisect on convexity:

Vec2 vec = convexity.Bisect(x).ResultVec2();

@Aharon-Tam
Copy link

Aharon-Tam commented Sep 10, 2022

  1. When I said monotonic increasing function, I meant for a 2D curve the y's values are increasing for each consecutive x's.
    Which most like to fit a n-degree polynomial such that y(x) = f(x) = a0+ a1x + a2x^2 + a3x^3 + a4x^4 + ...
    a0, a1, a2, a3, a5, ... are those coefficients that I am looking for.
    I will check the notes on the b-spline coefficients that you sent me and see how far I can go with it.
  2. And yes, for convexity, I meant the second derivative which it seems you have a solution for it.

@msteinbeck
Copy link
Owner

Which most like to fit a n-degree polynomial such that y(x) = f(x) = a0+ a1x + a2x^2 + a3x^3 + a4x^4 + ...
a0, a1, a2, a3, a5, ... are those coefficients that I am looking for.

Given that your spline is cubic, you can try to decompose it into a sequence of Bezier curves (see Listing 7 in our paper for more details) and compute a quintic function using Hermite interpolation for each Bezier segment where x0 is the first control point of each segment and x1 ist the last control point of each segment.

Note that Hermite interpolation can also be used for polynomials of higher degree.

@Aharon-Tam
Copy link

Thanks

@msteinbeck
Copy link
Owner

Please note that I didn't test this approach. Your need to check whether the computed quintic function produced the same (or at least a suitable approximation) curve as your spline.

@msteinbeck
Copy link
Owner

Could you solve your issue? If yes, please close this issue.

@Aharon-Tam
Copy link

Yes, issued solved.

@msteinbeck
Copy link
Owner

Are you using quintic Hermite interpolation? Does it produce the same output as your spline?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants