% Write a script to plot a projectile.
% equations needed -- from Physics 1:
% x = x0 + v0*cos(angle0)*t;
% y = y0 + v0*sin(angle0)*t - g*t.^2/2; 
% 
% note: the angle input will be in degrees so we will need to use sind and
% cosd

% let's reset all active variables
clear

% ---------------------------------------------------------------- INPUTS

% ask user for starting position, velocity, angle, time
x0 = input('Starting x position (meters): '); 
fprintf('x0 = %d\n',x0);

y0 = input('Starting y position (meters): '); 
fprintf('y0 = %d\n',y0);

v0 = input('Initial velocity (m/s): '); 
fprintf('v0 = %d\n',v0);

angle0 = input('Initial angle (degrees): ');
fprintf('angle0 = %d\n',angle0);

t = input('Elapsed Time (seconds): ');
fprintf('t = %d\n',t);

c = input('Plot color (red = r, blue = b, green = g -- do not forget to use quotes for strings): ');

if (c ~= 'r') && (c ~= 'b') && (c ~= 'g')
    fprintf('You have chosen and invalid color so we will default to red.\n');
    c = 'r'; % set default color to red
else 
    fprintf('color = %d\n',c);
end

% ----------------------------------------------------------------CONSTANTS

% acceleration of gravity in m/s
g = 9.8;

% ----------------------------------------------------------------

% build out a vector in time (divided into 1/100 sec intervals)
time   = 0:.01:t;

% these are our algorithmic equations
x = x0 + v0*cosd(angle0)*time; 
y = y0 + v0*sind(angle0)*time - g*time.^2/2; 

% this will keep the plots on the figure so we can show multiples
hold on

% this will clear the current figure so only one plot shows
%clf 

plot(x,y,c);

% thank the user for wasting their time with this
disp('Thank you for using this tool!');