计算立方贝塞尔长度的廉价方法 [英] Cheap way of calculating cubic bezier length
问题描述
的解析解决方案似乎并不存在,但这并不意味着
编码的廉价解决方案不存在。便宜的我的意思是在50-100纳秒(或更少)的范围内。
有人知道这样的事吗?也许在两个类别:
1)更少的错误,如1%但更慢的代码。
2)更多错误,比如20%但更快?
我通过google扫描了一下,但没有找到任何看起来像是一个很好的解决方案的东西。只有像N线段上划分
和总和N sqrt - 对于更精确的速度太慢,
,对于2或3段可能太不准确。
有什么更好的?另一种选择是将弧长估计为和弦和控制网之间的平均值。在实践中:
Bezier bezier = Bezier(p0,p1,p2,p3);
chord =(p3-p0).Length;
cont_net =(p0 - p1).Length +(p2 - p1).Length +(p3 - p2).Length;
app_arc_length =(cont_net + chord)/ 2;
然后,您可以递归地将样条线段分成两段,并计算到收敛的弧长。我测试了自己,实际上它收敛得非常快。我从这个论坛。
An analytical solution for cubic bezier length seems not to exist, but it does not mean that coding a cheap solution does not exist. By cheap I mean something like in the range of 50-100 ns (or less).
Does someone know anything like that? Maybe in two categories:
1) less error like 1% but more slow code. 2) more error like 20% but faster?
I scanned through google a bit but it doesn't find anything which looks like a nice solution. Only something like divide on N line segments and sum the N sqrt - too slow for more precision, and probably too inaccurate for 2 or 3 segments.
Is there anything better?
Another option is to estimate the arc length as the average between the chord and the control net. In practice:
Bezier bezier = Bezier (p0, p1, p2, p3);
chord = (p3-p0).Length;
cont_net = (p0 - p1).Length + (p2 - p1).Length + (p3 - p2).Length;
app_arc_length = (cont_net + chord) / 2;
You can then recursively split your spline segment into two segments and calculate the arc length up to convergence. I tested myself and it actually converges pretty fast. I got the idea from this forum.
这篇关于计算立方贝塞尔长度的廉价方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!