Gravity modeling

I want to simulate a free fall and a collision with the ground (for example, a bouncing ball). The object will fall in a vacuum - air resistance can be lowered. A collision with the earth should cause some loss of energy, so that finally the object stops moving. I use JOGL to render a point, which is my falling object. The severity is constant (-9.8 m / s ^ 2).

I found the Euler method for calculating the new position of a point:

deltaTime = currentTime - previousTime; vel += acc * deltaTime; pos += vel * deltaTime; 

but I'm doing something wrong. The point bounces several times, and then moves down (very slowly).

Here is the pseudocode (initial pos = (0.0f, 2.0f, 0.0f), initial vel (0.0f, 0.0f, 0.0f), gravity = -9.8f):

 display() { calculateDeltaTime(); velocity.y += gravity * deltaTime; pos.y += velocity.y * deltaTime; if(pos.y < -2.0f) //a collision with the ground { velocity.y = velocity.y * energyLoss * -1.0f; } } 

What is the best way to achieve a realistic effect? How does the Euler method relate to constant acceleration equations?

+8
physics game-physics
source share
2 answers

Since floating points do not round well, you will never get a speed that is actually 0. Probably you will get something like -0.00000000000001 or something like that.

you need to do this 0.0 when it is close enough. (identify some delta.)

+6
source share

To expand my comment above and answer Tobias , I will add here the full answer.

After the initial check, I decided that you were bleeding fast. Simply put, the relationship between kinetic energy and velocity is E = mv^2 /2 , so after taking the velocity derivative you get

 delta_E = mv delta_v 

Then, depending on how energyloss defined, you can establish a relationship between delta_E and energyloss . For example, in most cases energyloss = delta_E/E_initial , then the above ratio can be simplified as

 delta_v = energyloss*v_initial / 2 

This assumes the time interval is small, allowing you to replace v in the first equation with v_initial so that you can get away from it for what you are doing. To be clear, delta_v is subtracted from velocity.y inside your conflict block, not what you have.

Regarding the question of adding air resistance or not, the answer depends on this. For small initial incidence heights, this does not matter, but it may begin to deal with less energy loss due to rebound and higher incidence points. For 1 gram, 1 inch (2.54 cm) diameter, smooth sphere, I plotted the time difference between and without air friction and drop height:

difference in time with and without air-drag vs. drop height

For materials with low energy loss (80 - 90 +% energy), I would think about adding it 10 meters or more, a drop in height. But, if the drops are below 2 - 3 meters, I would not worry.

If someone wants calculations, I will share them.

+2
source share

All Articles