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  

MATLAB作图之贝塞尔曲线(beizer)模板程序+效果图_第1张图片