-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path3body.py
More file actions
69 lines (49 loc) · 1.37 KB
/
3body.py
File metadata and controls
69 lines (49 loc) · 1.37 KB
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
class Body:
def __init__(self, x, y, ax, ay, m):
self.cor = [x, y]
self.acc = [ax, ay]
self.mass = m
self.oldx = [x]
self.oldy = [y]
def update(self, x, y):
self.oldx.append(x)
self.oldy.append(y)
def getXpos():
return self.oldx
def getYpos():
return self.oldy
def r(b1, b2):
a = b1.cor
b = b2.cor
summa = 0
for i in range(len(a)):
v = a[i] - b[i]
summa += v**2
return summa**0.5
def a(b1, other):
G = 1
mass = b1.mass
deldelx = 0
deldely = 0
print("start body: ", b1.cor)
for b in other:
if b1 != b:
rad = r(b1, b)
print("body: ", b.cor ,"rad: ", rad)
vx = (b1.cor[0] - b.cor[0])/(rad**3)
vx *= b.mass
vx *= -1
vy = (b1.cor[1] - b.cor[1])/(rad**3)
vy *= b.mass
vy *= -1
print(vx, vy)
deldelx += vx * G
deldely += vy * G
#print(deldelx, deldely)
return 0
p1 = Body(-0.97000436, 0.24208753, 0.4662036850, 0.4323657300, 1)
p2 = Body(0, 0, -0.933240737, -0.86473146, 1)
p3 = Body(0.97000436, -0.24208753, 0.4662036850, 0.4323657300, 1)
bodies = [p1, p2]
#print(r(p1, p2))
print(a(p1, bodies))