% David Fisher
% Jan 28, 2010
%
% Plots a projectile ball thrown at 5 m/s at a 30 degree angle

function projectileBall

clc
% Define constants
initialVelocity = 5; % m/s
launchAngle = 30; % degrees
launchAngle = launchAngle/180*pi; % convert to radians
timeStep = 0.01; % Determines how many points in time the calculations are done
Vx = initialVelocity * cos(launchAngle); % Vx is constant without air resistance
initialVy = initialVelocity * sin(launchAngle); % Initial y velocity


% Store the time, x position, and y position in an accumulator
%  Each column of the matrix is currentTime;currentX;currentY
%  At time=0, x=0, and y=0 (column 1 of matrix)
currentTime = 0;
currentX = 0;
currentY = 0;
storedLocationsIndex = 1;
storedLocations(:,storedLocationsIndex) = [currentTime;currentX;currentY];  % start the ball at time = 0 , x = 0, y = 0
storedLocationsIndex = storedLocationsIndex + 1;   % We want to write column 2 next


while currentY >= 0
   % Increment the currentTime by the timeStep
   % Find the new currentX value:
   %   For practice make it a separate function and call it here
   %   Call the function getXLocation
   %     Pass that function the Vx and currentTime values
   %     It will return a value for you to store into currentX
   %     (see comment below for details writing that function)
   % Find the new currentY value:
   %   For practice make it a separate function and call it here
   %   Call the function getYLocation
   %     Pass that function the initalVy and currentTime values
   %     It will return a value for you to store into currentY
   %     (see comment below for details writing that function)
   
   
   % Store the currentTime, currentX, and currentY into the storedLocations
   % matrix accumulator for all rows at the storeLocationIndex column
   % Then increment the storeLocationIndex for the next loop
   
end % end the while loop

% Now you have a big matrix of stored locations, plot them
%  Hint: You can get all the elements in a row using storedLocations(2,:)
axis equal  % Helps make 30 degrees look like 30 degrees

fprintf('Done!\n\n');

end % end the funtion projectileBall


% TODO: Make a function called getXLocation
   %   Receives 2 inputs and has 1 output
   %   Receives Vx and the currentTime
   %   Returns the currentX value
   %   Inside that function you will have a line like this:
   %    currentX = Vx * currentTime


% TODO: Make a function called getYLocation
   %   Receives 2 inputs and has 1 output
   %   Receives initialVy and the currentTime
   %   Returns the currentY value
   %   Inside that function you will have a line like this:
   %    currentY = initialVy * currentTime + 1/2*a*currentTime^2
   %    (I'll let you define a)


% Hint: If you create an accidental infinite loop use Ctrl+c to exit