function Y_dot = pingpong_ode_dl(t,Y)
% this function is the ode solver for projective motion of a ball when
% factoring in drag and sping force


global m g s 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; % air density in slug/ft^3, this was bcause we neeeded to take out the mass term
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);
df_y = df*(v_y/v_mag);


% spinning lift force
% s = rev/ sec
c_l = 0.065;  % approximated form the Stanford paper simulations -> make sure to cite

% will need to add update since it decreases dye to viscous forces
% s = -70; %rev / sec -> max is somewhere close to 150 rev/ sec global
% variable now
L = (4/3)*(4*pi*r^3*abs(s)*rho*v_mag)*c_l;
theta = atan(v_y/v_x);

lx = sign(s)*L*sin(theta); % need to multiple the lift in each direction by the corresponding direction
ly = sign(s)*L*cos(theta);

% acceleration
a_x = df_x/m + lx/m;  %
a_y = -g + df_y/m + ly/m;  % ft/sec^2 

% bouyant force is on the order of 2.85e-3 which is pretty negligible in
% reference to the drag and lift generated by the spin

Y_dot = [v_x;a_x;v_y;a_y];  % the derivative of the state space vectors

end


