-
Notifications
You must be signed in to change notification settings - Fork 1
/
bezier.m
28 lines (21 loc) · 787 Bytes
/
bezier.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
function [C_u_1, C_u_2] = bezier(P, u)
%{
The following function allows to compute the Bézier's curve
of a point cloud given at the input applied to a point u.
Input data:
- P: cloud of points.
- u: real number in [0,1].
Output data:
- C_u_1: the first Bézier's curve coordinate at the point u.
- C_u_2: the second Bézier's curve coordinate at the point u.
Author: SABIR ILYASS - 2022.
%}
% The following function returns for an integer n
% the i-th Berstein polynomial applied to the point u
bernstein = @(n, i, u) factorial(n) * (u^i) * ((1-u)^(n-i)) / (factorial(i) * factorial(n - i));
n = size(P,2);
C_u_1 = 0; C_u_2 = 0;
for i = 0:n - 1
C_u_1 = C_u_1 + bernstein(n - 1,i,u) * P(1,i + 1);
C_u_2 = C_u_2 + bernstein(n - 1,i,u) * P(2,i + 1);
end