function anxindaima_3d2% 所需匿名函数col1Func(n) repmat([255,158,196]./255,[n,1])repmat([-39,-81,-56]./255,[n,1]).*repmat(rand([n,1]),[1,3]);col2Func(n) repmat([118,156,216]./255,[n,1])repmat([137,99,39].*.1./255,[n,1]).*repmat(rand([n,1]),[1,3]);aFunc(n) eval(char([100,105,115,112,40,39,20316,32773,58,108,117,104,97,111,39,41]));szFunc(n) rand([n,1]).*158;hold on% 计算爱心点位置并绘制爱心n120;xlinspace(-3,3,n);ylinspace(-3,3,n);zlinspace(-3,3,n);[X,Y,Z]ndgrid(x,y,z);F((-(X.^2).*(Z.^3)-(9/80).*(Y.^2).*(Z.^3))((X.^2)(9/4).*(Y.^2)(Z.^2)-1).^3);FVisosurface(F,0);hpntsFV.vertices;hpnts(hpnts-repmat(mean(hpnts),[size(hpnts,1),1])).*repmat([.75,.7,.7],[size(hpnts,1),1]);hpntshpntsrand(size(hpnts)).*.7;heartHdlscatter3(hpnts(:,1),hpnts(:,2),hpnts(:,3),.,SizeData,5,CData,col1Func(size(hpnts,1)));% 计算星星位置并绘制星星sx1rand([2e3,1]).*120-60;sy1rand([2e3,1]).*120-60;sz1ones(size(sx1)).*-30;star1Hdlscatter3(sx1,sy1,sz1,.,SizeData,szFunc(length(sx1)),CData,col2Func(size(sx1,1)),LineWidth,1);sx2rand([2e3,1]).*120-60;sy2rand([2e3,1]).*120-60;sz2rand([2e3,1]).*120-20;star2Hdlscatter3(sx2,sy2,sz2,.,SizeData,szFunc(length(sx2)),CData,[1,1,1]);% 坐标区域修饰axgca;ax.XLim[-30,30];ax.YLim[-30,30];ax.ZLim[-40,30];ax.Projectionperspective;% ax.DataAspectRatio[1,1,1];view(-42,14);aFunc(1);ax.Color[0,0,0];ax.XColornone;ax.YColornone;ax.ZColornone;set(ax,LooseInset,[0,0,0,0]);set(ax,Position,[-1/5,-1/5,12/5,12/5])set(gcf,Color,[0,0,0]);% 显示作者名已修改text(0,0,20,luhao,Color,w,HorizontalAlignment,center) % 取消注释并替换作者名% 旋转爱心和星星theta10;theta20;theta30;while 1theta1theta1-0.01;theta2theta2-0.003;theta3theta3-0.02;set(heartHdl,XData,hpnts(:,1).*cos(theta1)-hpnts(:,2).*sin(theta1),...YData,hpnts(:,1).*sin(theta1)hpnts(:,2).*cos(theta1))set(star1Hdl,XData,sx1.*cos(theta2)-sy1.*sin(theta2),...YData,sx1.*sin(theta2)sy1.*cos(theta2))set(star2Hdl,XData,sx2.*cos(theta3)-sy2.*sin(theta3),...YData,sx2.*sin(theta3)sy2.*cos(theta3))pause(0.05)endend
MATLAB旋转爱心代码
function anxindaima_3d2% 所需匿名函数col1Func(n) repmat([255,158,196]./255,[n,1])repmat([-39,-81,-56]./255,[n,1]).*repmat(rand([n,1]),[1,3]);col2Func(n) repmat([118,156,216]./255,[n,1])repmat([137,99,39].*.1./255,[n,1]).*repmat(rand([n,1]),[1,3]);aFunc(n) eval(char([100,105,115,112,40,39,20316,32773,58,108,117,104,97,111,39,41]));szFunc(n) rand([n,1]).*158;hold on% 计算爱心点位置并绘制爱心n120;xlinspace(-3,3,n);ylinspace(-3,3,n);zlinspace(-3,3,n);[X,Y,Z]ndgrid(x,y,z);F((-(X.^2).*(Z.^3)-(9/80).*(Y.^2).*(Z.^3))((X.^2)(9/4).*(Y.^2)(Z.^2)-1).^3);FVisosurface(F,0);hpntsFV.vertices;hpnts(hpnts-repmat(mean(hpnts),[size(hpnts,1),1])).*repmat([.75,.7,.7],[size(hpnts,1),1]);hpntshpntsrand(size(hpnts)).*.7;heartHdlscatter3(hpnts(:,1),hpnts(:,2),hpnts(:,3),.,SizeData,5,CData,col1Func(size(hpnts,1)));% 计算星星位置并绘制星星sx1rand([2e3,1]).*120-60;sy1rand([2e3,1]).*120-60;sz1ones(size(sx1)).*-30;star1Hdlscatter3(sx1,sy1,sz1,.,SizeData,szFunc(length(sx1)),CData,col2Func(size(sx1,1)),LineWidth,1);sx2rand([2e3,1]).*120-60;sy2rand([2e3,1]).*120-60;sz2rand([2e3,1]).*120-20;star2Hdlscatter3(sx2,sy2,sz2,.,SizeData,szFunc(length(sx2)),CData,[1,1,1]);% 坐标区域修饰axgca;ax.XLim[-30,30];ax.YLim[-30,30];ax.ZLim[-40,30];ax.Projectionperspective;% ax.DataAspectRatio[1,1,1];view(-42,14);aFunc(1);ax.Color[0,0,0];ax.XColornone;ax.YColornone;ax.ZColornone;set(ax,LooseInset,[0,0,0,0]);set(ax,Position,[-1/5,-1/5,12/5,12/5])set(gcf,Color,[0,0,0]);% 显示作者名已修改text(0,0,20,luhao,Color,w,HorizontalAlignment,center) % 取消注释并替换作者名% 旋转爱心和星星theta10;theta20;theta30;while 1theta1theta1-0.01;theta2theta2-0.003;theta3theta3-0.02;set(heartHdl,XData,hpnts(:,1).*cos(theta1)-hpnts(:,2).*sin(theta1),...YData,hpnts(:,1).*sin(theta1)hpnts(:,2).*cos(theta1))set(star1Hdl,XData,sx1.*cos(theta2)-sy1.*sin(theta2),...YData,sx1.*sin(theta2)sy1.*cos(theta2))set(star2Hdl,XData,sx2.*cos(theta3)-sy2.*sin(theta3),...YData,sx2.*sin(theta3)sy2.*cos(theta3))pause(0.05)endend