求贝赛尔 曲线的长度

Quadratic Bezier curves are defined by second order polynominal, andcan be written as
Quadratic BezierCurve, krzywa Beziera st II,
where t is real parameter with values in range [0,1]. P'sare respectively curve starting point, anchor point and the end point.Derivative of the quadratic Bezier curve can be written as
Quadratic BezierCurve dervative, pochodna krzywa Beziera st II.

Length of any parametric (in general length of any well defined curve) curve can be computated using curve length integral.In case of 2nd order Bezier curve, using its derivatives, this integral can be written as
Curve Length Integral, dlugosc krzywej.
To simplify this integral we can make some substitutions. In this case it we will look like this
.
Next after doing some algebra and grouping elements in order to parameter t we will do another substitutions (to make this integral easier)
.

Finally we get simplified inegral, that can be written in form
Integral to calculate, całka do policzenia
This integral can be 'easily' simplified and calculated using relation
target integral, docelowa całka,
but we need to do some more substitutions
.

After doing elementary algebra we finaly get our expression. To calculate length of quadratic Bezier curve with thisexpression all we need arecoordinates of end points and control point. We dont need to use iterative methods anymore.
Quadric Bezier curve length, dlugosc krzywej Beziera st II.

Accuracy of this evaluation

To check accuracy we will evalute length of quadric Bezier curve using previously calculated expression and approximation algorithm.Used algorithm approximates a Bezier curve with a set of line segments and calculates curve length as a sum over lengths of all that line segments.

In this case we will use a series of quadric Bezier curves. All curves have the same end points. For each curve control point is taken from a set ofpoints equally spaced on a circle, with given radius and centered in the middle between end points.

Presented plot shows comparison of curve length calculated using both (our expression and line approximation) methods for a set of Bezier quadriccurves. Green line shows results from approximation method, curve lengths calculated using our expression are drawn with red cross

Implementation

Implementation in c language can look as follows

float blen(v* p0, v* p1, v* p2)
{
v a,b;
a.x = p0->x - 2*p1->x + p2->x;
a.y = p0->y - 2*p1->y + p2->y;
b.x = 2*p1->x - 2*p0->x;
b.y = 2*p1->y - 2*p0->y;
float A = 4*(a.x*a.x + a.y*a.y);
float B = 4*(a.x*b.x + a.y*b.y);
float C = b.x*b.x + b.y*b.y;

float Sabc = 2*sqrt(A+B+C);
float A_2 = sqrt(A);
float A_32 = 2*A*A_2;
float C_2 = 2*sqrt(C);
float BA = B/A_2;

return ( A_32*Sabc + A_2*B*(Sabc-C_2) + (4*C*A-B*B)*log( (2*A_2+BA+Sabc)/(BA+C_2) ) )/(4*A_32);
};
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值