Every physics textbook has the projectile formulas for a vacuum: range R = u² sin 2θ / g, time of flight T = 2u sin θ / g and maximum height H = u² sin² θ / 2g. Real balls fly in air, and the answer changes a lot. Here is a small simulation that shows how much, and why the best launch angle is no longer 45 degrees.
The model
Gravity pulls down with g = 9.81 m/s². Air drag points against the velocity and grows with speed. I use a quadratic drag, a_drag = -k * |v| * v , where k (in 1/m) bundles air density, area, mass and the drag coefficient. k = 0 is the textbook case.
The code
function fly ( { speed , degrees , k = 0 , g = 9.81 , dt = 0.001 } ) { const a = ( degrees * Math . PI ) / 180 ; let x = 0 , y = 0 , vx = speed * Math . cos ( a ) , vy = speed * Math . sin ( a ) ; let t = 0 , top = 0 ; while ( y >= 0 ) { const v = Math . hypot ( vx , vy ) ; vx += - k * v * vx * dt ; vy += ( - g - k * v * vy ) * dt ; x += vx * dt ; y += vy * dt ; t += dt ; top = Math .…