# Bezier curves in Scilab

**URL:** <https://scilab.discourse.group/t/bezier-curves-in-scilab/610>\
**Category:** Graphics and plotting\
**Created:** [August 14, 2024, 7:25am UTC](https://scilab.discourse.group/t/bezier-curves-in-scilab/610 "2024-08-14T07:25:31Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![adeline.carnis](https://avatars.discourse-cdn.com/v4/letter/a/6bbea6/32.png) [@adeline.carnis](https://scilab.discourse.group/u/adeline.carnis)\
**Post date:** [August 14, 2024, 7:25am UTC](https://scilab.discourse.group/t/bezier-curves-in-scilab/610/1 "2024-08-14T07:25:31Z")

</div>

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](https://help.scilab.org/bezier.html)** and **[bernstein](https://help.scilab.org/bernstein.html)** 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

```auto
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](https://global.discourse-cdn.com/free1/uploads/utc/original/1X/b0852dd2c06aad21b5db5d5d4e99d54cc0386a50.png)

- \infty symbol computed from a single set of control points

```auto
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](https://global.discourse-cdn.com/free1/uploads/utc/original/1X/71bb7313e2aafd663b4e3ef7ede5911650dd83ae.png)

- Advanced example with multiple parts. In this example, the [comet](https://help.scilab.org/comet.html) function is used instead of [plot](https://help.scilab.org/plot.html) function to get an animated draw.

```auto
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](https://global.discourse-cdn.com/free1/uploads/utc/original/1X/60484d5b545c13ab9294b92de1f636200451ab67.png)

_Don’t hesitate to share your use cases and [report issues](https://gitlab.com/scilab/scilab/-/issues)._
