clear all;close all;clc;vA = [2.31; -0.55]; % initial velocity OF 1
dt = 0.1; % time step for animation.
t = 0:dt:10 ; % get points trajectory
pA = zeros(2,length(t)+1) ;pA(:,1) = [4 ;10] ; % initial position
for i = 2:length(t)+1 % t is time variable
% plot(pA(1),pA(2),'ro') % Plot circle
pA(:,i) = pA(:,i-1) + vA*dt; % update position
%pB(:,i) = pB(:,i-1) + vB*dt; % update position
end%plot
figuretitle('Motion animation');%xlabel('x (m)');
%ylabel('y (m)');
h = plot(pA(1,2),pA(1,1),'cs') ;%h = plot(pB(1,1),pB(1,2),'gp') ;
axis([min(pA(2,:)) max(pA(2,:)) min(pA(1,:)) max(pA(1,:)) ])for i = 1:length(pA) set(h,'XData',pA(1,i),'YData',pA(2,i)) %set(h,'XData',pB(1,i),'YData',pB(2,i))
pause(.5)end
this is the code for a single object moving with constant velocity,anyone explain how to create two objects with same velocity?
Best Answer