用于生成三次样条轨迹的库(不是插值)?

发布于 2024-10-06 08:00:26 字数 541 浏览 4 评论 0原文

一点背景。我有一个使用三次样条来模拟一维轨迹的模拟。在这种情况下,三次样条将对象的位置、速度、加速度和加加速度指定为时间的函数。

如果您有:

  • 的初始值和最终值 位置、速度、加速度和 时间
  • 常数值约束 最大和最小速度, 加速度和加加速度

则有一个独特的样条曲线。如果您不指定最终时间,而是想要最短时间轨迹,那么还有一个唯一的样条线。

不过,实际上找到这些样条线可能是一件非常痛苦的事情。在指定时间的情况下,样条曲线将由最多 7 个多项式组成,并且节点(多项式之间的过渡点)事先未知。

这不是将样条线拟合到一组数据的常见情况,而是根据边界条件和一些附加约束创建样条线。我读过一些论文,其中人们使用了类似的安排并有类似的需求,但我从未找到任何库(甚至源代码)来解决生成此类样条的问题。我已经编写了一些处理大多数情况的代码,但它不是非常健壮或快速。我不太担心它的速度,但更强大就更好了。

有没有可以做到这一点的库?开源代码,即使不是作为库构建的?首选 C、C++、Java 或 Python,但如果它是开源的,其他语言仍然可以作为参考。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

七颜 2024-10-13 08:00:26

有一个用于 C++ 的开源 boost 库,可能会让您成功一半。

我认为它具有您需要的所有基本构建块(Legrendre/Laguerre/Hermite 多项式、求根等...),尽管它缺乏实际计算样条曲线。

库文档位于此处,因此您可以自行检查: http://www.boost.org/doc/libs/1_45_0/libs/math/doc/html/index.html

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

葬花如无物 2024-10-13 08:00:26

样条的问题在于您必须求解联立线性方程才能求解条件。如果您的情况有关于其中一些导数的更多信息,您可以使用分段三次 Hermite 插值 (PCHIP)。

例如,您可以提出不同的约束,使用 PCHIP,并贪婪地解决您的问题,而不是定义加加速度必须为零。无论如何,即使这次不能使用它,它也是值得记住的东西。

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

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

乄_柒ぐ汐 2024-10-13 08:00:26

SciPy 的插值函数 可能会有所帮助...另外你可以轻松获得这些样条线的导数或积分...我不确定你为什么说“不是插值”...在我看来,这就是你想要实现的目标。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文