Advertisement
Guest User

donut orbit

a guest
Aug 9th, 2015
360
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.91 KB | None | 0 0
  1. from __future__ import division
  2. from visual import *
  3. import random
  4.  
  5. loci = [] # where the positions will be stored
  6.  
  7. # All lengths in m, all masses in kg, all times in seconds
  8.  
  9. N = 40000 # number of mass points (will decrease later)
  10. G = 6.7E-11 # universal gravitational constant
  11. r = 1e6 # radius of "pastry" part of donut
  12. R = 5e6 # distance from center of donut to line running
  13. # around the donut, through the centroid of the
  14. # actual donut part (a drawing would help here)
  15. C = 2*pi*R # circumference of donut through its pastry centroid
  16. A = pi*r**2 # cross sectional area of donut
  17. V = C*A # volume of donut, using Pappus' theorem
  18.  
  19. startpos = vector(5e6,5e6,0) # starting position of asteroid
  20. v = vector(-800,400,0) # starting velocity of asteroid
  21. mA = 100 # mass of asteroid
  22. p = mA*v # initial momentum of asteroid
  23. asteroid = sphere(pos=startpos, radius=1e5, color=color.cyan,
  24. make_trail=True)
  25.  
  26. dt = 100 # time increment
  27.  
  28. # Build the donut by cutting it out of a cube of random points.
  29. for i in range(N):
  30. rx = random.uniform(-R-r, R+r)
  31. ry = random.uniform(-R-r, R+r)
  32. rz = random.uniform(-R-r, R+r)
  33. radial = sqrt( rx**2 + rz**2 )
  34. centroidDistance2 = (R-radial)**2 + ry**2
  35. if centroidDistance2 < r**2:
  36. loci.append(vector(rx,ry,rz))
  37.  
  38. N = len(loci)
  39. donut = points(pos=loci, size=3, color=color.green)
  40.  
  41. m = 5500*V/N # mass of each point particle
  42. # assuming density of donut is the same as that of Earth
  43.  
  44. while True:
  45. rate(1000)
  46. F = vector(0,0,0)
  47. for i in range(N):
  48. relpos = asteroid.pos - loci[i]
  49. F = F - G*m*mA/relpos.mag**2 * relpos.norm()
  50. p = p + F*dt
  51. v = p/mA
  52. asteroid.pos = asteroid.pos + v*dt
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement