让心脏向上/向下/向左/向右移动

时间:2017-12-20 04:46:34

标签: matlab matlab-figure

我能够在matlab中创造一个心脏:

Object.assign = function() {
   // check in arguments if property class
   throw "Error";
}

让我们说在展示这个数字之后我想把它提升一会儿(即1s)。我的意思是,第一步是显示心脏,第二步是移动它,即。向上(或向下/向左/向右)。可以采取什么方法?

2 个答案:

答案 0 :(得分:0)

一种方法是使用translation matrix。基本上,这允许您使用矩阵乘法任意旋转和平移(即“移动”)您的图像。我现在无法访问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 :(得分:0)

你可以在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)