一、静态心形图绘制
(1)效果展示
(2)静态心形原始代码
clc;
clear all;
const=;
% 均布三位坐标
x=-:0.05:;
y=-:0.05:;
z=-:0.05:;
[x,y,z]=meshgrid(x,y,z); % 绘制三位坐标点
% 心形函数
f=(x.^ + (/)*y.^ + z.^ - ).^ - x.^.*z.^ - (/)*y.^.*z.^-const;
p=patch(isosurface(x,y,z,f,)); % 连接各点,组成封闭的图形
set(p, 'FaceColor', 'red', 'EdgeColor', 'none');
daspect([ ])
view()
camlight; lighting phong
二、动态心形图绘制
(1)效果展示
(2) 动态心形源代码
clc;
clear;
filename='heart';
% 三位坐标均布
[x,y,z]=meshgrid(linspace(-,));
% 心形函数
p=(x.^+(/)*y.^+z.^-).^-x.^.*z.^-(/)*y.^.*z.^;
[faces,verts,colors] = isosurface(x,y,z,p,,x);
% 循环绘制心形形成的过程
for i=:
figure(i)
pp=patch('Faces',faces(:+i*,:),'Vertices',verts);
set(pp,'FaceColor','red','EdgeColor','none');
view(-,)
axis off
axis equal
axis tight
camlight
lighting gouraud
pause(0.5)
f(i) = getframe(i);
imind = frame2im(f(i));
[imind,cm] = rgb2ind(imind,);
if i == imwrite(imind,cm,filename,'gif', 'Loopcount',inf,'DelayTime',0.5);
else
imwrite(imind,cm,filename,'gif','WriteMode','append','DelayTime',0.5);
end
close(i)
end