Closed xu2555 closed 5 years ago
Catmull-Rom-Spline?
Hi @xu2555,
what you need is known as cubic spline interpolation
. TinySpline provides the following function: BSpline::interpolateCubic
Hi @msteinbeck ,
I am using c, and assume this is the function to call. tsError ts_bspline_interpolate_cubic(const tsReal points, size_t n, size_t dim, tsBSpline spline, tsStatus *status);
Could you provide some example codes to use it?
Thank you!
Let's say you have 5 points in 3D. You can create a cubic spline passing these points with:
tsBSpline spline;
tsReal points[15];
points[0] = 1;
points[1] = -1;
points[2] = 0;
points[3] = -1;
points[4] = 2;
points[5] = 0;
points[6] = 1;
points[7] = 4;
points[8] = 0;
points[9] = 4;
points[10] = 3;
points[11] = 0;
points[12] = 7;
points[13] = 5;
points[14] = 0;
ts_bspline_interpolate_cubic(points, 5, 3, &spline, NULL);
The resulting spline (spline
) is a sequence of cubic bezier curves connecting each point in points
. There is an example using the C interface: https://github.com/msteinbeck/tinyspline/blob/master/examples/c/interpolation.c To run this example:
TINYSPLINE_FLOAT_PRECISION=Yes
.You may also have a look at the Java example: https://github.com/msteinbeck/tinyspline/blob/master/examples/java/Swing.java In this example, I use TinySpline to interpolate a spline from a given list of points and render it's sequence (bezier curves) one after another using Swing (https://github.com/msteinbeck/tinyspline/blob/master/examples/java/Swing.java#L78).
This works very well! Thank you very much!
Hello,
This works very well, thank you!
How to make result curve passes control points?
Regards,