让心动起来up/down/left/right

Make the heart move up/down/left/right

我能够在 matlab 中制作一颗心:

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

假设我想在显示图形后将其向上移动片刻(即 1 秒)。我的意思是,第一步是展示心脏,第二步是移动它,即向上(或 down/left/right)。可以采取什么方法?

一种方法是使用 translation matrix。基本上,这允许您使用矩阵乘法任意旋转和平移(即 "move")您的图像。我现在无法访问 matlab,所以我无法对此进行测试,但这里是要点:

d2r = pi/180;
mat = @(angle_th, x_move, y_move)[cos(angle_th*d2r), -sin(angle_th*d2r), x_move; sin(angle_th*d2r), cos(angle_th*d2r), y_move; 0, 0, 1];
% now set up the multiply; this will move x and y by 1:
XY = mat(0, 1, 1)*[x; y; ones(size(x))];
x_moved = XY(1, :);
y_moved = XY(2, :);
% now create your heart or whatever other image using x_moved and y_moved

现在显然您可以将 x、X、y 或 Y 值加 1,但平移矩阵是一种通用方法。

您可以在 1 秒后使用新坐标重新绘制等值面

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);

[XX, YY, ZZ] = meshgrid(x,y,z);
isosurface(XX,YY,ZZ,F,0);

lighting phong
axis equal
axis manual
ax = gca;
k = 2;

ax.XLim = ax.XLim*k;
ax.YLim = ax.YLim*k;
ax.ZLim = ax.ZLim*k;

pause(1);

TranslationVector = [0.5 0.5 0.5];

h = findobj('Parent',ax,'type','patch');
delete(h);
isosurface(XX+TranslationVector(1),YY+TranslationVector(2),ZZ+TranslationVector(3),F,0)