; add model procedures here globals [ antenna ; refers to the turtle acting as the emitter and receiver antenna-x antenna-y ; the x/y coordinates of the antenna antenna-heading ; the heading of the antenna, in terms ; of -180 to +180 degrees. antenna-direction ; the direction of rotation of the antenna scope ; refers to the turtles acting as the display scope scope-x scope-y ; holds the x/y coordinates of the display scope scope-radius ; holds the radius of the display scope horizon ; the lowest that a UFO can fly envelope ; the highest that a UFO can fly ] breeds [ waves antennas ufos scopes scope-markers ] waves-own [ ticks ; used to measure the travel of the wave bounced? ; helps the wave remember that is has bounced off something ; used to prevent our simplified waves ; from bouncing multiple times ] ufos-own [ goal-x goal-y ; where the ufo is heading speed ; relative speed of the ufo ] scope-markers-own [ ticks ] to setup ca set-default-shape waves "wave" set-default-shape antennas "antenna" set-default-shape ufos "ufo" set-default-shape scope-markers "phosphor" antenna-setup scope-setup set envelope screen-edge-y set horizon antenna-y + .5 + 1 create-custom-ufos 3 [ UFO-setup ] end to antenna-setup create-custom-antennas 1 [ set antenna self set antenna-direction 1 set antenna-x 0 set antenna-y 1 setxy antenna-x antenna-y set size 1 ] end to ufo-setup ; start on left or right edge set xcor plus-or-minus ( screen-edge-x + .5 ) ; start somewhere between horizon and upper limit of sky set ycor envelope - random-float ( envelope - horizon ) ; head for opposite edge set goal-x 0 - xcor ; at some other altitude set goal-y envelope - random-float ( envelope - horizon ) ; point towards the goal set heading towardsxy-nowrap goal-x goal-y ;set the size set size 1 ; set the speed and color set speed .005 + random-float .005 set color random 13 * 10 + 15 end to-report plus-or-minus [ value ] ; randomly reports either +value or -value report value * (((random 2) * 2) - 1) ; explanation of "(((random 2) * 2) - 1)" ; Operation: Yields: ; random 2 -> 0 or 1 ; * 2 -> 0 * 2 = 0 or 1 * 2 = 2 ; - 1 -> 0 - 1 = -1 or 2 - 1 = 1 ; thus, returns -1 or +1 end to scope-setup set scope-x 0 set scope-y 0 - screen-edge-y - .5 set scope-radius screen-edge-y + antenna-y ; - .5 create-custom-scopes 1 [ set scope self set shape "scope" set size scope-radius * 2 setxy scope-x scope-y set heading 0 set color green ] end to go ufo-move antenna-sweep emit-pulse repeat screen-size-y * ( 2.0 / resolution ) [ if any waves [ wave-propigate monitor-receiver ] ] scope-fade end to wave-propigate ask waves [ ; advance clock timing the pulse set ticks ticks + resolution ; pulses are considered lost if they do not return in a certain time. ; but for display purposes, we will destroy pulses that leave the screen, ; or are below the antenna ifelse ycor + dy * resolution > screen-edge-y + .4 ;; off the top or abs ( xcor + dx * resolution ) > screen-edge-x + .4 ;; off the side or ycor + dy <= ( antenna-y - 1 ) ;; below the antenna [ die ] [ ; wave moves forward jump resolution ; if wave has not yet hit something and there's a UFO in the way... if not bounced? and any ufos with [ distance myself <= resolution ] [ wave-bounce ] ] ] if rf-visible? [ display ] end to antenna-sweep set antenna-heading antenna-heading + sweep-angle * antenna-direction ifelse reciprocate? [ if abs antenna-heading > 90 [ set antenna-heading 90 * antenna-direction set antenna-direction antenna-direction * -1 ] ] [ if abs antenna-heading >= 180 [ set antenna-heading -180 * antenna-direction + antenna-direction ] ] ; antenna-dir 0 - antenna-dir set heading-of scope antenna-heading set heading-of antenna antenna-heading end to emit-pulse if abs antenna-heading < 90 [ create-custom-waves 1 [ set heading antenna-heading setxy antenna-x antenna-y set size 1 set bounced? false set ticks 0 set color white set hidden? not rf-visible? ] ] end to monitor-receiver ask antenna [ ask waves with [ bounced? and distance myself <= .5 ] [ scope-activate ] ] end to scope-activate ; converts the incoming wave to mark the scope ; marks the scope based on the travel-time of the wave locals [ range ] hideturtle set breed scope-markers set shape "phosphor" ; move to center of scope setxy scope-x scope-y set color green + 1 ; reverse heading set heading ( heading + 180 ) mod 360 ; calulate distance, and scale for scope viewing. set range ticks * .5 if range > scope-radius [ set range scope-radius ] jump range show-turtle end to scope-fade ask scope-markers [ ifelse color > green - 4 [ set color (color - resolution * .09) set size size - resolution * .05 ] [ die ] ] end to ufo-move ask ufos [ if abs (xcor + dx ) > abs goal-x [ ufo-setup ] set heading towardsxy-nowrap goal-x goal-y fd speed * ufo-speed ] end to wave-bounce set heading heading + 180 set color yellow set shape "wave-return" set bounced? true end @#$#@#$#@ GRAPHICS-WINDOW 201 10 552 382 5 5 31.0 1 10 1 1 1 CC-WINDOW 18 327 190 388 Command Center BUTTON 84 10 139 43 NIL go T 1 T OBSERVER BUTTON 18 10 73 43 NIL setup NIL 1 T OBSERVER SLIDER 18 53 139 86 sweep-angle sweep-angle 1 10 3 1 1 NIL SWITCH 18 218 140 251 RF-visible? RF-visible? 1 1 -1000 SWITCH 18 97 139 130 reciprocate? reciprocate? 0 1 -1000 SLIDER 18 280 140 313 resolution resolution 0.1 1 0.5 0.05 1 NIL SLIDER 18 155 139 188 ufo-speed ufo-speed 1 10 2 1 1 NIL @#$#@#$#@ WHAT IS IT? ----------- This model is a demonstration of how RADAR works. RADAR is an acronym for RAdio Detection And Ranging RADAR works by measuring the time it takes for a directed radio pulse to bounce off a distant object and return to the source. The return time is directly proportional to the distance of the object related to the speed of light. ( d = t/2c ) A real radar pulse travels at the speed of light. Our radar is not so fast, but still works pretty well. Sonor works in a similar fashion, but uses sound waves instead of radio waves. HOW TO USE IT ------------- Click Setup. Click Go. CONTROLS -------- sweep-angle How many degrees the antenna turns between pulses. reciprocate? Whether the antenna sweeps in a circle, or goes back-and-forth. ufo-speed How fast the ufos move RF-visible? Makes the radar waves visible to the naked eye resolution adjusts the fineness of the simulation. In practical terms, higher resolution means the wave takes more steps to traverse the sky. THINGS TO TRY ------------- Adjust the sweep-angle, ufo-speed, and resolution. Note how these variables affect the success of radar at finding the UFOs. Use the slow-down slider to slow down time. Now you can follow the radio waves as they propigate out, bounce back, and are received again. EXTENDING THE MODEL ------------------- How about doppler radar? NETLOGO FEATURES ---------------- To get the sweeping single line of the scope, a custom turtle shape of a circle with a line from the center is used. Since patch resolution is not important, but large shapes are, the model uses few patches and a large patch size. @#$#@#$#@ default true 0 Polygon -7566196 true true 150 5 40 250 150 205 260 250 antenna true 0 Polygon -7566196 false true 0 150 46 256 148 299 255 255 298 151 225 240 181 255 120 255 74 241 Polygon -7566196 false true 119 254 150 150 180 255 antenna2 true 0 Polygon -7566196 false true 0 150 46 256 148 299 255 255 298 151 225 240 181 255 120 255 74 241 Polygon -7566196 false true 119 254 150 150 180 255 phosphor true 5 Circle -11352576 true true 16 16 268 scope true 5 Circle -11352576 false true 3 3 295 Line -11352576 true 150 9 150 150 ufo false 4 Rectangle -256 false true 15 135 285 180 Rectangle -256 false true 60 120 239 194 Rectangle -256 false true 104 104 197 211 wave true 2 Line -44544 true 15 119 150 180 Line -44544 true 150 180 285 120 wave-return true 2 Polygon -44544 true true 15 120 28 104 150 179 271 105 284 122 150 203 @#$#@#$#@ NetLogo 2.0alpha1 (Rev B) @#$#@#$#@ @#$#@#$#@ @#$#@#$#@