2D Road animation

I am animating a road which will be used in the analysis of a half car suspension model. At the moment the plot follows the road as it is being generated. What I want to do is plot the car in the middle of the plot and pull the road from right to left underneath the car.
for t = 1:200
r = road(t);
R(t,:) = r;
% pause(.05)
set(line,'YData',R); %# Update the y data of the line
drawnow %# Force the graphics to update immediately
ylim([-1 1])
xlim([t-5 t+5])
end
figure; plot(R,'k');
ylim([-1 1])
Does anyone have any suggestions on how to, rather than follow the road, have it come across the figure. Any help is much appreciated.

1 comentario

James Murphy
James Murphy el 26 de Abr. de 2016
The road function is as follows,
function [x] = road(t)
% ROAD takes in time t and outputs height x.
% road produces a step at t = 50s, undulation at t=100 and random road at
% t>150.
if t < 50
x = 0;
return
elseif t >=50 && t < 100
x = 0.05;
return
elseif t>=100 && t<150
% x = 0.05 + 0.025*(0.4*sin(t));
% x = (.05*sin(f*[1:.1:126]))+.05;
x = 0.05*sin(0.25*t) + 0.05;
return
else
x = 0.05 + 0.025*rand(1);
return
end

Iniciar sesión para comentar.

Respuestas (0)

Categorías

Más información sobre Animation en Centro de ayuda y File Exchange.

Preguntada:

el 26 de Abr. de 2016

Comentada:

el 26 de Abr. de 2016

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by