开发者

Library for generating cubic spline trajectories (not interpolation)?

开发者 https://www.devze.com 2023-01-28 07:06 出处:网络
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

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-t开发者_如何学JAVAime 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.


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


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


SciPy's interpolation functions might help... Plus you can get the derivatives or integrals of those splines easily... I'm not sure why you say "not interpolation"... It seems to me like that is what you are trying to accomplish.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号