% -----------------------------------------------------
% trajectorytest.m
% -----------------------------------------------------
% A program used to test function projectileTrajectory.m
% Compute the x and y distances as a function of time for a 
% projectile given initial velocity. 
% -----------------------------------------------------
% Notes: Note the use of global variable g.  
% -----------------------------------------------------
% Copyright and license details available at matlabmarina.com
%------------------------------------------------------

clear;
clc;

% define global variables
global g

g = 32.2;     % acceleration due to gravity in ft/s^2

% Define inputs
v_initial = 200;  % initial velocity in ft/s
theta = 20;       % launch angle in degrees

% Compute for time from 0 to 20 s 
time = 0.00 : 0.01 : 4.50;        % time in seconds

% Calculute the trajectory - distance along x and y
[y, x] = projectileTrajectory(v_initial, theta, time);

% plot the trajectory
figure(1)
plot(x, y);
xlabel('distance along x in ft');
ylabel('distance along y in ft');
grid;

% plot the distances x and y vs time 
figure(2)
subplot(2,1,1);
plot(time, x);
xlabel('time in s');
ylabel('distance along x in ft');
grid;

subplot(2,1,2);
plot(time, y);
xlabel('time in s');
ylabel('distance along y in ft');
grid;
