Advertisement
Guest User

Untitled

a guest
Oct 24th, 2010
782
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.61 KB | None | 0 0
  1. # Import modules
  2. from __future__ import division
  3. from visual import *
  4. from visual.graph import *
  5. from math import *
  6.  
  7. # Define constants
  8. G = 6.67300*10**-11
  9. mass_star_1 = 2e30 #kg
  10. mass_star_2 = 1e30 #kg
  11. period = 15*24*60*60 #s
  12. radius_star_1 = 695500000
  13. radius_star_2 = 347750000
  14. seperation = radius_star_1*10
  15. dt = 30
  16.  
  17. # Some calculations
  18. central_mass = mass_star_1+mass_star_2
  19. distance_star_1 = (mass_star_2*seperation)/(mass_star_1+mass_star_2)
  20. distance_star_2 = (mass_star_1*seperation)/(mass_star_1+mass_star_2)
  21. omega = (2*math.pi)/period
  22. velocity_star_1=vector(0,-omega*distance_star_1,0)
  23. velocity_star_2=vector(0,omega*distance_star_2,0)
  24.  
  25. # Define planets, arrows, etc
  26. star_1 = sphere(pos=(-distance_star_1,0,0),mass=mass_star_1,radius=radius_star_1,color=color.blue, velocity=velocity_star_1)
  27. star_2 = sphere(pos=(distance_star_2,0,0),mass=mass_star_2,radius=radius_star_2,velocity=velocity_star_2)
  28. trail = curve(color=color.white)
  29. trail_2 = curve(color=color.red)
  30.  
  31. star_2.p = star_2.mass*star_2.velocity
  32. star_1.p = star_1.mass*star_1.velocity
  33.  
  34. while(1==1):
  35.     rate(500)
  36.     trail.append(pos=star_1.pos)
  37.     trail_2.append(pos=star_2.pos)
  38.    
  39.     # Update the force
  40.     distance = mag(star_1.pos-star_2.pos)
  41.     f_gravity_dir = norm(star_1.pos-star_2.pos)
  42.     f_gravity_mag = G*((star_2.mass*star_1.mass)/(distance**2))
  43.     f_gravity = f_gravity_dir*f_gravity_mag
  44.  
  45.     #print f_gravity
  46.    
  47.     # Update position and momentum
  48.     star_1.p = star_1.p + -f_gravity*dt
  49.     star_1.pos += (star_1.p/star_1.mass)*dt
  50.     star_2.p = star_2.p + f_gravity*dt
  51.     star_2.pos += (star_2.p/star_2.mass)*dt
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement