## High-Precision Bezier Curves

Version 6.0.5 (11.1 KB) by
Fast, robust and accurate arbitrary-dimension and precision Bezier curve generation from its control points and/or knots.

Updated 9 May 2022

Syntax
y = bspl(x)
y = bspl(x, t)
y = bspl(x, t, dim)
y = bspl(x, t, dim, bin)
Description
y = bspl(x, t, dim, bin) Returns the Bézier curve 'y' that results from evaluating the control points 'x' with a knot vector 't' along the dimension specified in 'dim'. An optional parameter 'bin' could parse the binomial coefficient terms to be used. In the event of parsing a scalar value as knot, then a uniform knot vector with the parsed resolution would be used.
Please refer to the code section for a detailed description of the functions used. It is recommended that the case-allocation coefficients are adjusted based on the specifications of the machine that runs this code for maximum speed, using speed routines as the one shown in the last example.
Examples
% Bezier curve evaluation
x = rand(randi(4) + 2, randi(2) + 1);
a = bspl(x);
b = bspl(x, rand(10, 1));
figure
hold on
if size(x, 2) > 2
plot3(a(:, 1), a(:, 2), a(:, 3))
plot3(x(:, 1), x(:, 2), x(:, 3))
plot3(b(:, 1), b(:, 2), b(:, 3), 'o')
view(3)
else
plot(a(:, 1), a(:, 2))
plot(x(:, 1), x(:, 2))
plot(b(:, 1), b(:, 2), 'o')
end
title('Generalised Curve')
legend('curve', 'points', 'knots')
% Piece-wise input
x = [0.73, 0.72; 0.48, 0.85; 0.24, 0.97; 0.23, 0.89; 0.23, 0.89; 0.23, 0.80;
0.46, 0.51; 0.56, 0.42; 0.56, 0.42; 0.67, 0.33; 0.65, 0.45; 0.64, 0.57];
a = bspl(x, 50);
b = [x(1, :); x(diff(x(:, 1)) == 0, :); x(end, :)];
figure
hold on
plot(a(:, 1), a(:, 2))
plot(x(:, 1), x(:, 2))
plot(b(:, 1), b(:, 2), 'o')
title('Piece-Wise Curve')
legend('curve', 'points', 'nodes')
% High-order approximation
x = 2 * pi * (0 : 1 / (5e3 - 1) : 1)';
x = [x, exp(-x / 2) .* sin(2 * x) + 5e-3 * (rand(5e3, 1) - 0.5)];
a = bspl(x, 1e4);
figure
hold on
b = plot(a(:, 1), a(:, 2), 'LineWidth', 7);
b.Color(4) = 0.1;
plot(x(:, 1), x(:, 2), '.', 'MarkerSize', 1)
title('Data Approximation')
legend('Fitted', 'Data')
% Iterative workflow
b = [1 4 6 4 1];
figure
hold on
h = cell(4, 1);
for i = 1 : 4
x = rand(1, 5);
plot(bspl(x, [], 1, b))
h{i} = strcat('curve_', num2str(i));
end
title('Workflow Example')
legend(h)
% Speed test
n = 500;
t = zeros(n, 1);
bspl(rand(n));
for i = 1 : n
x = rand(i, 2);
tic
for j = 1 : 10
bspl(x, 10);
end
t(i) = toc / j;
end
figure
plot(smooth(t))
title('Speed Test')

### Cite As

Moreno, M. (2023). High-Precision Bezier Curves (https://www.mathworks.com/matlabcentral/fileexchange/109179-high-precision-bezier-curves), MATLAB Central File Exchange. Retrieved .

##### MATLAB Release Compatibility
Created with R2022a
Compatible with any release
##### Platform Compatibility
Windows macOS Linux

### Community Treasure Hunt

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

Start Hunting!
Version Published Release Notes
6.0.5

Multi-dimensional piece-wise size correction: ii = p * (a - 1) + 1 : p * a

6.0.4

Matrix form of composite curves for multi-threaded operation. Unequally-sized curve segments corrected via knot insertion. Correction of default piece-wise curve resolution

6.0.3

Optimised piece-wise processing: fastest processing and removal of final query knot interpolation through a 'dynamic' knot vector

6.0.2

Medium-sized problems: correction of linear indices in z(i, :) + u(:, i)

6.0.1

Piece-wise knot correction, faster binomial coefficients, optional parameter to parse binomial coefficient as input, better description text.

6.0.0

Support for piece-wise functions and speed boost for small cases using de casteljau's algorithm

5.0.2

Parse special cases: linear interpolation and single point

5.0.1

Speed increase at low and medium orders, and typo correction removing the end-values of 'x' in the logarithmic case

5.0.0

Operation optimisation via test function

4.0.1

Enhanced input checks

4.0.0

Figure change

3.0.2

Memory optimisation, faster initialisation, input checks and description text enhancement

3.0.1

End-point NaN corrections

3.0.0

Overflow free and exponentially-increased precision.

2.0.1

Exponent typo in vectorised calculation

2.0.0

More robust overflow handing and significant speed boost for medium-sized data sets

1.0.3

Overflow and saturation handling. Addition of test function

1.0.2

Single-point evaluation of 't' if the query value is non-natural. Enhancement of the description text

1.0.1

Enhancement of knot insertion algorithm and description texts

1.0.0