The trajectory of an object in projectile motion can be described by
$$ x = x_0 + v_{0x}t$$$$ y = y_0 + v_{0y}t + 0.5gt^2$$Which says that the object will move at constant velocity in the horizontal direction, but with acceleration vertically.
In order to visualize this, we will use vpython. For that, first we want to import this library
In [5]:
from vpython import *
import math
Now, let's create a screen showing a ball of color red and initial position $x_0$, $y_0$
In [6]:
#initial position
x0 = -10.0
y0 = 0.0
#create canvas "screen"
scene1 = canvas(title='Projectile motion demo', width=600, height=300, center = vec(0,0,0))
#create ball
ball = sphere(pos = vec(x0,y0,0), radius=1, color = color.red, make_trail = True, trail_type="points")
#initial velocities
vx0 = 5.0
vy0 = 5.0
#define where the floor is
floor = - 11.0
ball.velocity = vector(vx0,vy0,0)
Then, we want to assign a small time step to see how the system evolves in time. And the system should evolve until the ball hits the floor
In [7]:
dt = 0.01
t = dt
while ball.pos.y > floor:
rate(100)
#note Projectile Motion equations are here!
ball.pos.x = x0 + vx0*t
ball.pos.y = y0 + vy0*t - 0.5*(9.8)*t**2
t = t+dt
Look at the path the sphere followed. Is that what you where expecting to see?
Now, let's make a more realistic model. Assuming that the force caused by air resistance is directly proportional to projectile's velocity, with k retarding force constant. The motion is described by the following expressions
$$ x = x_0 + \frac{v_{0x}}{k} \left( 1 - e^{-kt} \right)$$$$ y = y_0 + \frac{-gt}{k} + \frac{k v_{0y} + g}{k^2} \left( 1- e^{-kt} \right)$$Let's see how this looks like
In [14]:
x0 = 10.0
y0 = 0.0
floor = -11.0
scene2 = canvas(width=600, height=200, center = vec(0,0,0))
#create 2 balls at the same initial position
ball1 = sphere(pos = vec(x0,y0,0), radius=1, color = color.blue, make_trail = True, trail_type="points")
ball2 = sphere(pos = vec(x0,y0,0), radius=1, color = color.red, make_trail = True, trail_type="points")
#initial velocities
vx0 = 5.0
vy0 = 5.0
ball1.velocity = vector(vx0, vy0, 0)
ball2.velocity = vector(vx0, vy0, 0)
k1 = 1.05
k2 = 0.005
dt = 0.01
t = dt
while ball1.pos.y > floor:
rate(100)
#note Projectile Motion equations are here!
ball1.pos.x =
ball1.pos.y =
t = t+dt
#t2 = dt
#while ball2.pos.y > floor:
# rate(100)
# ball2.pos.x =
# ball2.pos.y =
# t2 = t2+dt
In [ ]: