PDA

View Full Version : [HOWTO] Matem/Simulazione, creare un filmato con octave


gurutech
27-05-2006, 15:06
ciao,
oggi ho smanettato un po' per la tesi ed ho trovato, googlando un po', il modo di creare filmati avi con GNU Octave e Mencoder. Posto qui perchè mi sembra la sezione adatta, ma se così non è spostate pure :)

robot.m

clear;
th0=0;
phi0=0;
x=3.1;
y=2.8;
xc=0;
yc=0;
psi0=atan((yc-y)/(xc-x));
r=sqrt((x-xc)^2+(y-yc)^2);
v=3;
wc=v/r;
OM=.3*pi;
oml=.9*pi;

axis([-10 10 -10 10]);
grid on;
gset term jpeg
%gset term x11
n=0;
for t=0:0.01:3.5
n=n+1;
eval(sprintf('gset output \"/tmp/%s%05d.jpg\"','frame',n))
x=xc+r*cos(wc*t+psi0);
y=yc+r*sin(wc*t+psi0);
th=th0+t*OM;
phi=th0+phi0+t*(OM+oml);
plotbot(x,y,th,phi);
usleep(5*10^4);
end


plotbot.m

function plotbot(x,y,th,phi)

d=1.5;
l=.5;

vx=zeros(1,4);
vy=zeros(1,4);
k=0;
for k=1:4
vx(k)=x+d*cos(th+(2*k-1)/4*pi);
vy(k)=y+d*sin(th+(2*k-1)/4*pi);
end
plot([vx vx(1)],[vy vy(1)],[x x+l*cos(phi)],[y y+l*sin(phi)]);


incollare i file con mencoder

cd /tmp
mencoder mf://*.jpg -mf w=640:h=480:fps=25:type=jpg -ovc lavc -lavcopts vcodec=mpeg4:mbd=2:trell -oac copy -o output.avi


risultato:
http://www.gurutech.it/files/robot.avi