Question: Imagine you're creating a computer program that simulates the motion of a ball bouncing on the ground until it comes to a stop. Here are

Imagine you're creating a computer program that simulates the motion of a ball bouncing on the ground until it comes to a stop.
Here are the key details:
The simulation happens on a flat surface, with coordinates in three dimensions: x, y, and z.
You'll start the simulation by launching a ball with a certain speed, angle, and direction.
Parameters you'll use:
Starting Speed: How fast the ball is initially moving.
Starting Bearing: The angle at which the ball is launched from the horizontal.
Starting Trajectory: The angle at which the ball is launched from the vertical.
Bounce Percentage: How much energy is retained when the ball bounces.
Drag Rate: How much speed is lost when the ball is in contact with the ground.
Ground Threshold: The height at which the ball is considered to be on the ground.
Time Interval: The duration of each time step in the simulation.
The ball starts from a height of 2.2 meters.
You'll use vectors to represent the ball's direction and speed. A vector is like an arrow indicating both direction and magnitude.
At each time step, you'll calculate the ball's movement and update its position.
You'll also consider forces like gravity and drag from the ground to update the ball's velocity.
If the ball bounces, its velocity and position change accordingly.
The simulation ends when the ball hits the ground and stops moving much.
Your task is to code this simulation and plot the following:
Distance traveled over time.
Ball's path from side view (x-position vs. z-position).
Height over time.
Ball's path from top-down view (x-position vs. y-position).
3D plot showing the ball's path.
Velocity over time.
Trajectory over time.
You'll use specific parameters for the simulation: bounce percentage of 0.7, drag rate of 0.01, ground threshold of 0.01, and time interval of 0.001. Try different values for speed, bearing, and trajectory to see where the ball stops, aiming for an x-value close to 20 meters. can you start with this code =====import matplotlib.pyplot as plt
import math
import astropy.coordinates
#Takes a 3D vector, and returns a tuple of the x, y, and z components
def spherical_to_components(magnitude, bearing, trajectory):
return astropy.coordinates.spherical_to_cartesian(magnitude, math.radians(trajectory), math.radians(bearing))
#Takes the x, y, and z components of a 3D vector, and returns a tuple of magnitude, bearing, and trajectory
def components_to_spherical(x, y, z):
magnitude, trajectory, bearing = astropy.coordinates.cartesian_to_spherical(x, y, z)
return magnitude, math.degrees(bearing.to_value()), math.degrees(trajectory.to_value())
#Takes two 3D vectors (each specified by magnitude, bearing, and trajectory) and returns a
#tuple representing the sum of the two vectors
def add_spherical_vectors(magnitude1, bearing1, trajectory1, magnitude2, bearing2, trajectory2):
x1, y1, z1= spherical_to_components(magnitude1, bearing1, trajectory1)
x2, y2, z2= spherical_to_components(magnitude2, bearing2, trajectory2)
return components_to_spherical(x1+ x2, y1+ y2, z1+==== and can you use the approach used in this code ========== import matplotlib.pyplot as plt
class SimpleDTSim:
def __init__(self):
# You might want to initialize the simulation here, but that means that you will initialize when the
# object is created, rather than on every simulation run
self.x =0
self.a =0
self.result =[]
def initialize(self, starting_x, a):
self.x = starting_x
self.a = a
self.result =[self.x]
def observe(self):
self.result.append(self.x)
def update(self):
self.x = self.a * self.x
def runsim(self, x, a, steps):
self.initialize(x, a)
for t in range(steps):
self.update()
self.observe()
plt.plot(self.result)
plt.show()
if __name__=='__main__':
sim = SimpleDTSim()
sim.runsim(1,1.1,30) or the one attached on the screenshot like i want the code to have the same def functions like, __init__, def initialize(self, def observe(self), def update(self), def runsim(self, if __name__=='__main__'.
 Imagine you're creating a computer program that simulates the motion of

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!