DEV Community

Cover image for Ball Trajectory Hypothetical
Scott Gordon
Scott Gordon

Posted on

Ball Trajectory Hypothetical

#   This function predicts a balls hypothetical projectory
#   where x is the horizontal position, and default horizontal
#   speed is 0.99 meters per second and initial vertical speed
#   is 9.9 meters per second
# by Scott Gordon

import matplotlib.pyplot as plt

def ball_trajectory(x):
    location = 10*x - 5*(x**2)
    return location

# Plot the hypothetical ball trajectory between moment it is
# thrown (x = 0) and when it hits ground (x = 2)
xs = [x/100 for x in list(range(201))]
ys = [ball_trajectory(x) for x in xs]
plt.plot(xs, ys)
plt.title('The Trajectory of a Thrown Ball')
plt.xlabel('Horizontal Position of Ball')
plt.ylabel('Vertical Position of Ball')
Enter fullscreen mode Exit fullscreen mode

Top comments (0)