How to drop a ball for real
The equations of motion are a set of formulas that enable us to describe the movement of an object. An object in free fall simply moves along a straight line since it is only driven by gravity that accelerates the object by means of the earth’s gravitational constant \(g \sim 9.81 \frac{m}{s^2}\). Therefore, we only need to consider the equations of motion for linear motions with constant acceleration.
To describe the motion of an object in free fall, we consider the following values:
- the initial velocity \(u\)
- the constant free fall acceleration \(-g\)
- a time \(t\), meaning, the duration of the motion
- a distance \(s\), meaning, how far the object moves
Based thereon, we can compute the distance \(s\) that an object travels in a certain amount of time \(t\) as follows:
\[s = v \cdot t\]As you can see, this requires us to know the velocity \(v\) of the object. For a linear motion with constant accleration, \(v\) can be computed as follows:
\[v = u + g \cdot t\]To rewrite the code for the falling ball from the previous step with correct physics, you might want to follow these steps:
- Set \(t\) to a small value to define one timestep of the simulation
- Compute the velocity \(v\) using the formula above
- Compute the new position by adding the travelled distance \(s\) to the current position
- Congrats! This is one timestep of your simulation.
Since this is executed in an infinite loop, the simulation is already complete :-)
Add gravity:
Fancy a hint? You can find the solution here.
Want to know where all these equations actually come frome? Take a look here