开发者

How can you draw a bezier curve in Matlab

What's the Matlab way to draw a Bezier curve ? Do you have to prgoram it yourself ?

I am not looking for a user made rou开发者_运维百科tine, but am asking if Matlab offers a standard way to draw them.


With the Curve Fitting Toolbox, Matlab supports B-splines, which are a generalization of Bézier curves. A rational B-spline with no internal knots is a Bézier spline.

For example

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

would plot a Bézier curve with control points at (0,0),(1,0),(1,1),(0,1).


After looking and searching through the documentation, my answer is No: you'd have to go with one of the 3rd party implementations.

Likeliest candidate would be the interp family functions, and they implement no Bezier interpolation.


You can try this, http://www.cnblogs.com/begtostudy/articles/1787709.html


The following code 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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜