how to animate 2 surfaces in Matlab?

Posted by Kate on Stack Overflow See other posts from Stack Overflow or by Kate
Published on 2010-05-03T21:23:40Z Indexed on 2010/05/03 21:28 UTC
Read the original article Hit count: 227

Filed under:
|
|

Hi everyone, I've written this code which makes an animation of 2 ellipsoids.

Parameter k1 of these ellipsoids must depend on time (so they'd move asynchronously), but I need to animate them in one figure. Can I use loop for it or is it better to use timer & some kind of callback functions?

The second problem - I need to move inner ellipsoid so they would have one common side. How can I do this?

a=5; b=a; c=10; u = (0:0.05*pi:2*pi)'; v = [0:0.05*pi:2*pi]; X = a*sin(u)*cos(v); Y = a*sin(u)*sin(v); Z = c*cos(u)*ones(size(v)); Z(Z>0)=0; % cut upper V1=4/3*pi*a*b*c; d=1/2; e=2^d; a2=a/e; b2=a/e; c2=c; V2=4/3*pi*a2*b2*c2; X2 = a2*sin(u)*cos(v);%-2.5; Y2 = b2*sin(u)*sin(v); Z2 = c2*cos(u)*ones(size(v));%+0.25; Z2(Z2>0)=0; % cut h=1/3;

for j = 1:20 k1=(sin(pi*j/20)+0.5)^h; a=a*k1; c=c*k1; X = a*sin(u)*cos(v); Y = a*sin(u)*sin(v); Z = c*cos(u)*ones(size(v)); Z(Z>0)=0; a2=a2*k1; b2=a2*k1; c2=c2*k1; X2 = a2*sin(u)*cos(v)+5;%-2.5; Y2 = b2*sin(u)*sin(v); Z2 = c2*cos(u)*ones(size(v));%+0.25; Z2(Z2>0)=0; hS1=surf(X,Y,Z); alpha(.11) hold on hS2=surf(X2,Y2,Z2); hold off axis([-20 20 -20 20 -20 20]); F(j) = getframe; end movie(F,4)

© Stack Overflow or respective owner

Related posts about animation

Related posts about surface