本文主要是介绍【5·20特辑】MatLAb之我在和你表白,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
520到了,准备好和心爱的他(她)来一场浪漫的科技表白嘛?
剑指“白”科技-----> MatLAb(矩阵实验室)
MATLAB是matrix&laboratory两个词的组合,意为矩阵工厂(矩阵实验室),软件主要面对科学计算、可视化以及交互式程序设计的高科技计算环境。它将数值分析、矩阵计算、科学数据可视化以及非线性动态系统的建模和仿真等诸多强大功能集成在一个易于使用的视窗环境中,为科学研究、工程设计以及必须进行有效数值计算的众多科学领域提供了一种全面的解决方案,并在很大程度上摆脱了传统非交互式程序设计语言(如C、Fortran)的编辑模式。
浪漫“花心”
------------我可不花心
clear; clc; close all;
% NOTICE: Your MATLAB version should be at least R2019a !% --------------------------- functions -------------------------------
f = @(x, y, z)(x.^2 + 2.25*y.^2 + z.^2 - 1).^3 - ...x.^2.* z.^3 - 0.1125*y.^2.*z.^3;
g = @(x, y, z)(sqrt(x.^2+y.^2)-2.5).^2 + z.^2 - 0.4^2;% -------------------------- generate data ----------------------------
t = linspace(-5, 5);[x1, y1, z1] = meshgrid(t);
[x2, y2, z2] = meshgrid(t);val1 = f(x1, y1, z1);
val2 = g(x2, y2, z2);[p1, v1] = isosurface(x1, y1, z1, val1, 0);
[p2, v2] = isosurface(x2, y2, z2, val2, 0);% --------------------------- basic plot ------------------------------
figure()
subplot(1, 1, 1)h = patch('faces',p1,'vertices',v1,'facevertexcdata',jet(size(v1,1)),...'facecolor','w','edgecolor','flat'); hold on;
patch('faces',p2,'vertices',v2,'facevertexcdata',jet(size(v2,1)),...'facecolor','w','edgecolor','flat');
grid on; axis equal; axis([-3,3,-3,3,-1.5,1.5]); view(3)
title(["$(x^2+\frac{9}{4}y^2+z^2-1)^3-x^2z^3-\frac{9}{80}y^2z^3=0$",..."$(\sqrt{x^2+y^2}-R)^2 +z^2 = r^2$"],'Interpreter','latex','position',[3.3,4])
warning('off');
% 请在此处进行您的演讲!% 请在此处进行您的演讲!
T = suptitle("$I\ Love\ U\ !$");
% 请在此处进行您的演讲!% 请在此处进行您的演讲!
set(T,'Interpreter','latex','FontSize',24)% -------------------------- generate gif -----------------------------
pic_num = 1;
for i = 1:20v1 = 0.98 * v1;set(h, 'vertices', v1); drawnow;F = getframe(gcf);I = frame2im(F);[I,map]=rgb2ind(I,256);if pic_num == 1imwrite(I,map,'BeatingHeart.gif','gif','Loopcount',inf,'DelayTime',0.05);elseimwrite(I,map,'BeatingHeart.gif','gif','WriteMode','append','DelayTime',0.05);endpic_num = pic_num + 1;
end
for i = 1:20v1 = v1 / 0.98;set(h, 'vertices', v1); drawnow;F = getframe(gcf);I = frame2im(F);[I,map] = rgb2ind(I,256);imwrite(I,map,'BeatingHeart.gif','gif','WriteMode','append','DelayTime',0.05);pic_num = pic_num + 1;
end% ----------------------------- dynamic -------------------------------
while truefor i = 1:20v1 = 0.98 * v1;set(h, 'vertices', v1); drawnow;endfor i = 1:20v1 = v1 / 0.98;set(h, 'vertices', v1); drawnow;end
end
效果展示:(动态效果哦~)
还有姐妹版
clc
f=@(x,y,z)(x.^2+ (9./4).*y.^2 + z.^2 - 1).^3 - x.^2.*z.^3 - (9./80).*y.^2.*z.^3;
[x,y,z]=meshgrid(linspace(-3,3));
val=f(x,y,z);
[p,v]=isosurface(x,y,z,val,0);
patch('faces',p,'vertices',v,'facevertexcdata',jet(size(v,1)),'facecolor','w','edgecolor','flat');
view(3);grid on;axis equal;
因为是妹妹,所以不会动~5555555
据说是失传的老代码
这篇关于【5·20特辑】MatLAb之我在和你表白的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!