% Quelle: https://pomax.github.io/bezierinfo/

P = [
    0,  0;
    -1, 3;
    2, 2;
    1, 1
];

N = 50;
curve = zeros(N, 2);

% Konstruktion von de Casteljau
ind = 1;
for t = linspace(0, 1, N)
    points = P;
    while size(points, 1) > 1
        starts = points(1:end-1,:);
        ends = points(2:end,:);
        points = t*starts + (1-t)*ends;
    end
    curve(ind, :) = points;
    ind = ind + 1;
end

hold on
plot(P(:,1), P(:, 2), 'xr')  % Plot der Kontrollpunkte
plot(curve(:,1), curve(:, 2))
axis equal

xlabel("x"); ylabel("y")
title(["Bézier curve with ", num2str(size(P, 1)), " control points"])