Forums Register Login

Calculating time of flight for projectile with gravitational trajectory

+Pie Number of slices to send: Send
Hi!

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

What I am trying to figure out is the amount of time in seconds a projectile is traveling while completing its flight. I've seen all kinds of (hard to read) formula's and have concocted the following:



The angle is currently at 45 degrees but it should also accept negative degrees such as -10. 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. I think I've got it for 99% but can't seem to find the last piece.
The sample might be a bit messy but it was just to figure out what kind of formula goes behind this all.

Thank you for your time!
+Pie Number of slices to send: Send
Split the movement of the projectile into two parts - horizontal and vertical speeds.
Then just use the vertical velocity as that's the only bit that matters.
You could work out the height of a projectile at any given moment by applying the vertical climb and subtracting gravity.
Obviously gravity will be -10m/s after 1 sec, -20m/s after 2 secs etc.
When the height reaches 0 then that's how long it stays in the air.
Then I'd just store these results in a quick look up table and work out the vertical velocity on the fly from the angle.
This will work fine for games but I'd suggest something more rigorous if you're planing on launching men into space

Mike
+Pie Number of slices to send: Send
I recognize this is an old topic, but I felt like taking a crack at it anyway. Essentially it is
just an implementation of Mike's suggestion. The quadratic function was added to provide
a better prediction of the total time the projectile is in motion.

The formulas can be found in any physics I textbook (or online). As for the reason behind
all the variable name changes, it just made it easier for me to keep track of the components.

Abridged Legend:

vi := Velocity Initial
vxi := Velocity X-component Initial

you get the idea.



+Pie Number of slices to send: Send
 

Andrew Kenyon wrote:I recognize this is an old topic, but I felt like taking a crack at it anyway.



I plotted some of the output and it gives a nice arc. Nice work. I was snooping around and found this code using differential equations translated to code.

http://www.codeproject.com/Articles/19107/Flight-of-a-projectile

+Pie Number of slices to send: Send
Good find. I've bookmarked it for my own reference.

From reading over the OP's comments (and the comments in his code), I didn't get the impression that he'd had any recent exposure to the calculus or even to algebra-based physics.
With that in mind, I tried to keep the changes easy to follow (if he ever checks back). I do really like that code in that link you provided, and if I ever need to build something more
robust I'll definitely use it for inspiration.
If you open the box, you will find Heisenberg strangling Shrodenger's cat. And waving this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 2878 times.
Similar Threads
StackOverflowError when trying to use threads
Trying to calculate lines over pi/4
Angles
Trouble with java's sin() method
Intersection points not being determined accurately- java awt
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 03:10:33.