One of the fastest way to calculate the length of a bezier curve is by breaking down the curve into straight-line segments, and then, obviously, add the length of each segment to get the final length of the curve.
Looking at the code from my previous post “The Cubic Bezier Form and Code”, you can see where each segment is calculated. All that we would need to do is to add a hold value to hold the previous segment end point and compute the distance to the current start of the new segment.
.
.
local length = 0;
if ( j > 1 ) then
local xx = x - prevPt.x
local yy = y - prevPt.y
length = length + math.sqrt((xx*xx) + (yy*yy))
end
prevPt.x = x;
prevPt.y = y;
.
.
.
This method is what I would consider a brute force method. I will do a follow up on finding the length of Bezier curves by using subdivision, and arc-length computation, To learn more about calculating the length of a bezier curve, see Jens Gravesen: “Adaptive subdivision and the length of Bezier curves” and Gravesen, Jens, “The Length of Bézier Curves”, Graphics Gems V, p. 199-205, code: ch4-7.
Webmentions
[…] my previous post “Calculating The Length of a Bezier Curve. Part I” I computed the length of a curve using a brute force method which in reality was really bad. But […]