orbital-simulator


Information

Created with NetLogo version NetLogo 4.0.4
Running with NetLogoLite.jar version 404.


WHAT IS IT?


-------
A model that draws massiv objects orbiting around a more massive object. The model uses simple orbital physics to calcualte the paths of the orbiting objects.
The positions of the objects are stored in a table. When the objects current position is similar to a recorded position, the object's orbit is marked "stable" -- In other words, the object is not going to crash into the planet, or shoot off into distance space.
When "move-planet" is on, the planet is tugged by the orbiting bodies, making it more difficult to obtain stable orbits.

Procedures

NetLogo Version: NetLogo 4.0.4

globals
[ the-planet
  g
  cd?
  ; ticks
  all-stable?
  stable-ticks
]

breed [ planets a_planet ]
breed [ objects an_object ]

planets-own
[ mass
  vx vy
  radius
]

objects-own
[ mass
  ax
  ay
  vx
  vy
  xx
  yy
  fuel
  
  ph
  dlist
  stable-orbit?
  base-color
  
]

to startup setup end

to setup
   ca
   set g 6.67259e-11
   
   create-planets 1
   [ set the-planet self
     home
     set shape "planet"
     set radius 6.378 ;; KKM
     set size 20
     set mass 5.9742e21  ;; tonnes
     set vx random-float .1 
     set vy random-float .1
     
   ]
   create-objects 10
   [ make-ship pd
   ]
end

to go
   if move-planet? [ move-planet ]
   
   set cd? false
   move-objects
   if cd? [ cd ]
   ;if ticks <= 0 [ tick-advance frame-skip]
   ;tick
   ;ifelse all-stable? [ set stable-ticks stable-ticks + 1 ]
   ;[ set stable-ticks 0 ]
   ;if stop-when-stable? and stable-ticks >= 360
   ;[ tick stop ]
   tick
end



to move-planet
ask planets
     [ let mx mean [ xx ] of objects - xcor
       let my mean [ yy ] of objects - ycor
       set heading atan mx my
       set vx vx * .99 + dx * .0001
       set vy vy * .99 + dy * .0001
       set xcor xcor + vx
       set ycor ycor + vy
     ]     
end     

to move-objects
   set all-stable? true
   ask objects
   [ ;if d < 10 * s [ escape ]
     let f [ f-list ] of planets
     let fx mean map [ first ? ] f
     let fy mean map [ last ? ] f
     set ax fx
     set ay fy
     set vx vx + ax
     set vy vy + ay
     set xx xx + vx
     set yy yy + vy
     let d distance the-planet 
     let r [radius] of the-planet 
     if d <= r [ make-ship ]
     ifelse visible-x xx and visible-y yy
     [ set xcor xx set ycor yy
       if hidden? [ show-turtle ]
     ]
     [ if not hidden?
       [ hide-turtle
         set vx 0
         set vy 0
       ]
     ]
     if vx != 0 or vy != 0
     [ set heading atan vx vy 
       ifelse abs ( subtract-headings ph floor heading) > .0001
       [ set ph floor heading
         let rd item ph dlist
         let nd 10 * floor (d * .1)
         let new-so? (rd = nd)
         ifelse new-so?
         [ ]
         [ set dlist replace-item ph dlist nd 
           set all-stable? false
         ]
         if stable-orbit? != new-so?
         [ set stable-orbit? new-so?
           ifelse stable-orbit?
           [ if shape != "sat-stable" [ set shape "sat-stable"  ] ]
           [ if shape != "sat" [ set shape "sat"         ] 
           ]
         ]
       ]
       [ let tph towards the-planet
         if abs (subtract-headings heading tph) < 5
         [ set shape "sat-collide"
         ]
       ]
     ]
   ]
end
   
to-report f-list
   let scale .00000000000002
   let d distance myself
   let t towards myself
   let f -1 * ( (g * (mass * scale) * ([mass] of myself  * scale)) / ( d * d ) )
   let fx f * sin t
   let fy f * cos t
   report list fx fy
end    

to-report visible-x [ x ]
   report (x > min-pxcor and x < max-pxcor)
end

to-report visible-y [ y ]
   report (y > min-pycor and y < max-pycor)
end

to make-ship
     let pm pen-mode
     pu
     set dlist n-values 360 [ 0 ]
     set ph 0     
     set shape "sat"
     set size 20
     set mass 1.0e18  ;; tonnes
     let r (((random 2 )* 2 )- 1) * ( max-pxcor * .5 + random-float .5 * max-pxcor )
     set heading random-float 360
     jump r
     set heading random-float 360
     set ph heading
     set vx dx
     set vy dy
     set vx  vx * 1
     set vy  vy * 1
     set xx xcor
     set yy ycor
     set pen-mode pm
     set base-color color
     set cd? true
end

to escape
   let h atan vx vy
   let t towards the-planet
   let eh subtract-headings h t
   ifelse eh > 0 [ set eh 135 ] [set eh -135]
   set eh t + eh
   set vx vx + .0001 * sin eh 
   set vy vy + .0001 * cos eh
end

                    


Download Link

View or download the complete model file (to download: right-click, save-link-as):
-- Download orbital-simulator --