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= … Continue reading 3-Body Simulation

N-body Simulation

What are N-body simulations? According to physics.princeton.edu, an N-body simulation replicates the motion of particles that interact with one another through some type of physical forces. These particles can range from celestial bodies to individual atoms or molecules, but for our code, we will define the particles as physical celestial bodies. Here is the code for Python: 3-Body Simulation: from visual import* R= 6.378e6 G=6.67e-11 … Continue reading N-body Simulation

Satellite Orbiting Earth Code

The code for satellite orbiting Earth is here:

Earth=sphere(pos=(0,0,0),
 radius=R,
 color=color.blue)

h=3.6e7

object_pos_init= vector(R,0,0)

object= sphere(pos=object_pos_init,
 radius=R/5,
 color=color.white,
 make_trail=True,
 trail_type="points",
 interval=10)

v_esc= sqrt(2*G*M/R)
 v0= v_esc
 v= vector(0,0.95*v0,0)

T_circ= (2*pi*(R+h)/v0)
 dt= 0.001*T_circ

F=vector(0,0,0)
 p= m*v
 r= (object.pos-Earth.pos)

t=0
 while t<10*T_circ:
 rate(1000)
 F= G*M*m/mag2(r)*(-norm(r))
 p= p+F*dt
 v= p/m
 object.pos = object.pos+v*dt
 r= (object.pos- Earth.pos)
 t= t+dt

sqrt(G*M/(h+R))

Here is how it runs:


Continue reading “Satellite Orbiting Earth Code”