Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Library for generating cubic spline trajectories (not interpolation)?

A little background. I have a simulation that uses cubic splines for 1D trajectories. In this context, a cubic spline specifies an object's position, velocity, acceleration, and jerk as a function of time.

If you have:

  • initial and final values for position, velocity, acceleration, and time
  • constant-value constraints on the maximum and minimum velocity, acceleration, and jerk

then there is a unique spline. If you don't specify the final time, but instead want the minimum-time trajectory, then there is also a unique spline.

Actually finding these splines can be a royal pain, though. In the case where time is specified, a spline will consist of up to 7 polynomials, and the knots (transition points between polynomials) aren't known ahead of time.

This is not the usual case of fitting a spline to a set of data, it's creating splines from the boundary conditions and some additional constraints. I've read papers where people have used similar arrangements and have had similar needs, but I've never found any libraries (or even source code) that tackles generating splines of this sort. I've written some code that handles most cases, but it isn't terribly robust or fast. I'm not very worried about it being fast, but more robust would be great.

Are there any libraries that can do this available? Open source code, even if not built as a library? C, C++, Java, or Python preferred, but if it's open source other languages would still be useful as a reference.

like image 392
Dan Homerick Avatar asked Dec 06 '10 00:12

Dan Homerick


People also ask

Is cubic spline interpolation?

Cubic spline interpolation is a way of finding a curve that connects data points with a degree of three or less. Splines are polynomial that are smooth and continuous across a given plot and also continuous first and second derivatives where they join.

Is cubic spline interpolation the best?

Runge's phenomenon tells us that such an approximation often has large oscillations near the ends of the interpolating interval. On the other hand, cubic spline interpolation is often considered a better approximation method because it is not prone to such oscillations.

Can spline functions be used for interpolation?

In the mathematical field of numerical analysis, spline interpolation is a form of interpolation where the interpolant is a special type of piecewise polynomial called a spline.

What is a spline interpolation used for?

Cubic spline interpolation is a mathematical method commonly used to construct new points within the boundaries of a set of known points. These new points are function values of an interpolation function (referred to as spline), which itself consists of multiple cubic piecewise polynomials.


2 Answers

There is a boost library for C++ that is open source and might get you half-way there.

It has all the basic building blocks you need I think (Legrendre/Laguerre/Hermite polynomials, root finding, etc...), though it comes short of actually calculating splines.

The library documentation is here so you can check for yourself: http://www.boost.org/doc/libs/1_45_0/libs/math/doc/html/index.html

like image 93
J T Avatar answered Nov 13 '22 22:11

J T


The problem with splines is that you have to solve simultaneous linear equations to solve the conditions. If your situation has any more information about some of those derivatives, you may be able to use Piecewise Cubic Hermite Interpolation (PCHIP).

For example, instead of defining that jerk must be zero, you could come up with a different constraint, use PCHIP, and solve your problem greedily. Anyway, it's something to remember even if you can't use it this time.

http://www.mathworks.com/moler/interp.pdf

like image 43
Dov Avatar answered Nov 13 '22 22:11

Dov