Advertisement
KittyMcSnuggles

Bouncingball with classes

Feb 19th, 2018
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.13 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, H0, velocity, CoR, angleThetha, timedelta):
  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(H0)
  16.          self.Distance.append(0)
  17.          while self.H_peak > 0.01:
  18.              self.Height.append(self.Height[-1] + vel_y*timedelta + 0.5*g*timedelta**2)
  19.              vel_y = vel_y - (g * timedelta)
  20.              self.D_cumil += vel_x*timedelta
  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.              
  28. ball1 = bounceBall()
  29. ball1.traceBounce(0, 5, 0.8, 45, .001)
  30. plt.plot(ball1.Distance,ball1.Height)
  31. plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement