3-Body Simulation

3-Body Simulation that looks like a sword:

from visual import*
R= 6.378e6
G=6.67e-11

M1= 6.0e24
M2= M1
M3= M1

r1= vector(10*R,-10*R,0)
r2= vector(20*R,0,0)
r3= vector(0,0,0)

object1= sphere(pos=(r1),
 radius=R,
 color=color.white,
 make_trail=True,
 trail_type="points",
 interval=10)

object2= sphere(pos=(r2),
 radius=R,
 color=color.yellow,
 make_trail=True,
 trail_type="points",
 interval=10)

object3= sphere(pos=(r3),
 radius=R,
 color=color.red,
 make_trail=True,
 trail_type="points",
 interval=10)

v1= vector(0,0,0)
v2= v1
v3= v1

v_characteristic= sqrt(G*M1/mag(r1-r2))
T = mag(r1-r2)/v_characteristic
 
dt = 0.0001*T

p_object1=M1*v1
p_object2=M2*v2
p_object3=M3*v3

t=0
small= 0.5*R

while t< 50*T:
 rate(10000)

r12 = mag(r2- r1)
 r13 = mag(r3- r1)
 r23 = mag(r3- r2)
 
 if r12<small:
 r12=small

if r13<small:
 r13=small
 
 if r23<small:
 r23=small
 
 F12= G*M2*M1/(r12*r12)*norm(r1-r2)
 F21 = -F12
 F13= G*M3*M1/(r13*r13)*norm(r1-r3)
 F31 = -F13
 F23= G*M3*M2/(r23*r23)*norm(r2-r3)
 F32 = -F23

F1= F21+F31
 F2= F12+F32
 F3= F23+F13

p_object1=p_object1+F1*dt
 v1=p_object1/M1
 r1= r1+v1*dt
 object1.pos= r1

p_object2=p_object2+F2*dt
 v2=p_object2/M2
 r2= r2+v2*dt
 object2.pos= r2
 
 p_object3= p_object3+F3*dt
 v3=p_object3/M3
 r3= r3+v3*dt
 object3.pos= r3

t=t+dt

 

ezgif.com-video-to-gif.gif
Final Simulation

 

Advertisements

2 thoughts on “3-Body Simulation

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s