How Can Gravity Affect Distance Traveled in a Coding Simulation?

In summary, when trying to calculate the distance traveled by an object falling from any point in time, without knowing the initial time or velocity, you can use the equation: Distance = Vi * t + 0.5 * G * T2 with the velocity when you paused as Vi and t = 1 second. This will give you the distance traveled in the Y axis only starting from the moment you paused the fall to 1 second forward in time.
  • #1
bnpla
3
0
I'm tyring to code an engine that simply adds gravity to the world.
I know that gravity is a constant value added to the velocity of an object on each second, like this:

Velocity = Vi * t + 0.5 * G * T2

What I'm tyring to figure out, is the distance traveled of an object falling from any point in time, without having the values of the initial time or initial velocity...

Let's say i drop a coin from some distance to the floor. Now let's say i stop the time at some X seconds. I want to know how much the coin will move in the Y axis only knowing the velocity of the coin at that particular time and nothing else.

I don't want to know the total distance since i dropped the coin. I want to know the distance that the coin will travel starting from the moment i paused the fall to 1 second forward in time.
 
Physics news on Phys.org
  • #2
bnpla said:
I'm tyring to code an engine that simply adds gravity to the world.
I know that gravity is a constant value added to the velocity of an object on each second, like this:

Velocity = Vi * t + 0.5 * G * T2

That equation is incorrect

Vf = Vi + G * t
Xf = Xi + Vi * t + .5 * G * t2

I don't want to know the total distance since i dropped the coin. I want to know the distance that the coin will travel starting from the moment i paused the fall to 1 second forward in time.

Rewrite the second equation above.

distance = Xf - Xi = Vi * t + .5 * G * t2

Use the velocity when you paused as Vi and use 1 for t.
 
  • #3
It should be:
Distance = Vi * t + 0.5 * G * T2
so use this formula with [itex]v_i=v(X)[/itex] and [itex]T=1[/itex]
 
  • #4
Welcome to PF!

bnpla said:
I'm tyring to code an engine that simply adds gravity to the world.
I know that gravity is a constant value added to the velocity of an object on each second, like this:

Velocity = Vi * t + 0.5 * G * T2

Just a complaint about terminology: I would not say that gravity IS a constant value added to the velocity of an object each second. Gravity is a force. It is true that the force of gravity ADDS a constant value to the (vertical) velocity of a falling object each second. In other words, the force of gravity causes a constant acceleration. That is its effect. The change in velocity in one second due to this acceleration is what you described above. You might think I'm being pedantic, but it is important to distinguish between different types of quantities in physics. Gravity is a force, and a force is not the same thing as a velocity or an acceleration. A force causes an acceleration, which implies a change in velocity.

bnpla said:
What I'm tyring to figure out, is the distance traveled of an object falling from any point in time, without having the values of the initial time or initial velocity...

Let's say i drop a coin from some distance to the floor. Now let's say i stop the time at some X seconds. I want to know how much the coin will move in the Y axis only knowing the velocity of the coin at that particular time and nothing else.

I don't want to know the total distance since i dropped the coin. I want to know the distance that the coin will travel starting from the moment i paused the fall to 1 second forward in time.

You can still use the same equation and just take NOW to be the initial time, and "one second from now" to be the final time. So, in this situation, vi is the velocity now which we are taking to be the initial velocity. The important thing to remember is that the equation is actually:

d = vi Δt + (1/2)a(Δt)2

where Δt is the difference between the final time (after the distance has been travelled) and the initial time. Normally, we take the initial time to be t = 0, and the final time, t is the amount of elapsed time "up to now", so that Δt = t - 0 = t, and it's just fine to replace Δt with t. But if you're not starting at t = 0, then that's not the case.

Example:

You're watching a recorded video of me dropping a coin. Suppose, at t = 0, I dropped the coin (i.e. I released it from rest) from a height of 1 metre. Suppose that you come into the room 3 seconds after the video had already started. So you don't know what the initial height was. All you know is that right now at this instant (at t = 3 s) it is falling at a speed of 29.43 m/s. (Somehow you were able to determine this -- who cares how). Now, you want to determine how far it will have fallen (below its current height) one second from now, at t = 4 s. All you have to do is take the initial time ti to be 3 s , and the final time, tf to be 4 s. Then Δt = tf - ti = 1 s. In this time interval, the object will fall a distance:

d = vi Δt + (1/2)a(Δt)2

= (-29.43 m/s)*(1 s) + (1/2)(-9.81 m/s2)*(1 s)2

= -29.43 m - (4.905 m/s2)*(1 s2)

= -34.335 m

Notice that the ONLY numbers I used in the calculation above were: 1. the time interval I was interested in (1 s), 2. the velocity at the beginning of that time interval, and 3. the acceleration due to gravity.

A slight flaw with my example is that an object dropped from a height of 1 m would hit the floor long before t = 3 s, but who cares? It's irrelevant to the example. This is the distance that a freely falling object with that initial downward speed will fall in 1 second regardless of where or how fast it started.
 
  • #5
cepheid said:
Welcome to PF!

Just a complaint about terminology: I would not say that gravity IS a constant value added to the velocity of an object each second. Gravity is a force. It is true that the force of gravity ADDS a constant value to the (vertical) velocity of a falling object each second. In other words, the force of gravity causes a constant acceleration. That is its effect. The change in velocity in one second due to this acceleration is what you described above. You might think I'm being pedantic, but it is important to distinguish between different types of quantities in physics. Gravity is a force, and a force is not the same thing as a velocity or an acceleration. A force causes an acceleration, which implies a change in velocity.

Yes i know, i was in a rush, and i do agree that terminology IS important.

cepheid said:
You can still use the same equation and just take NOW to be the initial time, and "one second from now" to be the final time. So, in this situation, vi is the velocity now which we are taking to be the initial velocity. The important thing to remember is that the equation is actually:

d = vi Δt + (1/2)a(Δt)2

Thanks! Finally i can sleep! Having no background in physics, this simple problem was killing my poor brain, lol. At one time i was using that same formula, and i was getting wrong results, but after i saw this posts i noticed my error: i was taking the initial distance rater than speed in the first component of the equation, so that was destroying my rational brain haha.

Ok, problem solved!


As a side note, i ended up solving this problem on a diferent manner a few moments before reading this post. I formulated this:

*** Warning: this formula was made up without physics knowledge ***

Code:
Let V = Velocity of the object at a given time.
Let Y = Vertical position of the object at a given time.

StepY = V * (V/g)  * 0.5  - Y; //this is how much the object will move in the next second.
 
  • #6
PS: i will use the d = vi Δt + (1/2)a(Δt)2 formula, my "made up formula" is way to ugly, and it was a desperated attempt to solve my problem. Doing Vi + 0.5 * a is way cleaner, because i will always evaluate 1 second ahead of time.
 

FAQ: How Can Gravity Affect Distance Traveled in a Coding Simulation?

What is gravity?

Gravity is a fundamental force of nature that causes objects with mass to be attracted to each other. It is responsible for keeping planets in orbit around the sun and for keeping us grounded on Earth.

How does gravity affect distance traveled?

Gravity affects distance traveled by causing objects to accelerate towards each other. The stronger the gravitational force, the greater the acceleration, and therefore the greater the distance traveled over time.

What is the formula for calculating the force of gravity?

The formula for calculating the force of gravity is F = G(m1m2)/r^2, where F is the force of gravity, G is the universal gravitational constant, m1 and m2 are the masses of the two objects, and r is the distance between them.

Does the distance between two objects affect the strength of gravity?

Yes, the distance between two objects does affect the strength of gravity. The force of gravity decreases as the distance between two objects increases. This is represented by the inverse square law in the formula for calculating the force of gravity.

How does mass affect the force of gravity?

The force of gravity is directly proportional to the masses of the two objects. This means that the greater the mass of the objects, the stronger the force of gravity between them. This is also represented in the formula for calculating the force of gravity.

Similar threads

Replies
2
Views
7K
Replies
11
Views
2K
Replies
11
Views
1K
Replies
12
Views
3K
Replies
6
Views
1K
Replies
6
Views
461
Replies
1
Views
2K
Back
Top