function dy=generalHeight(x,h,a,v0,theta)

% Finds the height of a parabolic trajectory, above the ground,
% of a projectile thrown from the top of a hill
% Input
%   x  : horizontal position of projectile (m)
%   h  : hill heiht (m)
%   a  : hill width (m)
%   v0 : initial velocity of projectile (m/s)
%   theta : angle of initial velocity with horizon (rad)
% Output:
%   dy : vertical height of trajectory from ground (m)
% Usage:
%   h = height(50,200,800,100,30*pi/180)
% J.M.Soler. Nov.2011

% Set internal parameters
x0 = 0;                 % initial position at hill top
y0 = h;
g = 9.8;                % gravitational acceleration (m/s^2)

% Find y(x)
vx = v0*cos(theta);     % horizontal velocity
vy = v0*sin(theta);     % initial vertical velocity
t = (x-x0)/vx;          % time at point x, since x=x0+vx*t
y = y0+vy*t-0.5*g*t.^2; % vertical position at time t

% Find dy=y(x)-y0(x)
yground = h*exp(-0.5*(x/a).^2);  % ground height
dy = y-yground;                  % height above ground

end % function
