Make the heart bounce in and out

匿名 (未验证) 提交于 2019-12-03 02:43:01

问题:

I was able to make a heart in matlab as:

n=100; x=linspace(-3,3,n); y=linspace(-3,3,n); z=linspace(-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); isosurface(F,0) lighting phong axis equal 

Would it be possible to make it bounce in and out? What approach might be taken?

回答1:

try this

step = 0.05; x = -1.5 : step : 1.5; y =   -1 : step : 1; z = -1.5 : step : 1.5;  [X,Y,Z] = meshgrid(x, y, z);  f = (X.^2 + 9/4 .* Y.^2 + Z.^2 - 1).^3 - X.^2 .* Z.^3 - 9/80 .* Y.^2 .* Z.^3;  isosurface(X,Y,Z,f,0)  axis tight axis equal colormap flag axis manual  ax = gca;  k=1.25; ax.XLim = ax.XLim*k; ax.YLim = ax.YLim*k; ax.ZLim = ax.ZLim*k;  tempLims.XLim = ax.XLim; tempLims.YLim = ax.YLim; tempLims.ZLim = ax.ZLim;  t=0;  heartData = sin((1:250)/100*2*pi)/6.*hamming(250)'; heartData(251:400) = 0;  while 1     t=t+1;     t=mod(t, length(heartData))+1;      k = 1 + heartData(t);      ax.XLim = tempLims.XLim * k;     ax.YLim = tempLims.YLim * k;     ax.ZLim = tempLims.XLim * k;     pause(0.01); end 


标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!