How can you draw a bezier curve in matlab

What is the way Matlab draws a Bezier curve? Do you have to burn it yourself?

I'm not looking for a custom routine, but I ask if Matlab offers a standard way to draw them.

+3
source share
4 answers

After searching and searching the documentation, my answer is No: you need to go with one of the third-party implementations.

The best candidate will be interpfamily functions, and they do not implement Bezier interpolation.

+1
source

Using the Curve Fitting Toolbox, Matlab supports B-splines, which are a generalization of Bezier curves. A rational B-spline without internal nodes is a Bezier spline.

for example

p = spmak([0 0 0 1 1 1],[1 0;0 1]);
fnplt(p)

(0,0), (1,0), (1,1), (0,1).

+3

The following code is based on this link .

function B = bazier( t, P )
    %Bazier curve
    % Parameters
    % ----------
    % - t: double
    %   Time between 0 and 1
    % - C: 2-by-n double matrix
    %   Control points
    %
    % Returns
    % -------
    % - B: 2-by-1 vector
    %   Output point

    B = [0, 0]';

    n = size(P, 2);
    for i = 1:n
        B = B + b(t, i - 1, n - 1) * P(:, i);
    end
end

function value = b(t, i, n)
    value = nchoosek(n, i) * t^i * (1 - t)^(n - i);
end
0
source

Source: https://habr.com/ru/post/1733649/


All Articles