Heart-shaped drawing MATLAB

A static mapping Heart

(1) results show

 

(2) static source code Heart

. 1  CLC;
 2  Clear All;
 . 3  const = 0 ;  
 . 4 % uniform three coordinates
 . 5 X = - . 5 : 0.05 : . 5 ;
 . 6 Y = - . 5 : 0.05 : . 5 ;
 . 7 Z = - . 5 : 0.05 : . 5 ;
 . 8 [x, y, z] = meshgrid (x, y, z);% plotted three coordinate points
 . 9 % heart function
 10 F = (X ^. 2 + ( . 9 / . 4 ) * Y ^. 2 + Z. ^ 2- . 1 ) ^. . 3 - X ^. 2 * Z ^.. . 3 - ( . 9 / 80 ) * Y ^. 2 * Z ^.. . 3 - const ;
 . 11 P = Patch (the isosurface (X, Y, Z, F, 0 ));% points are connected to form a closed pattern
 12 is  SET (P, ' FaceColor ' , ' Red ' , ' EdgeColor ' , ' none ' );
 13 is daspect ([ . 1  . 1  . 1 ])
 14 View ( . 3)
15 camlight; lighting phong

 

 

 

Two , heart-shaped dynamic mapping

(1) results show

 

 (2) the dynamic heart-shaped source

. 1  CLC;
 2  Clear;
 . 3 filename = ' Heart ' ;
 . 4 % three coordinate uniform
 . 5 [X, Y, Z] = meshgrid now (linspace (- . 3 , . 3 )); 
 . 6 % Heart function
 . 7 P = (X . ^ 2 + ( . 9 / . 4 ) * Y ^. 2 + Z ^. 2 - . 1 ) ^. . 3 the -X-^. 2 * Z ^.. . 3 - ( . 9 / 80 ) * Y ^. 2 * Z. . ^ 3 ; 
 8[Faces, Verts, Colors] = the isosurface (X, Y, Z, P, 0 , X);
 . 9 % during cycle drawn heart-shaped formation
 10  for I = . 1 : . 9 
. 11  Figure (I)
 12 is PP = Patch ( ' Faces ' , Faces ( . 1 : 284 + I * 1000 , :), ' Vertices ' , Verts);
 13 is  SET (PP, ' FaceColor ' , ' Red ' , ' EdgeColor ' , ' none ' );
 14 view(-30,24)
15 axis off
16 axis equal
17 axis tight
18 camlight
19 lighting gouraud
20 pause(0.5)
21 f(i) = getframe(i);
22 imind = frame2im(f(i));
23 [imind,cm] = rgb2ind(imind,256);
24 if i == 1
25     
26         imwrite(imind,cm,filename,'gif', 'Loopcount',inf,'DelayTime',0.5);
27 else
28         imwrite(imind,cm,filename,'gif','WriteMode','append','DelayTime',0.5);
29 end
30 close(i)
31 end

 

Guess you like

Origin www.cnblogs.com/smqh-bokeyuan/p/11366734.html