让心脏向上/向下/向左/向右移动[重复]

问题描述 投票:-3回答:2

这个问题在这里已有答案:

我能够在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

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

matlab matlab-figure
2个回答
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)

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,但翻译矩阵是一种通用的方法。

© www.soinside.com 2019 - 2024. All rights reserved.