Notes | Code and Results |
---|---|
Motion without gravity.
We have a ball moving upward (in the y-direction) at 5 m/s, so its velocity vector is:
$$ \vec{v} = <0, 5, 0> $$
Notice that:
These equations for the position comes from the fact that, as we all know, velocity is the change in distance over time. Considering only motion in the x direction (vx):
$$ v_x = \dfrac{\Delta x}{\Delta t} $$
We can write the change in distance (Δx) as the difference in the old and new positions:
$$ v_x = \dfrac{x_{new} - x_{old}}{\Delta t} $$
Therefore, if we know the velocity (v), the time step (Δt), and the starting position (xold), then we can solve this equation to find the new position (xnew).
$$ x_{new} = x_{old} + v_x \cdot \Delta t \tag{1}$$
This could be read as: the new position is equal to the old position plus the change in position.
There is no motion in the x direction, but the same general equation applies in y, so:
|
The result should look like:
|
Adding gravity (acceleration)Acceleration is the change in velocity (Δv) with time (Δt) so: $$ a = \dfrac{v_{new} - v_{old}}{\Delta t} $$ So for each timestep, we'll solve this equation for the new velocity (vnew ): $$ v_{new} = v_{old} + a \cdot \Delta t \tag{1}$$ The acceleration due to gravity (g) is: $$ a = g = -9.8 \, \text{m/s}^2 $$ So, for vertical, ballistic motion we can write the equation as: $$ v_{new} = v_{old} + g \cdot \Delta t \tag{2}$$ We can add this as a single line to the previous program, before we calculate the new position.
|
|
Add a floor
Add a floor to your model so the ball bounces.
|
|