您好,欢迎访问三七文档
当前位置:首页 > 办公文档 > PPT模板库 > matlab绘制动态三维心形代码(蛋疼的情人节奉献)
Matlab绘制三维动态心形It’sOKtosendapictoyourgirlfriendonValentine'sDay情人节蛋疼玩意效果图:原始代码:%仅供参考,自助修改,原则上自己动手,要是非常强烈的要帮忙%可以联系我的QQ865802870,但愿我还在上面.Sourcecode:%构造体积方程和坐标轴,画出图形;linspace(a,b,c)均匀生成介于a到b的c个值,c的默认为100。Meshgrid生成矩阵网格。[X,Y,Z]=meshgrid(linspace(-3,3,101));%3D心型图方程如下;F=-X.^2.*Z.^3-(9/80).*Y.^2.*Z.^3+(X.^2+(9/4).*Y.^2+Z.^2-1).^3;hFigure=figure;sz=get(hFigure,'Position');set(hFigure,'Position',[sz(1)-0.15*sz(3)sz(2)1.3*sz(3)sz(4)]);set(hFigure,'color','w','menu','none')hAxes=axes('Parent',hFigure,'NextPlot','add',...'DataAspectRatio',[111],...'XLim',[30120],'YLim',[3565],'ZLim',[3075]);view([-3930]);axisoff%制作出动态的隐形效果;hiddenon%画出网格,制作网格动态效果;%快渲染心得背面:p=patch(isosurface(F,-0.001));set(p,'FaceColor','w','EdgeColor','w');%构造Y-Z平面,,描完函数在该平面的点:foriX=[3538414548515457616467]plane=reshape(F(:,iX,:),101,101);cData=contourc(plane,[00]);xData=iX.*ones(1,cData(2,1));plot3(hAxes,xData,cData(2,2:end),cData(1,2:end),'r');pause(.1),drawnowend%构造X-Z平面,描完函数在该平面的点:foriY=[41444751555861]plane=reshape(F(iY,:,:),101,101);cData=contourc(plane,[00]);yData=iY.*ones(1,cData(2,1));plot3(hAxes,cData(2,2:end),yData,cData(1,2:end),'r');pause(.1),drawnowend%构造X-Y平面,描完函数在该平面的点:foriZ=[363840424446485052545658606264666971]plane=F(:,:,iZ);cData=contourc(plane,[00]);startIndex=1;ifsize(cData,2)(cData(2,1)+1)startIndex=cData(2,1)+2;zData=iZ.*ones(1,cData(2,1));plot3(hAxes,cData(1,2:(startIndex-1)),...cData(2,2:(startIndex-1)),zData,'r');endzData=iZ.*ones(1,cData(2,startIndex));plot3(hAxes,cData(1,(startIndex+1):end),...cData(2,(startIndex+1):end),zData,'r');pause(.1),drawnowend%给三维心着色set(p,'FaceColor','r','EdgeColor','w');pause(.2);set(p,'FaceColor','w','EdgeColor','r');%函数已经画完,接下来为文字部分;pause(.2)%设置字体大小,粗细,位置等,以下是打出I(心型图)Wendy;text(7,50,70,'I','fontWeight','bold','FontAngle','italic','FontName','TrebuchetMS','fontsize',60,'Color','r')pause(.5)text(80,50,43,'Math','fontWeight','bold','FontAngle','italic','FontName','TrebuchetMS','fontsize',60,'Color','r')pause(.2)line([2080],[5050],[52.552.5],'color','r')line([5050],[2080],[52.552.5],'color','r')line([5050],[5050],[3080],'color','r')%制作者签名;text(40,60,30,'MadeByWilliam8/8/2012','fontsize',8)text(35,45,30,'','fontsize',8)%制作心的动态效果%fori=1:28%set(p,'FaceColor','r','EdgeColor','w');%pause(.1);%set(p,'FaceColor','r','EdgeColor','r');%pause(.2)%end%referto://stackoverflow.com/questions/1526898/how-do-i-reproduce-this-heart-shaped-mesh-in-matlab%笛卡尔;x=0:0.01:2*pi;y=1-cos(x);polar(x,y)复制代码%简单心;figure(2)ezplot(vectorize('17*x^2-16*abs(x)*y+17*y^2-225'));复制代码%完美心;figure(1)N=200;f1=@(x,y,z)(x.^2+(9/4)*y.^2+z.^2-1).^3-x.^2.*z.^3-(11/80)*y.^2.*z.^3;[X,Y,Z]=meshgrid(linspace(-1.5,1.5,N));set(patch(isosurface(X,Y,Z,f1(X,Y,Z),0)),'facecolor','r','edgecolor','none');lightview(-10,24)复制代码%心痕;[x,y,z]=meshgrid(linspace(-1.3,1.3));val=(x.^2+(9/4)*y.^2+z.^2-1).^3-x.^2.*z.^3-(1/9)*y.^2.*z.^3;%画出等值面isosurface(x,y,z,val,0);%View视角colormap色图0-1axisequal;view(-10,10);colormap([10.20.2])复制代码%花心;clear;clc;closeallc=5;t=linspace(-c,c);[x,y]=meshgrid(t);z=17*x.^2-16*abs(x).*y+17*y.^2-225;pcolor(x,y,z);shadinginterppause(2);spinmap(10)复制代码%构造体积方程和坐标轴,画出图形;[X,Y,Z]=meshgrid(linspace(-3,3,101));%3D心型图方程如下;F=-X.^2.*Z.^3-(9/80).*Y.^2.*Z.^3+(X.^2+(9/4).*Y.^2+Z.^2-1).^3;hFigure=figure;sz=get(hFigure,'Position');set(hFigure,'Position',[sz(1)-0.15*sz(3)sz(2)1.3*sz(3)sz(4)]);set(hFigure,'color','w','menu','none')hAxes=axes('Parent',hFigure,'NextPlot','add',...'DataAspectRatio',[111],...'XLim',[30120],'YLim',[3565],'ZLim',[3075]);view([-3930]);axisoff%制作出动态的隐形效果;hiddenon%画出网格,制作网格动态效果;%快渲染心得背面:p=patch(isosurface(F,-0.001));set(p,'FaceColor','w','EdgeColor','w');%构造Y-Z平面,,描完函数在该平面的点:foriX=[3538414548515457616467]plane=reshape(F(:,iX,:),101,101);cData=contourc(plane,[00]);xData=iX.*ones(1,cData(2,1));plot3(hAxes,xData,cData(2,2:end),cData(1,2:end),'k');pause(.1),drawnowend%构造X-Z平面,描完函数在该平面的点:foriY=[41444751555861]plane=reshape(F(iY,:,:),101,101);cData=contourc(plane,[00]);yData=iY.*ones(1,cData(2,1));plot3(hAxes,cData(2,2:end),yData,cData(1,2:end),'k');pause(.1),drawnowend%构造X-Y平面,描完函数在该平面的点:foriZ=[363840424446485052545658606264666971]plane=F(:,:,iZ);cData=contourc(plane,[00]);startIndex=1;ifsize(cData,2)(cData(2,1)+1)startIndex=cData(2,1)+2;zData=iZ.*ones(1,cData(2,1));plot3(hAxes,cData(1,2:(startIndex-1)),...cData(2,2:(startIndex-1)),zData,'k');endzData=iZ.*ones(1,cData(2,startIndex));plot3(hAxes,cData(1,(startIndex+1):end),...cData(2,(startIndex+1):end),zData,'k');pause(.1),drawnowend
本文标题:matlab绘制动态三维心形代码(蛋疼的情人节奉献)
链接地址:https://www.777doc.com/doc-5737261 .html