Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import math
- import matplotlib.pyplot as plt
- g = 9.8
- class bounceBall(object):
- def __init__ (self):
- self.Height = []
- self.Distance = []
- self.D_cumil = 0
- self.H_peak = 1
- def traceBounce(self, velocity, CoR, angleThetha, Tdelta):
- thetha = angleThetha * math.pi/180 #converting to radians
- vel_y = velocity * math.sin(thetha)
- vel_x = velocity * math.cos(thetha)
- self.Height.append(0)
- self.Distance.append(0)
- while self.H_peak > 0.01:
- self.Height.append(self.Height[-1] + vel_y*Tdelta + 0.5*g*Tdelta**2)
- vel_y = vel_y - (g * Tdelta)
- self.D_cumil += vel_x*Tdelta
- self.Distance.append(self.D_cumil)
- if self.Height[-1] < 0.0001:
- vel_y = abs(vel_y*CoR)
- self.H_peak = vel_y / (2*g)
- # print(round(vel_y, 4), ",", round(self.Height[-1],4),",", round(self.H_peak,4))
- class bounceBallFull(bounceBall):
- CoD = 0.6
- def traceUpdate(self, velocity, CoR, angleThetha, Tdelta,):
- self.traceBounce(velocity, CoR, angleThetha, Tdelta)
- thetha = angleThetha * math.pi/180 #converting to radians
- vel_x = velocity * math.cos(thetha)
- print(vel_x)
- self.D_cumil = 0
- for i in range(len(self.Distance)):
- self.D_cumil += vel_x * Tdelta
- self.Distance[i] = self.D_cumil
- vel_x -= 0.6*(vel_x**0.5)*Tdelta
- #print(vel_x)
- inputH0 = 0
- inputV0 = 15
- inputCoR = 0.8
- inputAngle = 45
- inputTdelta = .001
- ball1 = bounceBall()
- ball1.traceBounce(inputV0, inputCoR, inputAngle, inputTdelta)
- x = ball1.Distance
- ball1a = bounceBallFull()
- ball1a.traceUpdate(inputV0, inputCoR, inputAngle, inputTdelta)
- plt.plot(ball1.Distance,ball1.Height)
- plt.show()
- plt.plot(ball1a.Distance,ball1a.Height)
- plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement