clear all; close all;

N = 200; % number of points
t = linspace(0,10,N); %time

v = sin(t);  % car's longitudinal velocity
theta = cos(t); % car's arientation with resoect to fixed frame

x(1) = 0;    % initial position
y(1) = 0;

figure(1); hold on; 
axis equal;  
axis([-10 40 -10 10]);

for n=1:N
    x(n+1) = x(n) + v(n)*cos(theta(n));  % this is equivalent to discretized dynamics with forward Euler
    y(n+1) = y(n) + v(n)*sin(theta(n));
    h = plot_car(x(n),y(n),theta(n),1,'b');  %plot car
    pause(0.1); % pause between two different frames
    M(n) = getframe;   % this is to create a movie
    %delete(h);  % remove plot of car
end

movie(M);  %this is to play a movie
%movie2avi(M,'movie_car','quality',100,'compression','None');   % check use of moviw2avi with help in Matlab. Note that no compression gives best resolution but huge video size !!!!
    

