-3

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

Let's say I would like to move it up just a moment (i.e. 1s) after showing the figure. I mean, 1st step is to show the heart and 2nd step is to move it ,i.e. up (or down/left/right). What approach could be taken?

KcFnMi
  • 5,516
  • 10
  • 62
  • 136

2 Answers2

1

you can redraw your isosurface with new coordinates after 1 second

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)
Artyom Emelyanenko
  • 1,323
  • 1
  • 11
  • 16
0

One way would be to use a translation matrix. Basically this allows you to arbitrarily rotate and translate (i.e. "move") your image using a matrix multiply. I don't have access to matlab right now, so I can't test this, but here is the gist:

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

Now obviously you could just add 1 to your x, X, y or Y values, but the translation matrix is a general approach.

sean
  • 61
  • 7