本文分享一段矩阵形式的bezier代码:
clc
clear% 控制点
P = [25;10;5;13]; %% 获得M矩阵
n = length(P) - 1;
M = zeros(n+1,n+1);
for i = 1:n+1for j = 1:n+1if(i+j<n+3)M(i,j) = (-1)^(n -i-j+2)*nchoosek(n,n-i+1)*nchoosek(n-i+1,j-1);elseM(i,j) = 0;endend
end
t_temp = linspace(0,1,100)';% 生成T矩阵
T = ones(length(t_temp),n + 1);
for i = 1:nT(:,i) = t_temp.^(n-i+1);
end% 计算获得bezier曲线离散点
r = T*M*P;figure(1)
plot(r)
hold on
plot([1,25,50,100],P,'*')
主要是要获得: