Bezier曲线【zz】
- % Faculty of Engineering, University of Fukui. 2004/07/07
- % coded by Sokthai Chan (sokthai@wireless.fuis.fukui-u.ac.jp)
- % Bezier Curve乮Infinite Sign乯
- % clear all the variable from memory
- clear all;
- % Data Setting
- t=[-0.8 -0.6 -1/4 1/2 1 3/2 1 1/2 -1/4 -0.6 -0.8];
- p=[0 0.9 0.9 -3/2 -3/2 0 3/2 3/2 -0.9 -0.9 0];
- n=11;
- a=-1;
- b=1;
- x=-1:0.01:1;
- m=length(x);
- % Matrix Setting
- Pn=zeros(1,m);
- Pv=zeros(1,m);
- Tv=zeros(1,m);
- Ts=((1:n)-1)*(b-a)/(n-1)+a; % Equally Divided Point
- % Calculation Bezier Curve
- for j=1:m
- for i=1:n
- B(i)=(nchoosek(n-1,i-1)*realpow(b-x(j),n-i)*realpow(x(j)-a,i-1))/realpow(b-a,n-1); % Base Function of Bernstein
- Pn(j)=Pn(j)+p(i)*B(i); % Scalar Bezier Curve
- Tv(j)=Tv(j)+t(i)*B(i); % Equally Divided Point
- Pv(j)=Pv(j)+p(i)*B(i); % Vector Bezier Curve
- end
- end
- % Plot Graphic
- figure(1)
- plot(x,Pn,'*',Ts,p,'-');
- legend('Scalar Bezier Curve','Bezier Control Polygon');
- xlabel('x'); ylabel('Pn(x)');
- title(['Bezier Curve']);
- figure(2)
- plot(Tv,Pv,'*',t,p,'-');
- legend('Vector Bezier Curve','Bezier Control Polygon');
- xlabel('x'); ylabel('Pn(x)');
- title(['Bezier Curve']);
复制代码
[ 本帖最后由 suffer 于 2007-6-3 12:06 编辑 ] |