function bytqx
u=[3 3 3 3 4 5 6 7 8 9 9 9 9];%等距节点
n=100;m=length(u);k=4;%阶数=次数+1
[bx by]=ginput(m-k);
[yT,duanshu]=bsplinej(u,k,n);
D=[bx by]'*yT;
plot(bx,by,'-ob','LineWidth',2);
hold on;
axis equal;
axis tight;
for i=1:duanshu
plot(D(1,1+n*(i-1):n*i),D(2,1+n*(i-1):n*i),'r','LineWidth',2);
end
hold off;
function [y,duanshu]=bsplinej(u,k,n)
%u为节点;k为阶数或次数+1;%n为小段曲线取点数
m=length(u);
N=zeros(k,n*(m-1),m-1);
D=zeros(2,n*(m-1-2*(k-1)));
tu=zeros(1,n*(m-1));
qjied=zeros(1,m-2*k+2);
sjied=zeros(1,m-2*k+2);
for i=k:1:m-k+1
qjied(i-k+1)=max(find(u(k:m-k+1)==u(i)));
end
ci=1;jishuq=1;
while ci<=m-2*k+2 & jishuq<=m-2*k+2
jishuq=max(find(qjied==qjied(jishuq)));
sjied(ci)=qjied(jishuq);
ci=ci+1;jishuq=jishuq+1;
end
duanshu=length(find(sjied~=0))-1;
sjied=k-1+sjied;
for i=1:1:m-1;
tu((i-1)*n+1:i*n)=linspace(u(i),u(i+1),n);
end
for i=1:1:m-1
N(1,(i-1)*n+1:i*n,i)=1;
end
for j=2:1:k
for i=1:1:m-j
t=tu((i-1)*n+1:(i-1+j)*n);
delt1=u(i+j-1)-u(i);
delt2=u(i+j)-u(i+1);
feizi1=(t-u(i)).*N(j-1,(i-1)*n+1:(i-1+j)*n,i);
feizi2=(u(i+j)-t).*N(j-1,(i-1)*n+1:(i-1+j)*n,i+1);
if delt1==0 & delt2==0
N(j,(i-1)*n+1:(i-1+j)*n,i)=0;
end
if delt1==0 & delt2~=0
N(j,(i-1)*n+1:(i-1+j)*n,i)=feizi2/delt2;
end
if delt2==0 & delt1~=0
N(j,(i-1)*n+1:(i-1+j)*n,i)=feizi1/delt1;
end
if delt1~=0 & delt2~=0
N(j,(i-1)*n+1:(i-1+j)*n,i)=feizi1/delt1+feizi2/delt2;
end
end
end
y=zeros(m-k,n*duanshu);
for i=1:1:m-k
for j=1:1:duanshu
y(i,(j-1)*n+1:j*n)=N(k,n*(sjied(j)-1)+1:n*(sjied(j)),i);
end
end
这个程序改一些点(只改点和阶数即可),画出一朵花的图形,把蓝线隐去,只留红线
function bsplinequm33
clear;
v=[0 0 0 0 1 2 2 2 2];
u=[0 0 0 0 1 2 2 2 2];
ku=3;kv=3;
Mu=30;Mv=30;
x=[1 2 3 4 5];y=[3 1 3 5 3];
n=length(x);
m=length(y);
[x y]=meshgrid(x,y);
z=[1 2 3 2 1;
1 2 3 2 1;
2 3 3 3 2;
1 2 3 2 1;
1 2 3 2 1 ];
Tu=bsplinej(u,ku+1,Mu);
Tv=bsplinej(v,kv+1,Mv);
xst=zeros(Mu,Mv);yst=zeros(Mu,Mv);zst=zeros(Mu,Mv);
xst=Tu'*x*Tv;
yst=Tu'*y*Tv;
zst=Tu'*z*Tv;
axis equal;
axis([0 6 0 6 1 3]);
for i=1:m
plot3(x(i,:),y(i,:),z(i,:),'-or','LineWidth',2);
hold on;
end
for i=1:n
plot3(x(:,i),y(:,i),z(:,i),'-ob','LineWidth',2);
end
grid on
mesh(xst,yst,zst);
axis([0 6 0 6 1 4]);
xlabel('X-axis');ylabel('Y-axis');zlabel('Z-axis');
hold off;
view([-30 30]);
function [y,duanshu]=bsplinej(u,k,n)
%u为节点;k为阶数或次数+1;%n为小段曲线取点数
m=length(u);
N=zeros(k,n*(m-1),m-1);
D=zeros(2,n*(m-1-2*(k-1)));
tu=zeros(1,n*(m-1));
qjied=zeros(1,m-2*k+2);
sjied=zeros(1,m-2*k+2);
for i=k:1:m-k+1
qjied(i-k+1)=max(find(u(k:m-k+1)==u(i)));
end
ci=1;jishuq=1;
while ci<=m-2*k+2 & jishuq<=m-2*k+2
jishuq=max(find(qjied==qjied(jishuq)));
sjied(ci)=qjied(jishuq);
ci=ci+1;jishuq=jishuq+1;
end
duanshu=length(find(sjied~=0))-1;
sjied=k-1+sjied;
for i=1:1:m-1;
tu((i-1)*n+1:i*n)=linspace(u(i),u(i+1),n);
end
for i=1:1:m-1
N(1,(i-1)*n+1:i*n,i)=1;
end
for j=2:1:k
for i=1:1:m-j
t=tu((i-1)*n+1:(i-1+j)*n);
delt1=u(i+j-1)-u(i);
delt2=u(i+j)-u(i+1);
feizi1=(t-u(i)).*N(j-1,(i-1)*n+1:(i-1+j)*n,i);
feizi2=(u(i+j)-t).*N(j-1,(i-1)*n+1:(i-1+j)*n,i+1);
if delt1==0 & delt2==0
N(j,(i-1)*n+1:(i-1+j)*n,i)=0;
end
if delt1==0 & delt2~=0
N(j,(i-1)*n+1:(i-1+j)*n,i)=feizi2/delt2;
end
if delt2==0 & delt1~=0
N(j,(i-1)*n+1:(i-1+j)*n,i)=feizi1/delt1;
end
if delt1~=0 & delt2~=0
N(j,(i-1)*n+1:(i-1+j)*n,i)=feizi1/delt1+feizi2/delt2;
end
end
end
y=zeros(m-k,n*duanshu);
for i=1:1:m-k
for j=1:1:duanshu
y(i,(j-1)*n+1:j*n)=N(k,n*(sjied(j)-1)+1:n*(sjied(j)),i);
end
end
这个程序也是只增加修改一些点,画出一个比较复杂且美观的图案
急用,谢谢