function Y_dot = pingpong_ode_d(t,Y)
% this functin does projectile motion through an ode solver with only drag
% acting as the force
global m g r
% split up the state space vector
% x direction
% r = [Y(1) Y(3)];
% x_dot and y_dot
v_vec = [Y(2) Y(4)];
v_x = Y(2);
v_y = Y(4);
% drag info
% r is a global variable
rho = 0.0023769; % slug/ft3; % air density has to be in mass/volume terms
A = 4*pi*r^2; % area of circle
c_d = 0.65; % obtained from downloaded paper
% magnitude of the force is needed
v_mag = norm([v_x v_y]);
% drag force
df = -0.5*A*rho*c_d*(v_mag^2);% direction of force is directly against velocity
df_x = df*(v_x/v_mag); % this is just cosine theta
df_y = df*(v_y/v_mag); % this is just sine theta
% acceleration
a_x = df_x/m; %
a_y = -g + df_y/m; % ft/sec^2
Y_dot = [v_x;a_x;v_y;a_y]; % the derivative of the state space vectors
end