Mesh animation with MATLAB

Alec Jacobson

December 30, 2010

weblog/

Here's a small piece of code demonstration how to animate a triangle mesh using matlab. Assuming your mesh vertices are stored in V and your face indices in F then issue:
t = trisurf(F,V(:,1),V(:,2),V(:,3));
view(2)
axis equal
axis tight
ax = axis;
axis([ax(:,1)-10, ax(:,2)+10, ax(:,3), ax(:,4)+10]);
then = now;
while(true)
x = 10*sin(100000*(now-then));
y = abs(10*cos(100000*(now-then)));
set(t,'Vertices',[V(:,1)+x V(:,2)+y V(:,3)]);
drawnow;
pause(0.1);
end
matlab mesh animation It's a pretty slow animation, but any faster on a 800-vertices mesh MATLAB drops frames. The pause helps but of course makes it slower, as a side effect though the my CPU is only at 20%.