# This program computes the trajectory of a projectile. import math # constant for Earth acceleration in meters/second^2 ACCELERATION = -9.81 def main(): # explain program print("This program computes the") print("trajectory of a projectile given") print("its initial velocity and its") print("angle relative to the") print("horizontal.") print() # read input from user velocity = float(input("velocity (meters/second)? ")) angle = math.radians(float(input("angle (degrees)? "))) steps = int(input("number of steps to display? ")) print() x_velocity = velocity * math.cos(angle) y_velocity = velocity * math.sin(angle) total_time = -2.0 * y_velocity / ACCELERATION time_increment = total_time / steps x_increment = x_velocity * time_increment x = 0.0 y = 0.0 t = 0.0 print("step", "x", "y", "time", sep="\t") for i in range(steps + 2): print(i, round(x, 2), round(y, 2), round(t, 2), sep="\t") t += time_increment x += x_increment y = y_velocity * t + 0.5 * ACCELERATION * t * t main()