文档库 最新最全的文档下载
当前位置:文档库 › 用matlab画3D心(surf,mesh)

用matlab画3D心(surf,mesh)

用matlab画3D心(surf,mesh)
用matlab画3D心(surf,mesh)

% 1.核心程序%

%designed by CONST from BUAA%

% 可根据电脑性能更改参数

th=linspace(-pi,pi,100);

ph=linspace(0,2*pi,100);

r=linspace(0,1.5,1000);

[t,p]=meshgrid(th,ph);

f=zeros(1,1000);

sf=zeros(100,100);

for i=1:100

for j=1:100

x=sin(ph(i))*cos(th(j));

y=cos(ph(i))*cos(th(j));

z=sin(th(j));

f=((x*r).^2 + (9/4)*(y*r).^2 + (z*r).^2 - 1).^3 - (x*r).^2.*(z*r).^3 - (9/80)*(y*r).^2.*(z*r).^3; [minf,ind]=min(abs(f));

sf(i,j)=r(ind);

end

end

[x,y,z]=sph2cart(p,t,sf);

% 2.mesh红心%

mesh(x,y,z)

axis equal

Colormap([1,0,0])

% 3.surf红心%

surf(x,y,z)

axis equal

shading interp

camlight right

%精细程度与起始参数设定有关%

% 4.彩色多个心%

x2=x+1.5;

y2=y+2;

z2=z+0.5;

x3=x+2;

y3=y-2;

z3=z+0.2;

mesh(x,y,z,ones(size(z))); hold on; mesh(x2,y2,z2,10*ones(size(z))); hold on; mesh(x3,y3,z3,25*ones(size(z)))

colormap hsv

axis equal

%绘制补色

[px,py]=meshgrid([0,10e-6],[0,10e-6]);

c=zeros(2,2);

for i=1:50

surf(px,py,c,i*ones(2,2));

hold on

end

% surf版%

surf(x,y,z,ones(size(z))); hold on; surf(x2,y2,z2,10*ones(size(z))); hold on; surf(x3,y3,z3,25*ones(size(z)))

colormap hsv

axis equal

%绘制补色

[px,py]=meshgrid([0,10e-6],[0,10e-6]);

c=zeros(2,2);

for i=1:50

surf(px,py,c,i*ones(2,2));

hold on

end

shading interp

camlight right

相关文档