;; SUMMARY ;;;; A simulation of RADAR ;; COPYRIGHT & LICENSE ;;;; Copyright (C) 2005 James P. Steiner ;;;; Some Rights Reserved. ;;;; Creative Commons Attribution-NonCommercial-ShareAlike License v. 2.0. ;;;; Visit http://creativecommons.org/licenses/by-nc-sa/2.0/ for more information. ;; APPLET DIMENSIONS (width x height) ;;;; 510 x 400 ;; 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 ] breed [ waves ] breed [ antennas ] breed [ ufos ] breed [ scopes ] breed [ scope-markers ] waves-own [ time ; 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 ] antennas-own [ clock ] scope-markers-own [ time ] to startup setup end to setup ca set-default-shape waves "wave" set-default-shape antennas "antenna" set-default-shape ufos "ufo side" set-default-shape scope-markers "phosphor" antenna-setup scope-setup set envelope max-pycor set horizon antenna-y + .5 + 1 create-ufos 3 [ UFO-setup ] end to antenna-setup create-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 ; start position is on the left or right edge of the patch, ; not the patch center. This helps reduces the effect of the ; ufos "popping" onto the sky. set xcor plus-or-minus ( max-pxcor + .49 ) ; 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 + min-pycor - .5 set scope-radius max-pycor + antenna-y ; - .5 create-scopes 1 [ set scope self set size scope-radius * 2 setxy scope-x scope-y set heading 0 set color green set shape "scope-frame" stamp set shape "scope-sweep" ] end to go every (1 / 30) [ ufo-move antenna-sweep emit-pulse repeat world-height * ( 2.0 / resolution ) [ if any? waves [ wave-propigate monitor-receiver ] ] scope-fade tick ] end to wave-propigate ask waves [ ; advance clock timing the pulse set time time + resolution ; pulses are considered lost if they do not return in a certain time. ; but for display purposes, we will destroy pulses that are about to ; leave the screen, or are heading below the antenna ifelse abs ( ycor + dy * resolution ) >= max-pycor + .5 - resolution ;; off the top / bottom or abs ( xcor + dx * resolution ) >= max-pxcor + .5 - resolution ;; off the let / right or abs ( 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 <= .5 ] [ wave-bounce ] ] ] if rf-visible? [ display ] end to antenna-sweep ask antenna [ set clock clock + sweep-angle ifelse reciprocate? [ set antenna-heading -90 * ( sin clock ) ] [ set antenna-heading antenna-heading + sweep-angle if antenna-heading >= 180 [ set antenna-heading antenna-heading - 360 ] ] set heading antenna-heading set [heading] of scope antenna-heading ] end to emit-pulse if abs antenna-heading < 90 [ create-waves 1 [ set heading antenna-heading setxy antenna-x antenna-y set size 1 set bounced? false set time 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 let range 0 hide-turtle 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 time * .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 + speed * ufo-speed * dx ) >= abs goal-x [ ufo-setup ] set heading towardsxy-nowrap goal-x goal-y jump speed * ufo-speed ] end to wave-bounce set heading heading + 180 set color yellow set shape "wave-return" set bounced? true end @#$#@#$#@ GRAPHICS-WINDOW 154 10 505 382 5 5 31.0 1 10 1 1 1 0 0 0 1 -5 5 -5 5 1 1 1 ticks CC-WINDOW 5 396 514 491 Command Center 0 BUTTON 84 10 139 43 NIL go T 1 T OBSERVER NIL NIL NIL NIL BUTTON 18 10 73 43 reset setup NIL 1 T OBSERVER NIL NIL NIL NIL SLIDER 18 53 139 86 sweep-angle sweep-angle 1 10 6 1 1 NIL HORIZONTAL SWITCH 18 218 140 251 RF-visible? RF-visible? 1 1 -1000 SWITCH 18 97 139 130 reciprocate? reciprocate? 1 1 -1000 SLIDER 18 280 140 313 resolution resolution 0.1 1 0.5 0.05 1 NIL HORIZONTAL SLIDER 18 155 139 188 ufo-speed ufo-speed 1 10 2 1 1 NIL HORIZONTAL @#$#@#$#@ 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 -7500403 true true 150 5 40 250 150 205 260 250 antenna true 0 Polygon -7500403 false true 0 150 46 256 148 299 255 255 298 151 225 240 181 255 120 255 74 241 Polygon -7500403 false true 119 254 150 150 180 255 antenna2 true 0 Polygon -7500403 false true 0 150 46 256 148 299 255 255 298 151 225 240 181 255 120 255 74 241 Polygon -7500403 false true 119 254 150 150 180 255 phosphor false 5 Circle -10899396 true true 0 0 300 scope-frame false 5 Circle -16777216 true false 15 15 270 Circle -10899396 false true 15 15 270 Line -10899396 true 0 15 300 15 scope-sweep true 5 Line -10899396 true 150 15 150 150 ufo side false 0 Polygon -1 true false 0 150 15 180 60 210 120 225 180 225 240 210 285 180 300 150 300 135 285 120 240 105 195 105 150 105 105 105 60 105 15 120 0 135 Polygon -16777216 false false 105 105 60 105 15 120 0 135 0 150 15 180 60 210 120 225 180 225 240 210 285 180 300 150 300 135 285 120 240 105 210 105 Polygon -7500403 true true 60 131 90 161 135 176 165 176 210 161 240 131 225 101 195 71 150 60 105 71 75 101 Circle -16777216 false false 255 135 30 Circle -16777216 false false 180 180 30 Circle -16777216 false false 90 180 30 Circle -16777216 false false 15 135 30 Circle -7500403 true true 15 135 30 Circle -7500403 true true 90 180 30 Circle -7500403 true true 180 180 30 Circle -7500403 true true 255 135 30 Polygon -16777216 false false 150 59 105 70 75 100 60 130 90 160 135 175 165 175 210 160 240 130 225 100 195 70 wave true 2 Line -955883 true 15 119 150 180 Line -955883 true 150 180 285 120 wave-return true 2 Polygon -955883 true true 15 120 28 104 150 179 271 105 284 122 150 203 @#$#@#$#@ NetLogo 4.0.4 @#$#@#$#@ @#$#@#$#@ @#$#@#$#@ @#$#@#$#@ @#$#@#$#@ default 0.0 -0.2 0 0.0 1.0 0.0 1 1.0 0.0 0.2 0 0.0 1.0 link direction true 0 Line -7500403 true 150 150 90 180 Line -7500403 true 150 150 210 180 @#$#@#$#@