forked from ademirtas04/Cache-Money-Rapid-React-2022
-
Notifications
You must be signed in to change notification settings - Fork 0
/
PhysicsSimBothHubs.py
106 lines (75 loc) · 2.54 KB
/
PhysicsSimBothHubs.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
import math
import matplotlib.pyplot as plt
import numpy as np
### m's used throughout (m/s, m/s^2) + kilograms
### accel = force/mass
angle = int(input("Type in angle of Launch here: "))
### TBD ###
LaunchAngle = angle*math.pi/180 # radian
### ###
RPM = 0
BRadius = 0.12
BCircumference = BRadius*2*math.pi
distance = 5.34 # meter
TargetHeight = 2.64 # meter
TargetStart = distance-0.61 # meter
TargetEnd = TargetStart+1.22 # meter
SecondHeight = 1.04 # meter
SecondStart = distance+0.77 # meter
SecondEnd = distance-0.77 # meter
HeightOfRelease = 0 # meter
Time = 1 # seconds
BallMass = 0.27 #kg
BallWeight = BallMass*9.8
print(BallWeight)
BDragCoef = 0.57 # unitless, air's coefficient
BAreaExposed = BRadius**2 * math.pi # meter^2
AirDensity = 1.225 # kg/m^3
Velocity = 0 # meter/second
v = Velocity
smoothness = 0.1
DragAccel = (0.5*BDragCoef*BAreaExposed*AirDensity*(v**2))/0.27
### INIT ###
lToTest = []
inp = input("Type in value here: (or enter to run sim) ")
while inp:
lToTest.append(float(inp))
inp = input("Type in value here: (or enter to run sim) ")
HubRange = np.array([TargetStart,TargetEnd])
HubHeight = np.array([TargetHeight,TargetHeight])
SecRange = np.array([SecondStart,SecondEnd])
SecHeight = np.array([SecondHeight,SecondHeight])
plt.plot(0,0,'o')
plt.plot([0,10],[0,0])
plt.plot(HubRange,HubHeight,'r')
plt.plot(SecRange,SecHeight,'g')
plt.plot([SecRange[0],SecRange[0]],[SecHeight[0],0],'g')
plt.plot([SecRange[1],SecRange[1]],[SecHeight[1],0],'g')
plt.plot([HubRange[0],HubRange[0]],[SecHeight[0],HubHeight[0]],'r')
plt.plot([HubRange[1],HubRange[1]],[SecHeight[1],HubHeight[1]],'r')
plt.plot(0,10)
for v in lToTest:
Times = [smoothness*x for x in range(0,80)]
Xpos = 0
Ypos = HeightOfRelease
cacheX = [0]
cacheY = [HeightOfRelease]
Xvel = v*math.cos(LaunchAngle)
Yvel = v*math.sin(LaunchAngle)
for time in Times:
Yvel = v*math.sin(LaunchAngle) - 9.8*time
if Yvel > 0:
Yvel = Yvel - smoothness*(0.5*BDragCoef*BAreaExposed*AirDensity*(Yvel*Yvel))/0.27
if Yvel < 0:
Yvel = Yvel + smoothness*(0.5*BDragCoef*BAreaExposed*AirDensity*(Yvel*Yvel))/0.27
Ypos += Yvel*smoothness
cacheY.append(Ypos)
Xvel = v*math.cos(LaunchAngle)
if Xvel > 0:
Xvel = Xvel - smoothness*(0.5*BDragCoef*BAreaExposed*AirDensity*(Xvel*Xvel))/0.27
if Xvel < 0:
Xvel = Xvel + smoothness*(0.5*BDragCoef*BAreaExposed*AirDensity*(Xvel*Xvel))/0.27
Xpos += Xvel*smoothness
cacheX.append(Xpos)
cacheY = [x for x in cacheY if x > -10]
plt.plot(cacheX[:len(cacheY)],cacheY)