idk if i posted this here but i need this
import math
g = 6.67384
list = []
gravity = []
thetas = []
def calc_grav(m1, m2, r):
f = g*((m1*m2)/r**2)
return f
def calc_rt(x1, y1, x2, y2):
x = x2 - x1
y = y2 - y1
c = math.sqrt(x**2 + y**2)
theta = math.degrees(math.acos(x/c))
return c, theta
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 gravitational force
i = 0
for o in list:
j = 0
for p in list:
# print "%s, %s" % (i, j)
if i >= j:
pass
else:
d = calc_rt(o.lx, o.ly, p.lx, p.ly)
gravity.append(calc_grav(o.mass, p.mass, d[0])) #do i really need arrays yet?
# thetas.append(d[1])
j += 1
i += 1
print gravity
#print thetas
#--TO DO--
#calculate magnitude of force ^^^^^^^^^^^^^^^
#calculate direction of force ^
#calculate x, y of the force
#add to initial motion vector (x, y)
#store this final vector so that it can be used next iteration, and multiply the vector by the timestep to get the new location of all objects
#add config file for custom simulations
#add output file