MATLAB作图之贝塞尔曲线(beizer)模板程序+效果图

对于贝塞尔曲线不了解的同学可以点开此链接:http://www.html-js.com/article/1628

声明: 程序中的数据可以根据实际情况进行修改

function bezier( vertices )  
%BEZIER 绘制Bezier曲线  
 vertices=[00.1 6.54;
4.76    5.19;
6.65    4.53;
9.51    4.99;
12.17   2.21;
15.23   6.81;
17.35   6.1;
19.21   8.89;
22.15   4.88;
23.46   3.72;
27.11   3.21;
28.81   2.78;
29.87   3.58;
30.52   2.28;
30.99   2.11;
32.01   2.47;
33.85   2.26;
34.91   1.55;
37.5    6;
35.71   9.54;
33.78   8.68;
32.89   10.96;
31.51   12.86;
30.87   14.86;
29.87   17.98;
29.11   21.62;
27.31   17.98;
24.56   18.86;
22.23   14.56;
19.5    19.68;
17.92   30;
15.21   41.38;
12.18   37.67;
8.83    40.54;
5.98    34.82;
4.8 24.52;
1.7 19.89
]';

Dim=size(vertices,1);%二位或者三维空间  
NumPoint=size(vertices,2)-1;%点的个数  
t=0:0.001:1;  
x=[]; y=[]; z=[];

if Dim==2  
     x=(1-t).^(NumPoint)*vertices(1,1);  
     y=(1-t).^(NumPoint)*vertices(2,1);  
  for j=1:NumPoint  
      w=factorial(NumPoint)/(factorial(j)*factorial(NumPoint-j))*(1-t).^(NumPoint-j).*t.^(j);  
      x=x+w*vertices(1,j+1);y=y+w*vertices(2,j+1);  
  end  
plot(vertices(1,:),vertices(2,:),'b');  
hold on;grid on;  
axis tight;    
xlabel('X');ylabel('Y');  
plot(x,y,'r');  
end  

if Dim==3  
    x=(1-t).^(NumPoint)*vertices(1,1);  
    y=(1-t).^(NumPoint)*vertices(2,1);  
    z=(1-t).^(NumPoint)*vertices(3,1);  
 for j=1:NumPoint  
     w=factorial(NumPoint)/(factorial(j)*factorial(NumPoint-j))*(1-t).^(NumPoint-j).*t.^(j);  
     x=x+w*vertices(1,j+1);y=y+w*vertices(2,j+1);z=z+w*vertices(3,j+1);  
 end  
plot3(vertices(1,:),vertices(2,:),vertices(3,:),'b');  
hold on;grid on;  
axis tight;    
%axis([0.5,1.5,0.5,1.5,0,0.7]);  
xlabel('X');ylabel('Y');zlabel('Z');  
plot3(x,y,z,'r');  
view(3);  
end  

end  

这里写图片描述

  • 2
    点赞
  • 39
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值