• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Calculating time of flight for projectile with gravitational trajectory

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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!
 
Ranch Hand
Posts: 287
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.



 
Ranch Hand
Posts: 789
Python C++ Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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

 
Andrew Kenyon
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic