Advertisement
TheLazarusProject

Bounc

Feb 20th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.92 KB | None | 0 0
  1. import math
  2. import matplotlib.pyplot as plt
  3. g = 9.8
  4.  
  5. class bounceBall(object):
  6.      def __init__ (self):
  7.          self.Height = []
  8.          self.Distance = []
  9.          self.D_cumil = 0
  10.          self.H_peak = 1
  11.      def traceBounce(self, velocity, CoR, angleThetha, Tdelta):
  12.          thetha = angleThetha * math.pi/180 #converting to radians
  13.          vel_y = velocity * math.sin(thetha)
  14.          vel_x = velocity * math.cos(thetha)
  15.          self.Height.append(0)
  16.          self.Distance.append(0)
  17.          while self.H_peak > 0.01:
  18.              self.Height.append(self.Height[-1] + vel_y*Tdelta + 0.5*g*Tdelta**2)
  19.              vel_y = vel_y - (g * Tdelta)
  20.              self.D_cumil += vel_x*Tdelta
  21.              self.Distance.append(self.D_cumil)
  22.              if self.Height[-1] < 0.0001:
  23.                      vel_y = abs(vel_y*CoR)
  24.                      self.H_peak = vel_y / (2*g)
  25. #             print(round(vel_y, 4), ",", round(self.Height[-1],4),",", round(self.H_peak,4))
  26.              
  27. class bounceBallFull(bounceBall):
  28.     CoD = 0.6
  29.     def traceUpdate(self, velocity, CoR, angleThetha, Tdelta,):
  30.         self.traceBounce(velocity, CoR, angleThetha, Tdelta)
  31.         thetha = angleThetha * math.pi/180 #converting to radians
  32.         vel_x = velocity * math.cos(thetha)
  33.         print(vel_x)
  34.         self.D_cumil = 0
  35.         for i in range(len(self.Distance)):
  36.             self.D_cumil += vel_x * Tdelta
  37.             self.Distance[i] = self.D_cumil
  38.             vel_x -= 0.6*(vel_x**0.5)*Tdelta
  39.             #print(vel_x)
  40.  
  41.  
  42.                    
  43. inputH0 = 0
  44. inputV0 = 15
  45. inputCoR = 0.8
  46. inputAngle = 45
  47. inputTdelta = .001
  48.  
  49. ball1 = bounceBall()
  50. ball1.traceBounce(inputV0, inputCoR, inputAngle, inputTdelta)
  51.  
  52. x = ball1.Distance
  53.  
  54. ball1a = bounceBallFull()
  55. ball1a.traceUpdate(inputV0, inputCoR, inputAngle, inputTdelta)
  56. plt.plot(ball1.Distance,ball1.Height)
  57. plt.show()
  58. plt.plot(ball1a.Distance,ball1a.Height)
  59. plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement