Professional Documents
Culture Documents
%pOsXY
%Calculate the total distance along X and Y -- dX and dY
dX = Vx * t;
dY = Vy * t;
%Make adjustments for the postion so that the particle starts from origin
adjusting the time accordingly.
% Horizontal side
if (Vx < 0)
dX = -1*Vx * t;
if (posX > dX)
fposX = posX - dX;
else
calposX
%call function to cal position of X
end
else
if ((posX+dX)<= 10)
else
end
calposX
%call function to cal position of X
end
dX = dX + posX;
% Vertical side
if (Vy < 0)
dY = -1*Vy * t;
if (posY > dY)
fposY = posY - dY;
else
calposY
%call function to cal position of X
end
else
if ((posY+dY)<= 10)
fposY = posY + dY;
else
calposY
%call function to cal position of X
end
dY = dY + posY;
end
disp( sprintf( 'The final position of the particle is in X is %d, and Y is
%d', fposX, fposY ));
%Calculate the position of Y Make adjustments for the postion so that the
particle starts from origin adjusting the time accordingly.
if (Vy < 0)
dY = dY - posY;
else
dY = dY + posY;
end
%Calculate the final position and the number of time it bounces along the
%walls
bY = dY/20; %bouces on Y
disp( sprintf( 'It bounced %d times on the horizontal side', floor(bY*2) ));
if ((bY - floor(bY))<= 0.5)
fposY = dY - (floor(bY)*20); % final position of the particle along the x
direction
else
fposY = 20 - dY + (floor(bY)*20);
end
%Calculate the position of X Make adjustments for the postion so that the
particle starts from origin adjusting the time accordingly.
if (Vx < 0)
dX = dX - posX;
else
dX = dX + posX;
end
%Calculate the final position and the number of time it bounces along the
%walls
bX = dX/20; %bouces on X
disp( sprintf( 'It bounced %d times on the verticle side', floor(bX*2) ));
if ((bX - floor(bX))<= 0.5)
fposX = dX - (floor(bX)*20); % final position of the particle along the x
direction
else
fposX = 20 - dX + (floor(bX)*20);
end