您好,欢迎访问三七文档
当前位置:首页 > 商业/管理/HR > 管理学资料 > matlab绘制3D玫瑰花
首先,新建m文件,复制以下代码functiony=hb(x)[mn]=size(x);fori=1:mforj=1:nifrem(x(i,j),2*pi)=0&&rem(x(i,j),2*pi)0.5*piy(i,j)=sin(2*x(i,j)-0.5*pi)+1elseifrem(x(i,j),2*pi)=0.5*pi&&rem(x(i,j),2*pi)1.5*piy(i,j)=2elseifrem(x(i,j),2*pi)=1.5*pi&&rem(x(i,j),2*pi)2*piy(i,j)=-cos(2*x(i,j))+1endendendend保存后,将下列代码复制到command窗口中,按回车运行即可。t=0:0.01*pi:2*pifori=1:5r(i,:)=i-0.9:0.1:i+0.1;end%绘制花瓣fori=1:5a=r(i,:);b=t;[a,b]=meshgrid(a,b)z=(log(a)+5).*hb(5*b+pi*i).*abs(sin(pi*a))[x,y,z]=pol2cart(b,a,z)surf(x,y,z,(40+i)*ones(size(z)))holdonend%绘制花托[xx,yy]=meshgrid(-5:0.1:5);h=2*cos((xx.^2+yy.^2).^0.5)-0.64;surf(xx,yy,h,27*ones(size(h)));holdon%绘制补色xxx=[-0.10.1];yyy=xxx;[xxx,yyy]=meshgrid(xxx,yyy);c=zeros(size(xxx))fori=1:50surf(xxx,yyy,c,i*ones(size(c)))holdonendaxisequalset(gca,'xtick',[],'ytick',[],'ztick',[])
本文标题:matlab绘制3D玫瑰花
链接地址:https://www.777doc.com/doc-4757754 .html