1. Open the MATLAB software, as shown in the figure:
2. Create a new script and copy the following program into the script . As shown in the picture:
clc,clear; figure('Color','y') while 1 for i=-5:0.2:5 f=@(xx,yy,zz) xx.^2.*zz.^3+9*yy.^2.*zz.^3/80-(xx.^2+9*yy.^2/4+zz.^2-1).^3;%心形曲面函数 [xx,yy,zz]=meshgrid(-1.5:0.1:1.5);%画图范围 vv=f(xx,yy,zz); h=patch(isosurface(xx,yy,zz,vv,0)); isonormals(xx,yy,zz,vv,h) set(h,'FaceColor','r','EdgeColor','none'); lighting gouraud view(40*i,20) drawnow axis equal off grid off pause(0.01) end end
3. Click Run to get a three-dimensional dynamic "heartbeat" that you can't imagine. It can be moved. Try it yourself. Programming can exercise your logical thinking ability and Spatial imagination ability, so I hope everyone can learn more knowledge through this small program, as shown in the picture:
The above is the detailed content of Use matlab to draw a beating heart. For more information, please follow other related articles on the PHP Chinese website!