;;;; Summary ;; An enhanced 3d wave machine ;; COPYRIGHT & LICENSE ;;;; Copyright (C) 2005 James P. Steiner ;;;; Based on prior work (C) Uri Wilensky. See code for details. ;;;; 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. ;;; globals [ rows cols max-peak max-pit curr-peak curr-pit dist-fact time drive-zpos setup-2d? old-freq old-3d old-x-d-point old-y-d-point old-width old-boundary old-pers pers-exp spacing ; all-nodes drive-nodes free-nodes edge-nodes grid-edge xtheta-control ytheta-control oldmx oldmy ] breeds [ nodes rays ] nodes-own [ x1 y1 z1 ;; computed xcor ycor zpos xpos ypos zvel ;; zcor component of velocity xvel yvel xorig yorig zorig p phi theta node-type link-set link-set-2 link-count link-count-2 i zpos-sum zpos-count neighbor xpos-sum xpos-count ypos-sum ypos-count row col vxcor vycor vzcor ] rays-own [ source target col row link-set vxcor vycor ] to setup locals [ ] no-display ca clear-output set setup-2d? not three-d? set rows grid-size set cols grid-size set grid-edge (grid-size - 1) / 2 set dist-fact 1 / ( sqrt 2 ) cct-nodes grid-size * grid-size ;; create enough nodes to fill a square grid [ hide-turtle set color base-color set node-type 1 ; free-node ;; line up the turtles so that turtle who + 1 is on your right, ;; turtle who - 1 is on your left, turtle who + columns, ;; is beneath you, and turtle who - columns is above you. set row int ( who / grid-size ) set col (who mod grid-size) set xorig (0.0 - .5 * cols + col ) set yorig (0.0 - .5 * rows + row ) set zorig 0 set zvel 0 set zpos 0 set xpos xorig set ypos yorig set time 0 set shape "small-pix" ] define-node-links define-nodes define-rays ; for wire-frame view set constrained? true go display end to define-nodes define-node-types define-node-sets end to define-node-types define-free-nodes define-drive-nodes define-edge-nodes end to define-node-links ask nodes ;; each turtle has an agent set that points to it's neighbor turtles [ without-interruption [ set link-set nodes with [ ( ( row = row-of myself ) and ( abs ( col - col-of myself ) = 1 ) ) or ( ( col = col-of myself ) and ( abs ( row - row-of myself ) = 1 ) ) ] set link-count count link-set ] ] end to get-peak locals [new-peak new-pit] set new-peak max values-from turtles [zpos] if new-peak > max-peak [ set max-peak new-peak ] set new-pit min values-from turtles [zpos] set-current-plot-pen "peak" plot new-peak set-current-plot-pen "pit" plot new-pit end to define-node-sets set free-nodes turtles with [ node-type = 1 ] set drive-nodes turtles with [ node-type = 2 ] set edge-nodes turtles with [ node-type = 3 ] end to define-free-nodes ask turtles [ set node-type 1 ; free-node ] end to define-edge-nodes ;; observer procedure ;; color edges of wave "membrane" blue ask turtles with [ row = 0 or row = grid-size - 1 or col = 0 or col = grid-size - 1 ] [ set node-type 3 ; edge set color edge-color ] end to define-drive-nodes ;;observer procedure ;; tell turtles that they are part of the the drive point ifelse circular-dp? [ ask turtles with [ sqrt( (row - rows * .5 - x-d-point + .5) ^ 2 + (col - cols * .5 - y-d-point + .5) ^ 2 ) + 1 <= width ] [ set node-type 2 ; drive-plate set color green ] ] [ ask turtles with [ row >= ( rows * .5 + x-d-point - width - 1 ) and row <= ( rows * .5 + x-d-point + width ) and col >= ( cols * .5 + y-d-point - width - 1 ) and col <= ( cols * .5 + y-d-point + width ) ] [ set node-type 2 ; drive-plate set color green ] ] end to define-rays ; for wire-frame view ask nodes [ if any? link-set with [ (col - 1) = col-of myself ] [ hatch 1 [ set breed rays set shape "ray" set source myself set target one-of (link-set) with [ (col - 1) = col-of myself ] ] ] if any? link-set with [ (row - 1) = row-of myself ] [ hatch 1 [ set breed rays set shape "ray" set source myself set target one-of (link-set) with [ (row - 1) = row-of myself ] ] ] ] end to go if move? [ set time time + speed set drive-zpos (amplitude * grid-size * (sin (time))) ] drive-force project if not any? free-nodes [stop] end to-report dist-3d [ b a ] locals [ ax ay az bx by bz dist ] set ax xpos-of a set ay ypos-of a set az zpos-of a set bx xpos-of b set by ypos-of b set bz zpos-of b set dist sqrt ((ax - bx) ^ 2 + (ay - by) ^ 2 + (az - bz) ^ 2 ) ifelse dist = 0 [ report 0.000001 ] [ report dist ] end to drive-force ;; turtle procedure ;; propagates the wave to neighboring turtles ifelse connected? [ ask drive-nodes [ set zpos drive-zpos set ypos yorig set xpos xorig ] ] [ ask drive-nodes [ accelerate ] ] ifelse constrained? [ ask edge-nodes [ set zvel 0 set xvel 0 set yvel 0 if xpos != xorig [set xpos xpos + ( xorig - xpos ) * .1] if ypos != yorig [set ypos ypos + ( yorig - ypos ) * .1] if zpos != zorig [set zpos zpos + ( zorig - zpos ) * .1] ] ] [ ask edge-nodes [ accelerate ] ] ask free-nodes [ accelerate ] end to color-nodes locals [ allz maxz minz ] set allz values-from nodes [ zpos ] set minz abs min allz set maxz abs max allz ifelse minz > maxz [ set maxz minz ] [ set minz maxz ] set minz 0 - minz if minz = maxz [ set minz minz - 1 set maxz maxz + 1 ] set minz minz * 1.1 set maxz maxz * 1.1 ask free-nodes [ set color scale-color base-color zpos minz maxz ] ask edge-nodes [ set color edge-color ] ; scale-color edge-color zpos minz maxz show-turtle ] ask drive-nodes [ set color drive-color ] ; scale-color green zpos minz maxz show-turtle ] end to accelerate set link-count count link-set ;; add up inter-node forces set xpos-sum ( sum ( map [ ( ( ?1 - xpos) + ( 0 - ?2 + xorig ) ) ] ( values-from link-set [ xpos ]) ( values-from link-set [ xorig ]) ; ( values-from link-set [ (dist-3d myself self) ] ) ) ) / link-count set ypos-sum ( sum ( map [ ( ( ?1 - ypos) + ( 0 - ?2 + yorig ) ) ] ( values-from link-set [ ypos ] ) ( values-from link-set [ yorig ] ) ; ( values-from link-set [ ( dist-3d myself self ) ] ) ) ) / link-count set zpos-sum ( sum ( map [ ( ( ?1 - zpos ) + ( 0 - ?2 + zorig ) ) ] ( values-from link-set [ zpos ] ) ( values-from link-set [ zorig ] ) ; ( values-from link-set [ ( dist-3d myself self ) ] ) ) ) / link-count ;; apply acceleration due to inter-atom forces set zvel zvel + (k * zpos-sum ) set xvel xvel + (k * xpos-sum ) set yvel yvel + (k * ypos-sum ) ;; apply (de)acceleration due to viscosity set zvel zvel * (1 - friction) set xvel xvel * (1 - friction) set yvel yvel * (1 - friction) ;; apply deelleration due to extreme occeclation ;if zvel > grid-size ;[ set xvel xvel * ( 1 - ( (log xvel 10) * .1 )) ; set yvel yvel * ( 1 - ( (log yvel 10) * .1 )) ; set zvel zvel * ( 1 - ( (log zvel 10) * .1 )) ;] ;; apply acceleration due to gravity set zvel zvel - gravity set zpos (zpos + zvel) set xpos (xpos + xvel) set ypos (ypos + yvel) end to project ifelse three-d? [ set setup-2d? false project-3d ] [ if any? rays with [ not hidden? ] [ ask rays [ hide-turtle ] ] project-2d ] color-nodes end to project-3d set theta-x (theta-x + delta-tx) mod 360 set theta-z (theta-z + delta-tz) mod 360 ;if perspective != old-pers ;[ set old-pers perspective ; set pers-exp 10 ^ perspective ;] monitor-mouse ask nodes [ set x1 xpos set y1 ypos set z1 zpos rotate-on-z-axis rotate-on-x-axis set vzcor y1 - (nearness * .01 * screen-edge-y) set vxcor ((0 - x1) * ( 1 - ( (vzcor) / (vzcor + perspective )))) / eye set vycor ((0 - z1) * ( 1 - ( (vzcor) / (vzcor + perspective )))) / eye + (altitude * .01 * screen-edge-y) ] ask nodes [ ifelse abs vycor > screen-edge-y or abs vxcor > screen-edge-x or vzcor < 0 - perspective [ hide-turtle ] [ set xcor vxcor set ycor vycor show-turtle ] ] ask rays [ ifelse (hidden?-of source) [ ifelse (hidden?-of target) [ hide-turtle ] [ setxy (vxcor-of target) (vycor-of target) set heading towardsxy-nowrap (vxcor-of source) (vycor-of source) set size distancexy-nowrap (vxcor-of source) (vycor-of source) set color color-of target if hidden? [ show-turtle ] ] ] [ setxy (vxcor-of source) (vycor-of source) set heading towardsxy-nowrap (vxcor-of target) (vycor-of target) set size distancexy-nowrap (vxcor-of target) (vycor-of target) set color color-of target if hidden? [ show-turtle ] ] ;; don't draw turtles that "wrap" around the edge of the ;; screen; we need no-display, above, because otherwise ;; the turtle would briefly be drawn before the hide-turtle ;; command had a chance to take effect ] end to project-2d ;; this is only needed for if the user turns three-d? off ;; while the model is running color-nodes ask nodes [ setxy xpos ypos show-turtle ] end to rotate-on-z-axis ; rotate nodes on z axis set p sqrt((x1 * x1) + (y1 * y1) + (z1 * z1)) set phi (atan sqrt((x1 * x1) + (y1 * y1)) z1) set theta (atan y1 x1) set theta theta + (theta-z mod 360) ; incrementing the angle to simulate rotation set y1 (p * (sin phi) * (sin theta)) set x1 (p * (sin phi) * (cos theta)) ; z is not changed by change in theta ; set z1 (p * (cos phi)) end to rotate-on-x-axis set p sqrt ( ( x1 ^ 2 ) + ( y1 ^ 2 ) + ( z1 ^ 2 ) ) set phi ( atan sqrt ( ( y1 ^ 2 ) + ( z1 ^ 2 ) ) x1 ) set theta ( atan z1 y1 ) set theta theta + ( theta-x mod 360 ) ; incrementing the angle to simulate rotation set y1 ( p * ( sin phi ) * ( sin theta ) ) set z1 ( p * ( sin phi ) * ( cos theta ) ) set x1 ( p * ( cos phi ) ) end to disintegrate ; end to event-manager every .1 [ if x-d-point != old-x-d-point or y-d-point != old-y-d-point or width != old-width [ print "Change Drive Point" set old-x-d-point x-d-point set old-y-d-point y-d-point set old-width width define-nodes ] ] end to monitor-mouse locals [ mx my ] ifelse mouse-down? [ set mx mouse-xcor set my mouse-ycor if oldmx = -9999 [ set oldmx mx set oldmy my ] if oldmx != mx or oldmy != my [ set theta-x (theta-x - (oldmy - my ) ) mod 360 set theta-z (theta-z - (oldmx - mx ) ) mod 360 set oldmx mx set oldmy my ] ] [ set oldmx -9999 ] if shape-of one-of rays != edge-shape [ ask rays [ set shape edge-shape ] ] end ; ***NetLogo Model Copyright Notice*** ; This model was created as part of the project: CONNECTED MATHEMATICS: ; MAKING SENSE OF COMPLEX PHENOMENA THROUGH BUILDING OBJECT-BASED PARALLEL ; MODELS (OBPML) ; The project gratefully acknowledges the support of the National Science ; Foundation (Applications of Advanced Technologies Program) -- grant numbers ; RED #9552950 and REC #9632612. ; Copyright 1996 by Uri Wilensky. All rights reserved. ; converted to NetLogo from StarLogoT, 2001. ; Permission to use, modify or redistribute this model is hereby granted, ; provided that both of the following requirements are followed: ; a) this copyright notice is included. ; b) this model will not be redistributed for profit without permission ; from Uri Wilensky. ; Contact Uri Wilensky for appropriate licenses for redistribution for ; profit. ; To refer to this model in academic publications, please use: ; Wilensky, U. (1996). NetLogo Wave Machine model. ; http://ccl.northwestern.edu/netlogo/models/WaveMachine. ; Center for Connected Learning and Computer-Based Modeling, ; Northwestern University, Evanston, IL. ; ***End NetLogo Model Copyright Notice*** @#$#@#$#@ GRAPHICS-WINDOW 557 92 1572 628 100 50 5.0 1 10 1 1 1 0 0 0 1 CC-WINDOW 5 642 1581 737 Command Center 0 BUTTON 14 193 291 241 NIL setup NIL 1 T OBSERVER T NIL BUTTON 331 355 549 411 go no-display\ngo\ndisplay T 1 T OBSERVER NIL NIL SLIDER 329 105 516 138 k k 0.0 0.99 0.81 0.01 1 NIL SLIDER 106 116 198 149 x-d-point x-d-point -20 20 6 1 1 NIL SLIDER 200 116 292 149 y-d-point y-d-point -20 20 -6 1 1 NIL SWITCH 57 514 148 547 three-d? three-d? 0 1 -1000 SLIDER 12 115 104 148 width width 0 10 2 1 1 NIL SLIDER 331 239 434 272 amplitude amplitude 0.0 1 0.02 0.01 1 % SLIDER 436 239 538 272 speed speed 0.0 50 30.0 0.1 1 NIL SLIDER 329 141 518 174 friction friction 0.01 0.1 0.06 0.01 1 NIL SLIDER 8 295 100 328 theta-x theta-x 0.0 359 100.0 1.0 1 NIL SWITCH 436 274 526 307 move? move? 0 1 -1000 SLIDER 6 348 98 381 delta-tx delta-tx 0 22.5 0.0 0.1 1 NIL SLIDER 330 176 520 209 gravity gravity -0.1 0.1 0.0 0.01 1 NIL SWITCH 331 274 435 307 connected? connected? 0 1 -1000 SLIDER 329 52 421 85 base-color base-color 4 134 4 10 1 NIL BUTTON 181 521 287 554 NIL disintegrate T 1 T OBSERVER T NIL SLIDER 424 52 516 85 edge-color edge-color 6 136 6 10 1 NIL BUTTON 170 151 225 184 center set x-d-point 0\nset y-d-point 0 NIL 1 T OBSERVER T NIL SWITCH 55 151 164 184 circular-dp? circular-dp? 0 1 -1000 SLIDER 104 295 196 328 theta-z theta-z 0.0 359.9 46.5 0.1 1 NIL SLIDER 100 349 192 382 delta-tz delta-tz 0 22.5 0.0 0.1 1 NIL SLIDER 8 403 100 436 eye eye 0.01 2 0.06 0.01 1 NIL SLIDER 103 404 202 437 perspective perspective 1 100 22 1 1 NIL SLIDER 12 46 197 79 grid-size grid-size 5 100 35 2 1 NIL SWITCH 436 309 546 342 constrained? constrained? 0 1 -1000 TEXTBOX 12 10 162 40 Grid properties-Adjust before pressing Setup. TEXTBOX 14 82 86 113 Drive-point properties TEXTBOX 330 15 519 44 Run-time properties-can be adjusted while the model is running. TEXTBOX 352 85 502 103 Physics properties TEXTBOX 345 220 495 238 Drive-point properties TEXTBOX 13 274 163 292 View controls TEXTBOX 9 330 115 348 Auto-rotate controls TEXTBOX 9 384 159 402 Perspective controls TEXTBOX 332 312 423 342 binds/unbinds the edge of the sheet TEXTBOX 313 10 328 241 | | | | | | | | | | | | | | | TEXTBOX 6 249 318 279 _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ TEXTBOX 333 421 549 473 Note: if drive point is disconnected and sheed edge is unconstrained and gravity is on, the sheet may fall off the view! SLIDER 8 438 178 471 nearness nearness -100 100 -28 1 1 % SLIDER 6 472 178 505 altitude altitude -100 100 67 1 1 NIL CHOOSER 358 474 496 519 edge-shape edge-shape "arrow" "ray" "ray 3" "ray v" "fat ray" "mid-point" "node" "pixel" 3 SLIDER 519 52 611 85 drive-color drive-color 7 137 7 10 1 NIL @#$#@#$#@ WHAT IS IT? ----------- This project simulates wave motion within a membrane. It is based on the original Wave Machine from the NetLogo Model library. The four edges of a membrane are (optionaly) fixed to a frame. A selected green rectangular or circular area is connected to a plate that moves up and down, exhibiting sinusoidal motion. Rather than just showing the nodes of the membrane, extra turtles are used to show the edges connecting the nodes of the membrane. Also, the points of the membrane are free to move in three dimentions. HOW TO USE IT ------------- Controls that must be set before SETUP: The GRID-SIZE slider controls the number of "nodes" in the membrane. The number of turtles is the GRID-SIZE squared. This is the resolution of the membrane. The WIDTH slider controls the size of the driving plate (the number of green turtles) The X-D-POINT slider controls the x-coordinate of the center of the driving force. The Y-D-POINT slider controls the y-coordinate of the center of the driving force. Controls of membrane properties: The FRICTION slider controls the amount of friction or attenuation in the membrane. The K slider controls the stiffness, really the force exerted on a turtle by a unit deflection difference between the turtle and its four neighbors. Controls of the driving force: The FREQUENCY slider controls the frequency at which the green selected area of the membrane (the driving force) moves up and down. The AMPLITUDE slider controls the maximum height of the green area of the membrane. Move? starts or stops the plate Connected? connects or disconnects the plate from the membrane. if the plate is disconnected, the membrane moves freely. Controls for viewing: The THREE-D? switch controls the view point of the projection. OFF is for the top view (2-D looking down), and ON gives a rotateable perpective view. Theta-x is the amount the view is rotated in the x axis Theta-z is the amount the view is rotated in the z axis. Delta-tx is the amount that theta-x is automatically incremented. Delta-tz is the amount that theta-z is automatically incremented. RUNNING THE MODEL ----------------- Click the SETUP button to set up the membrane. Click GO to make the selected area of the membrane (the green turtles) begin moving up and down. THINGS TO NOTICE ---------------- The membrane is made up of lines of turtles. Each turtle acts as it were connected to its four neighboring turtles by springs. In the prior model, turtles move only up and down -- the force's direction IS only up and down. The greater the distance between a turtle and its neighbors, the stronger the force. In this version, turtles can move in any direction. Forces along the x, y, and z axis are added together to obtain the net force the turtles neighbors exert on it. (A force of zero would be all turtles right on top of each other) When the selected area of the membrane (the green turtles) moves up, they "pull" the turtles which are their neighbors, which in turn pull up the turtles which are their neighbors, and so on. In that way, a wave moves within the membrane. When the wave reaches the edges of the membrane (the blue turtles), the wave is reflected back to the center of the membrane. The green turtles (within the selected area) continue to put more energy into the membrane. If there were no friction in the membrane, the waves in the membrane would keep getting bigger and bigger. To render the membrane to the edge of the window, the edges "rays" use a trick. Since they are drawn from a source to a target, if the source or the target was off the screen, they couldn't be drawn. So instead, what the rays do is change context, and always draw from the on-screen end-point out, rather than always drawing from one end-point or the other. They point towards the virtual, rather than the actual, endpoint. THINGS TO TRY ------------- Try different membranes. Soft membranes have smaller stiffness values and hard membranes have larger stiffness values. Try different driving forces, or try changing the frequency or amplitude. It is very interesting to change the size and the position of the driving force to see symmetrical and asymmetrical wave motions. Try to create a "standing wave," in which some points in the membrane do not move at all. Try releaseing the membrane border, see how the constrained border affects the behavior of the membrane. Change the value of gravity. How does gravity affect the membrane? @#$#@#$#@ default true 0 Polygon -7500403 true true 150 5 40 250 150 205 260 250 arrow true 1 Line -2674135 true 150 150 150 -150 Line -2674135 true 135 15 150 0 Line -2674135 true 150 0 165 15 fat ray true 1 Rectangle -2674135 true true 135 -165 165 165 mid-point true 1 Circle -2674135 true true 105 -45 90 node true 1 Circle -2674135 true true 105 105 90 pixel false 0 Rectangle -7500403 true true 14 15 285 285 ray true 1 Line -2674135 true 150 150 150 -150 ray 3 true 1 Line -2674135 true 225 150 225 -150 Line -2674135 true 75 150 75 -150 Line -2674135 true 150 150 150 -150 ray v true 1 Line -2674135 true 135 150 150 -150 Line -2674135 true 165 150 150 -150 small-pix true 1 Rectangle -2674135 true true 90 91 211 210 @#$#@#$#@ NetLogo 3.0.2 @#$#@#$#@ @#$#@#$#@ @#$#@#$#@ @#$#@#$#@