-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathtest.py
More file actions
30 lines (24 loc) · 678 Bytes
/
test.py
File metadata and controls
30 lines (24 loc) · 678 Bytes
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
alpha = 1000000000000
scaleFactor = (1-alpha) / (1 + alpha)
v1 = 0.0
v2 = -1.0
#print("Momentum = ", v1 + alpha*v2)
piCount = 0
while((v2 < v1) or (v1 < 0)):
piCount += 1
#print("Momentum = ", v1 + alpha*v2)
#print("Energy * 2 = ", v1**2 + (v2**2)*alpha)
if (v1 == 0):
v2 = scaleFactor
v1 = (v2 - 1)
#print("Momentum = ", v1 + alpha*v2)
# First hit
elif (v1 < 0):
v1 = - v1
#print("New momentum = ", v1 + alpha*v2)
# Ball hits wall
else:
# General case, small ball catches up
v1, v2 = v1 - (v1 - v2)*((2*alpha) / (alpha + 1)), v1 - (v1-v2)*((alpha - 1) / (alpha + 1))
#print("Momentum = ", v1 + alpha*v2)
print(piCount)