
Just an implementation of Mike's suggestion. I recognize this is an old topic, but I felt like taking a crack at it anyway. The sample might be a bit messy but it was just to figure out what kind of formula goes behind this all. I think I've got it for 99% but can't seem to find the last piece. Seaching for formula's which incorporate an initial velocity (which is probably what I need) all gave me a complete different formula than the one I have. The angle is currently at 45 degrees but it should also accept negative degrees such as -10. ("Expected seconds: "+secondsTillImpact+" Result seconds: "+recordedTime) I figured, reducing the below variable from secondsTillImpact would give the correct time but it did not.ĭouble secondsTillImpactTwo = ((ySpeed))/-(gravity) This seems to give a very accurate time whenever the angle is positive.ĭouble secondsTillImpact = Math.sqrt(2*y/-(gravity)) double secondsTillImpact = Math.sqrt(2*y/-(gravity+(ySpeed*2.5)))

double secondsTillImpact = Math.sqrt(2*y/-(gravity-ySpeed))

gravityAndInitVelocity = gravity+ySpeed time declares the interval before checking the new location.ĭouble xSpeed = velocity * s(Math.toRadians(angle)) ĭouble ySpeed = velocity * Math.sin(Math.toRadians(angle)) Public ProjectileTest (float velocity, float angle) I've seen all kinds of (hard to read) formula's and have concocted the following: What I am trying to figure out is the amount of time in seconds a projectile is traveling while completing its flight.

#Projectile motion equations time of flight code
I've looked at various sites explaining projectile trajectories in combination with gravity but I can't seem to get my code right. I've been lurking some time on the forums but today I encountered a problem which I simply can't seem to solve.
