Simple math/trig problem with velocity+gravity

BlitzMax Forums/BlitzMax Beginners Area/Simple math/trig problem with velocity+gravity

kronholm(Posted 2007) [#1]
Hey guys, I'm hoping someone can help me with this problem. It's probably very simple but I've spent hours now trying to figure it out.. Let me try to describe the gist of it.

I have a ball that's being thrown up in the air, starting from y = 0, i.e. groundlevel. To move it, I subtract an yvel value of for instance 5, so it moves up by 5 pixels each frame. I know that it will move for 100 frames, thus leaving it at -500 y if it just goes at it.

But I want it to fall down, thus I add a gravity value to the yvel each loop. The gravity could for instance be -0.1. So when it runs now, the ball goes up, reaches an yvel of 0 at some point, and then goes negative, causing it to fall, and landing (well, passing the ground) at an unknown point in time.

Now, what I want to do, is calculate how much gravity it would take for the ball to be thrown up at an initial yvel of 5 (or anything else), and then be at the ground coordinate (y=0) at the exact last frame, frame 100.

It boggles me! Never had any sort of trig, and I'm pretty numbers-blind so to speak unfortunately.. I'd appreciate it if anyone could throw me a bone, maybe even explain it thoroughly so I can it through my thick skull :)


Matty(Posted 2007) [#2]
High school physics texts covers this and is usually expressed with the following formulae:

Velocity = Initial Velocity + Acceleration * Time

Velocity * Velocity = (Initial Velocity * Initial Velocity) + 2*Acceleration*Displacement
Displacement = Initial Velocity * Time + 0.5 * Acceleration * Time*Time

In your case you want to use that 3rd formula.

Displacement = 0 (start/end position)
Initial Velocity = the yvel you specify above (units / frame)
Time = the variable you have specified as 100 frames above
Acceleration = the value you want to solve for.

So taking your values above of yvel=5 units/frame and Time=100 and Displacement = 0

0 = 5*100 + 0.5*Acceleration*100*100

rearranged gives you
-500 = 0.5*10000*Acceleration

Therefore Acceleration is
-500.0/(0.5*10000) units/frame^2
(which is -500/5000 = -0.1 units/frame^2)

EDIT - these are only for constant accelerations, like gravity in the situation you've mentioned above.


kronholm(Posted 2007) [#3]
I need a way to calculate the gravity, which is being subtracted from yvel every frame. Basically just how much gravity I need for a certain yvel, e.g. 5, so y (y:-yvel) reaches 0 at a certain time, e.g. 100.


kronholm(Posted 2007) [#4]
Figured it out, thanks


alanc5(Posted 2007) [#5]
What was the solution? Trig/math stuff always interests me.