简体   繁体   English

找到立方B样条的长度

[英]Finding the length of a cubic B-spline

Using scipy's interpolate.splprep function get a parametric spline on parameter u , but the domain of u is not the line integral of the spline, it is a piecewise linear connection of the input coordinates. 使用SciPy的的interpolate.splprep功能得到参数参数样条u ,但域u是不是花的线积分,这是输入的分段线性连接坐标。 I've tried integrate.splint , but that just gives the individual integrals over u . 我试过integrate.splint ,但只是给个人积分超过u Obviously, I can numerically integrate a bunch of Cartesian differential distances, but I was wondering if there was closed-form method for getting the length of a spline or spline segment (using scipy or numpy) that I was overlooking. 显然,我可以数字地整合一堆笛卡尔差分距离,但我想知道是否有闭合形式的方法来获得我忽略的样条或样条线段(使用scipy或numpy)的长度。

Edit: I am looking for a closed-form solution or a very fast way to converge to a machine-precision answer. 编辑:我正在寻找一种封闭形式的解决方案或一种非常快速的方式来收敛机器精度答案。 I have all but given up on the numerical root-finding methods and am now primarily after a closed-form answer. 我几乎放弃了数字根寻找方法,现在主要是在一个封闭形式的答案之后。 If anyone has any experience integrating elliptical functions or can point me to a good resource (other than Wolfram), That would be great. 如果任何人有任何集成椭圆函数的经验或者可以指向一个好的资源(除了Wolfram),那就太好了。

I'm going to try Maxima to try to get the indefinite integral of what I believe is the function for one segment of the spline: I cross-posted this on MathOverflow 我将尝试使用Maxima来尝试获得我认为是样条曲线的一个段的函数的无限积分:我在MathOverflow上交叉发布了它

Because both x & y are cubic parametric functions, there isn't a closed solution in terms of simple functions. 因为x和y都是立方参数函数,所以在简单函数方面没有封闭的解决方案。 Numerical integration is the way to go. 数值整合是要走的路。 Either integrating the arc length expression or simply adding line segment lengths - depends on the accuracy you are after and how much effort you want to exert. 集成弧长表达式或简单地添加线段长度 - 取决于您所追求的准确性以及您想要施加多少努力。

An accurate and fast "Adding length of line segments" method: 准确快速的“添加线段长度”方法:

Using recurvise subdivision (a form of de Casteljeau's algorithm) to generate points, can give you a highly accurate representation with minimal number of points. 使用recurvise细分(de Casteljeau算法的一种形式)生成点,可以用最少的点数为您提供高度精确的表示。 Only subdivide subdivisions if they fail to meet a criteria. 如果它们不符合标准,则仅细分细分。 Usually the criteria is based on the length joining the control points (the hull or cage). 通常,标准基于连接控制点(船体或笼子)的长度。 For cubic, usually comparing closeness of P0P1+P1P2+P2P3 to P0P3, where P0, P1, P2 & P3 are the control points that define your bezier. 对于立方,通常比较P0P1 + P1P2 + P2P3与P0P3的接近程度,其中P0,P1,P2和P3是定义贝塞尔曲线的控制点。

You can find some Delphi code here: link text 你可以在这里找到一些Delphi代码: 链接文本

It should be relatively easy to convert to Python. 转换为Python应该相对容易。 It will generate the points. 它会产生积分。 The code already calculates the length of the segments in order to test the criteria. 代码已经计算了段的长度以测试标准。 You can simply accumulate those length values along the way. 您可以在此过程中简单地累积这些长度值。

You can integrate the function sqrt(x'(u)**2+y'(u)**2) over u , where you calculate the derivatives x' and y' of your coordinates with scipy.interpolate.splev . 您可以将函数sqrt(x'(u)**2+y'(u)**2)集成到u ,您可以使用scipy.interpolate.splev计算坐标的导数x'y' The integration can be done with one of the routines from scipy.integrate ( quad is precise [Clenshaw-Curtis], romberg is generally faster). 可以使用scipy.integrate中的一个例程完成集成( quad精确[Clenshaw-Curtis], romberg通常更快)。 This should be more precise, and probably faster than adding up lots of small distances (which is equivalent to integrating with the rectangle rule). 这应该更精确,并且可能比添加大量小距离更快(这相当于与矩形规则集成)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM