Durham Hackathon

A short intro to numerical simulation

View on GitHub

Previous step

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:

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:

  1. Set \(t\) to a small value to define one timestep of the simulation
  2. Compute the velocity \(v\) using the formula above
  3. Compute the new position by adding the travelled distance \(s\) to the current position
  4. 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

Next step