n-body 2d gravity simulator in the works
g = 6.67384
list = []
def calc_grav(m1, m2, r):
f = g*((m1*m2)/r**2)
return f
class object:
lx = 0
ly = 0
lr = 0
lt = 0
mass = 0
vx = 0
vy = 0
vr = 0
vt = 0
def __init__(self, x, y, r, t, m, vx, vy, vr, vt):
self.lx = x
self.ly = y
self.lr = r
self.lt = t
self.mass = m
self.vx = vx
self.vy = vy
self.vr = vr
self.vt = vt
#generate two test objects
sun = object(0.0, 0.0, 0.0, 0.0, 1000.0, 0.0, 0.0, 0.0, 0.0)
pl1 = object(1000.0, 0.0, 1000.0, 0.0, 10.0, 0.0, 40.0, 40.0, 90.0)
pl2 = object(2000.0, 0.0, 2000.0, 0.0, 15.0, 0.0, 15.0, 15.0, 90.0)
list.append(sun)
list.append(pl1)
list.append(pl2)
#calculate distance
#insert method thing here
d = sun.lx - pl1.lx #temporary
#calculate gravitational force
i = 0
combos = []
for o in list:
j = 0
for p in list:
# print "%s, %s" % (i, j)
if i >= j:
pass
else:
print calc_grav(o.mass, p.mass, d)
j += 1
i += 1