[Reprint]matlab Dynamic drawing three-dimensional heart shape diagram
Matlab Dynamic drawing three-dimensional heart chart program as follows, the core is the Isosurface function, Verts stores the coordinates of the heart surface points, and faces stores the connection order of each point.
Clear
filename= ' heart ';
[X,y,z]=meshgrid (Linspace ( -3,3));
P= (x.^2+ (9/4) *y.^2+z.^2-1). ^3-x.^2.*z.^3-(9/80) *y.^2.*z.^3;
[Faces,verts,colors] = Isosurface (x,y,z,p,0,x);
For I=1:9
figure (i)
pp=patch (' Faces ', Faces (1:284+i*1000,:), ' vertices ', Verts);
Set (PP, ' facecolor ', ' Red ', ' edgecolor ', ' none ');
View ( -30,24)
axis off
axis equal
axis tight
camlight
lighting Gouraud
Pause (0.5)
f (i) = GetFrame (i);
Imind = Frame2im (f (i));
[IMIND,CM] = Rgb2ind (imind,256);
if i = = 1
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
End