contestada

Callista "cherry bomb" davidson is a world-famous stunt woman, and she is trying to achieve the long distance world record human cannonball. she needs your help, though, because she has no idea what angle is best to aim her cannon. you will need to simulate firing the cannon at all integer angles from 1 to 90 inclusive.

Respuesta :

Answer:

CODE

import time #importing time module

import math #importing math module

pi = math.pi #defining the value of pi

u = 70 #initial velocity

g = 9.8 #gravitational acceleration

time_step = 0.01 #time step of 0.01 secs

time_elapsed = 0.0

maxAngle = 0

angle = 1

h = 5.0 #setting the initial height to to 5m

x = 0.0

maxRange = 0.0

for angle in range(1,91): #loop which angle takes value from 1 to 90

ux = u * math.cos((pi / 180) * angle) #velocity in x axis

uy = u * math.sin((pi / 180) * angle) #velocity in y axis

for i in range(1000): #running for 1000 steps

dragx = 0.5 * 1.225 * 1.4 * 0.8 * ux * ux #calculating the drag in x direction

dragy = 0.5 * 1.225 * 1.4 * 0.8 * uy * uy #calculating the drag in y direction

drag_ax = dragx / 65.0 #calculating drag acceleration in x axis

drag_ay = dragy / 65.0 #calculating drag acceleration in y axis

accelx = drag_ax #resultant acceleration in x axis

accely = g + drag_ay #resultant acceleration in y axis

vx = ux - accelx * time_step #velocity in the x axis at any instant

vy = uy - accely * time_step #velocity in the y axis at any instant

h += uy * time_step - 0.5 * accely * time_step * time_step #height at any instant of the projectile

x += ux * time_step - 0.5 * accelx * time_step * time_step #range at any instant in the x axis of the projectile

print("Height " + str(h) + " Range " + str(x)) #printing the current position

time.sleep(time_step) #waiting for 0.01 secs

time_elapsed += time_step #calculating the time elapsed

ux = vx #setting the final velocitites to new initial velocities

uy = vy

if h <= 0.0: #if a height 0 is reached

if x > maxRange:

maxRange = x #max angles are noted

maxAngle = angle

h = 5.0 #variables are initialized

x = 0.0

u = 70.0

vx = 0.0

vy = 0.0

print("Wait till the next simulation starts.....")

time.sleep(10.0 - time_elapsed) #wait for 10 secs

time_elapsed = 0.0

break

print("The optimum angle for for Callista is {} degrees which will give her a range of {} metres".format(str(maxAngle),str(maxRange))) #the optimum angle is printed

Explanation: