% Procedure to calculate the vertical curve of a transition curve of a
% runway. Uses the same principles used in geomtric desig of highways.
% The curve studied here is a symetrical parabola with length L and grades
% g1 and g2.
%
% Created by: Toni Trani (10/23/2024)
% Added legend to the plot

% Inputs
%
% L         = Curve length (feet)
% g1       = First slope (%)
% g2       = Second slope (%)
% Spvc    = Station of the point of vertical curve (first tangent point) -feet
% Epvc    = Elevation of point of vertical curve (feet)


% Clear screen
clc

disp(' ')
L = input ('Curve Length (ft) =   ');

disp(' ')
g1 = input ('First tangent slope =   ');

disp(' ')
g2 = input ('Second tangent slope =   ');

disp(' ')
Spvc = input ('Station of PVC (feet)=   ');

disp(' ')
Epvc = input ('Elevation of PVC (feet)=   ');

% Compute the algebraic difference  between grades g1 and g2 (%)

A = g2 - g1;                                                        % algebraic change in grade (%)

% Find 100 points on the curve to make a plot

Spvt = Spvc + L;                                                % station of PVT point (ft)

npoints = 100;                                                  % number of points on the curve
x = linspace(0,L,npoints);                                  % creates 100 points along the x axis and saves them in a vector x
Ep = Epvc + (g1/100)*x + A*x.^2/(200*L);     % vector of points on the curve (elevation) 
Sp = Spvc + x;                                                   % vector of stations on the curve (ft) 

Epvt = Ep(npoints);                                           % elevation of PVT point - the last one of Ep (ft.)

% Find the lines for each semi-tangent segment

st1x = [Spvc Spvc+L/2];                                  % first semi-tangent (x coordinate points)
st1y = [Epvc Epvc+(g1/100)*L/2];                  % first semi-tangent (y coordinate points)
st2x = [Spvc+L/2 Spvc+L];                             % second semi-tangent (x coordinate points)
st2y = [Epvc+(g1/100)*L/2 Ep(npoints)];      % second semi-tangent (y coordinate points)

% Make a nice plot of the data created including two lines representing the
% grades g1 and g2

plot(Sp,Ep,'o-',st1x,st1y,'--',st2x,st2y,'--')
    xlabel('Distance (ft.)','fontsize',24)
    ylabel('Elevation (ft.)','fontsize',24)
    legend('Parabolic Curve','First Tangent Line','Second Tangent Line','fontsize',24)
    grid
