Bezier curves in Scilab

As a reminder, a Bezier curve is defined by control points. The first and last point are nodes of the curve. The other points allow you to define the shape of the arc.

Mathematically, from the control points [P0, P1, …, Pn], a Bezier curve is the set of points defined by the parametric representation
\forall ~t \in [0;1], ~~Z(t) = \sum \limits_{i = 0}^{n} B_i^n(t) \cdot P_i
where B_i^n are the Bernstein polynoms.

The bezier and bernstein functions have been added in Scilab 2024.1.0.

Please find below some examples of Bezier curves computed and plotted using Scilab:

  • Simple example: S of Scilab
t = linspace(0, 1, 1000);
P = [1.7 3; 1 3; 1 2; 2 2;2 1; 1.3 1];
z = bezier(P, t);
plot(P(:,1), P(:,2), "r.", "thickness", 3);
gca().data_bounds = [0.8 0.8; 2.2 3.2];
plot(z(:,1), z(:,2), "b", "thickness", 3)

s_bezier

  • \infty symbol computed from a single set of control points
t = linspace(0, 1, 1000);
R = [0 0; 2 2; 2 -1.6; 0 -2; 0 0; 0 2; -2 1.6; -2 -2; 0 0];
z = bezier(R, t);
plot(R(:,1), R(:,2), "r.", "thickness", 3);
gca().data_bounds = [-2.2 -2.2; 2.2 2.2];
plot(z(:,1), z(:,2), "b", "thickness", 3)

infinity_bezier

  • Advanced example with multiple parts. In this example, the comet function is used instead of plot function to get an animated draw.
t = linspace(0,1,1000);
p1 = [0 0;-1 -1; 1 -1; 0 0];
z1 = bezier(p1, t);
p2 = [0 0; 1 -1; 2 0; 0 0];
z2 = bezier(p2, t);
p3 = [0 0; 2 0; 1 1; 0 0];
z3 = bezier(p3, t);
p4 = [0 0; 1 1; -1 1; 0 0];
z4 = bezier(p4, t);
p5 = [0 0; -1 1; -2 0; 0 0];
z5 = bezier(p5, t);
p6 = [0 0; -2 0; -1 -1; 0 0];
z6 = bezier(p6, t);
P = [p1; p2; p3; p4; p5; p6];
u = unique(P, "r");

z = [z1; z2; z3; z4; z5; z6];
plot(u(:,1), u(:,2), "r.", "thickness", 3);
xpoly(P(:,1), P(:,2));
set(gce(), "foreground", color("red"));
gca().data_bounds = [-2.2 -1.2; 2.2 1.2];
comet(z(:,1), z(:, 2), "colors", "orange");

bezier3

Don’t hesitate to share your use cases and report issues.