Cheap way of calculating cubic bezier length

后端 未结 6 2048
遇见更好的自我
遇见更好的自我 2021-02-04 03:12

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 rang

6条回答
  •  粉色の甜心
    2021-02-04 03:46

    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.

提交回复
热议问题