Quadratic Bézier curves is defined by second order polynominal, Andcan is written as
where T is real parameter with the values in range [0,1]. P ' Sare respectively curve starting point, Anchor Point and the end point. Derivative of the quadratic Bézier curve can be written as
Length of any parametric (in general, length of any, defined curve) curve can be computated using curve length integral . In case of 2nd order Bézier curve, using its derivatives, this integral can is written as
To simplify the integral we can make some substitutions. In this case it we'll look like this
Next after doing some algebra and grouping elements on order to parameter T we'll do another substitutions Integral easier)
Finally we get simplified inegral, that can is written in form
This integral can is ' easily ' simplified and calculated using relation
But we need to do some more substitutions
After doing elementary algebra we finaly get our expression. To calculate length of quadratic Bézier curve with thisexpression all we need arecoordinates of end points and control poi Nt. We dont need to use iterative methods anymore. accuracy of this evaluation
To check accuracy we'll evalute length of quadratic Bézier curve using previously calculated expression and Approximatio n Algorithm. Used algorithm approximates a Bézier curve with a set of line segments and calculates curve length as a sum over lengths O F All this line segments. In this case we'll use a series of quadratic Bézier curves. All curves has the same end points. For each curve control point was taken from a set ofpoints equally spaced on a circle, with given radius and centered in th E Middle between end points. Presented plot shows comparison of curve length calculated using both (our expression and line approximation) methods for A set of Bézier quadriccurves. Green line shows results from approximation method, curve lengths calculated using our expression is 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 = (a.x*a.x + a.y*a.y);
float B = (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);
};
From: http://www.malczak.linuxpl.com/blog/quadratic-bezier-curve-length/