# Arc length of Cubic Bezier Curve

20 views (last 30 days)

Show older comments

##### 0 Comments

### Answers (2)

cuneyt haspolat
on 6 Mar 2019

Hello,

After the bezier curve generation, you can take many samples from bezier curve.

hint: linscape can be used for taking samples on curve.

Then, euclidien norm can be used to find length. When number of sample is increased, accuracy will be increased. There is a direct proportion between number of sample and accuracy of the length.

bonus: For Nurbs curve length, nrbmeasure function is available in Piegl's toolbox. Discretization which is same as my advice is used as well and Integral is used to find curve length together.

##### 0 Comments

Moreno, M.
on 16 Apr 2022

If you have access to symbolic math, there is a way of calculating the analytic arc-length of a generic Bézier curve as the definite integral of the norm of the derivative of the curve. I use the functions bspl and bez2ber (find the polynomial form coefficients of the curve from its control points) that I have developed for this exercise:

function c = bez2ber(x)

n = size(x, 1) - 1;

N = prod(1 : n);

c = x;

for i = 1 : n - 1

I = prod(1 : i);

s = (-1) ^ i;

j = s * x(1, :) / I;

for k = 1 : i - 1

s = -s;

j = j + s * x(k + 1, :) / prod(1 : k) / prod(1 : i - k);

end

j = j + x(i + 1, :) / I;

c(i + 1, :) = N / prod(1 : n - i) * j;

end

s = (-1) ^ n;

j = s * x(1, :) / N;

for k = 1 : n

s = -s;

j = j + s * x(k + 1, :) / prod(1 : k) / prod(1 : n - k);

end

c(n + 1, :) = N * j;

end

% Control points and derivative polynomial form

dim = [4, 2];

X = rand(dim);

Y = bez2ber((dim(1) - 1) * diff(X));

% Analytic calculation

syms t

fun = zeros(1, dim(2));

for i = 1 : dim(1) - 1

fun = fun + Y(i, :) * t ^ (i - 1);

end

a = double(int(norm(fun), [0, 1]));

% Discrete arc-length approximation

b = diff(bspl(X, 1e3));

b = sum(sqrt(sum(b .* b, 2)));

error = abs(b - a) / a;

This would work for any Bézier curve, regardless the order or the dimension as long as the factorial calculations of the polynomial form are within the floating-point exception limits (dim(1) = 171). Overflows happen for more than 55 control points if the round(prod(1:n)) is used instead of prod(1:n). More stable approaches for factorial calculations can be used.

The error for a discrete evaluation of the arc-length using 1000 points in a random cubic Bézier would be:

[a; b; error]

ans =

1.29640077147666

1.29640027557947

3.82518436167337e-07

##### 1 Comment

Moreno, M.
on 16 Apr 2022

### See Also

### Categories

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!