from math import sin, cos, radians
class Projectile:
"""Simulate the flight of a simple projectiles near the earth's surface
ignoring wind's resistance. Tracking is done in two dimensions, height (y) and distance (x)"""
def __init__(self, angle, velocity, height=0):
""" Create a Projectile with given launch angle, initial velocity and height"""
self.xpos= 0.0
self.seconds = 0
self.ypos = height
theta = radians(angle)
self.xvel = velocity * cos(theta)
self.yvel = velocity * sin(theta)
def update(self, time):
"""Update the state of this projectile to move it time seconds farther into the flight"""
self.xpos = self.xpos + self.xvel * time
yvel1 = self.yvel - 9.8 * time
self.ypos = self.ypos + time * (self.yvel + yvel1)/2.0
self.yvel = yvel1
self.seconds += time
# Check if maximum height reached
if(round(self.yvel) == 0 and self.yvel > 0 ):
print(f'After %.2f seconds, maximum height at %.2f m.'%(self.seconds, self.ypos))
def __str__(self):
"""Prints the details about the projectile"""
return f'After %.2f seconds, position is X: %.2f m, Y: %.2f m, velocity is %.2f m/s' %(self.seconds,self.xpos, self.ypos, self.xvel)
p = Projectile(47, 40)
for _ in range(75):
p.update(0.05)
print(p)
Using Python a) Add a function to the Projectle class below so it can print out...
MATLAB,
please provide code script
Objective: Create a function file that animates projectile motion defined by the following equations in a subplot. Your function should accept user inputs of launch speed and launch angle. The output of your function will be a top subplot that displays height (y) as a function of x. The bottom subplot should display the vertical velocity while the projectile is in motion. A video of what your animation should look like is posted with this...
How to do this question using while loop only?
What happens if you try to pay less than $5 per month? In Chapter 1, we studied the problem of a projectile being launched at an angle of theta at an initial velocity of v. The equations for the height h and horizontal location x as functions of time t are as follows: h(t) = vt sin theta - 1/2 gt^2 x(t) = vt cos theta Write a MATLAB program to...
HW#5 Functions and Arrays
For HW#5 we will return to the state method of solving the
ballistic projectile problem with added twists. The goal will be to
hit a target 1000 meters east of your cannon but the wind is
blowing from the south. Your initial muzzle velocity is fixed at
110 meters per second, but you can control the elevation and
azimuth angles of your aim. Elevation angle is measured up or down.
Azimuth angle is measured right or...
Please help me correct my MATLAB script code for this
problem, thank you!!
A projectile PA is launched from point A towards the east with an initial launch velocity voa and an initial lauw angle of 0x. The impact point of the projectile Pa is a point B in a valley with an ordinate, yon, located below the clevation of point A. The launch from point A is instantaneously detected at point B, and a counter projectile P launched simultaneously...