globals [ cx ;; x-cor of the circle's center cy ;; y-cor of the circle's center f0x ;; x-cor of focus 0 (for hyperbola) f0y ;; y-cor of focus 0 (for hyperbola) f1x ;; x-cor of focus 1 (for hyperbola) f1y ;; y-cor of focus 1 (for hyperbola) state ;; flag to alternate between different values with WatchMouse m ;; slope divided by 10 ] turtles-own [ dist ;; distance from 'goal' in current state old-dist ;; distance from 'goal' in last state intx ;; x-intersection (for parabola) inty ;; y-intersection (for parabola) diff ;; modified distance to x and y intercepts in current state old-diff ;; modified distance to x and y intercepts in last state ] to startup ca cg set cx 0 set cy 0 set f0x 0 set f0y 0 set f1x 0 set f1y 0 set state 0 end to setup startup ask patches [ if (patch-pos 0 0) [set pcolor white] ] crt num-turtles ask turtles [ set color green fd random-float 100 if (pos cx cy) [set pcolor white] ] end to move-turtles ifelse directrix? [parab] [hyperb] end to hyperb ;;turtle procedure set old-dist dist ;;distance between two foci at const set dist (abs ((distancexy-nowrap f0x f0y) - (distancexy-nowrap f1x f1y))) ;;find location to stop ifelse ((int dist) = const) [stop] [ifelse ((dist < old-dist) and (dist > const)) [fd 1] [ifelse ((dist > old-dist) and (dist < const)) [fd 1] [rt random-float 360 fd 1] ] ] end to parab ;; turtle procedure set old-diff diff set dist (distancexy-nowrap f0x f0y) set intx xcor set inty f1y ;;distance from directrix set diff ((distancexy-nowrap intx inty) - dist) ;; locate position to stop ifelse ((abs diff) < 1) [ stop] [ifelse ((abs diff) > (abs old-diff)) [rt random-float 360 fd 1] [fd 1] ] end to move-focus-directrix ;;resets foci for hyperbola or resets focus and directrix for parabola ;; checks for the mouse down and moves the foci or directrix accordingly if (mouse-down?) [ ask patches [ set pcolor black ifelse (state = 0) [ set f0x round mouse-xcor set f0y round mouse-ycor set state 1 ][ set f1x round mouse-xcor set f1y round mouse-ycor set state 0 ] ifelse directrix? [ if (patch-pos f0x f0y) or (pycor = f1y) [set pcolor white] ][ if (patch-pos f0x f0y) or (patch-pos f1x f1y) [set pcolor white] ] ] ] end to-report pos [x y] ;; turtle procedure report (xcor = x and ycor = y) end to-report patch-pos [x y] ;;patch procedure report (pxcor = x and pycor = y) end ; *** NetLogo Model Copyright Notice *** ; ; This model was originally 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 1998 by Uri Wilensky. All rights reserved. ; ; 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. ; ; This model was converted to NetLogo (and was changed in the process to ; be an alternate version of the model) as part of the project: ; PARTICIPATORY SIMULATIONS: NETWORK-BASED DESIGN FOR SYSTEMS LEARNING IN ; CLASSROOMS. The project gratefully acknowledges the support of the ; National Science Foundation (REPP program) -- grant number REC #9814682. ; Converted from StarLogoT to NetLogo, 2001. Updated 2002. ; ; To refer to this model in academic publications, please use: ; Wilensky, U. (1998). NetLogo ConicSection-Para-Hyper model. ; http://ccl.northwestern.edu/netlogo/models/ConicSection-Para-Hyper. ; Center for Connected Learning and Computer-Based Modeling, ; Northwestern University, Evanston, IL. ; ; In other publications, please use: ; Copyright 1998 by Uri Wilensky. All rights reserved. See ; http://ccl.northwestern.edu/netlogo/models/ConicSection-Para-Hyper ; for terms of use. ; ; *** End of NetLogo Model Copyright Notice *** @#$#@#$#@ GRAPHICS-WINDOW 242 10 621 410 20 20 9.0 1 10 1 1 1 CC-WINDOW 7 293 235 447 Command Center BUTTON 15 71 112 104 setup setup NIL 1 T OBSERVER T BUTTON 123 71 229 104 move-turtles move-turtles T 1 T TURTLE T SLIDER 11 195 233 228 const const 0 20 6 1 1 NIL BUTTON 40 110 189 143 move-focus-directrix move-focus-directrix T 1 T OBSERVER T SWITCH 66 159 184 192 directrix? directrix? 0 1 -1000 SLIDER 11 232 233 265 num-turtles num-turtles 0 100 50 1 1 NIL @#$#@#$#@ WHAT IS IT? ----------- The model displays two basic conic sections: hyperbolas and parabolas. The figures are generated behaviorally as opposed to algebraically - the turtles attempt to behave like points on the specified shape. The partner to this model is called 'Conic Sections-circle&ellipse.' A parabola is the set of all points that are the same distance from a point (focus) and a line (directrix). A hyperbola is based on the same idea as is a parabola except that it is reflected over the directrix. The ancient Greeks discovered that each conic section can be found by taking a cross section of one or two cones with their points pointing toward each other. A circle results from taking a slice that is perpendicular to the axis, while an ellipse results from taking a slice of one cone that is not perpendicular to the axis. Similiarly, a parabola results from a cross section that passes through one cone in a vertical fashion, such that the plane of the cut is parallel to one face. A hyperbola results from a vertical section that passes through both cones. The turtles use feedback to make decisions about how they behave. They set out in random directions, and then they receive information as to whether or not they are getting closer to where they want to be. If they are getting closer, they continue moving forward in the direction they are going. If they are moving farther away, they set out in a new random direction. This process is akin to the children's game of "Hot & Cold", in which players are told whether they are getting "hotter" or "colder" in relation to a hidden goal. HOW TO USE IT ------------- *Hyperbolas: -Select the number of turtles with the NUM-TURTLES slider. -Press SETUP. -Make sure the DIRECTRIX? switch is set to OFF. -Press the MOVE-FOCUS-DIRECTRIX button to select the two foci as for ellipses. -Press MOVE-TURTLES. Adjust CONSTANT and pick new foci as desired. *Parabolas: -Select the number of turtles with the NUM-TURTLES slider. -Press SETUP. -Make sure the DIRECTRIX? switch is set to TRUE. -Press the MOVE-FOCUS-DIRECTRIX button. After this, select first the position of the focus, and then a point through which the directrix will pass. -Press MOVE-TURTLES. -Note that CONSTANT has no effect on the parabola. THINGS TO NOTICE ---------------- When forming a hyperbola, turtles adjust their positions from two user-defined foci so that the difference between their distances from the foci attains a value of CONSTANT. When forming a parabola, turtles move to an equal distance from the directrix to the focus. THINGS TO TRY ------------- Adjust the slope of the parabola's directrix or the value of CONSTANT for the hyperbola while the turtles are still moving. See how they react to the changes in their environment. You may be able to get a better feeling for the turtles' behavior if only a few turtles are on-screen at one time. Try setting num to a small value (like 16 or 1), and watching the turtles. Both of these conic sections can be observed by shining a flashlight at a cone and looking at its shadow. Can you figure out at what angles the cone must be held? EXTENDING THE MODEL ------------------- Look at the StarLogoT model 'emergent-circle'. Watch how the turtles react with each other- something that is missing from 'Conic Sections'. Implement this emergent behavior for one or all of the conics in this project. NETLOGO FEATURES ---------------- Like more traditional programming languages (e.g. C++), NetLogo can have functions that report a value to the caller. The command used is called 'report' -- it has one input, the value to be reported. Look at the function 'pos'. It takes two inputs, x and y, and reports a boolean. CREDITS AND REFERENCES ---------------------- To refer to this model in academic publications, please use: Wilensky, U. (1998). NetLogo ConicSection-Para-Hyper model. http://ccl.northwestern.edu/netlogo/models/ConicSection-Para-Hyper. Center for Connected Learning and Computer-Based Modeling, Northwestern University, Evanston, IL. In other publications, please use: Copyright 1998 by Uri Wilensky. All rights reserved. See http://ccl.northwestern.edu/netlogo/models/ConicSection-Para-Hyper for terms of use. @#$#@#$#@ default true 0 Polygon -7566196 true true 150 5 40 250 150 205 260 250 arrow true 0 Polygon -7566196 true true 150 0 0 150 105 150 105 293 195 293 195 150 300 150 box true 0 Polygon -7566196 true true 45 255 255 255 255 45 45 45 circle true 0 Circle -7566196 true true 35 35 230 person false 0 Circle -7566196 true true 155 20 63 Rectangle -7566196 true true 158 79 217 164 Polygon -7566196 true true 158 81 110 129 131 143 158 109 165 110 Polygon -7566196 true true 216 83 267 123 248 143 215 107 Polygon -7566196 true true 167 163 145 234 183 234 183 163 Polygon -7566196 true true 195 163 195 233 227 233 206 159 spacecraft true 0 Polygon -7566196 true true 150 0 180 135 255 255 225 240 150 180 75 240 45 255 120 135 thin-arrow true 0 Polygon -7566196 true true 150 0 0 150 120 150 120 293 180 293 180 150 300 150 truck-down false 0 Polygon -7566196 true true 225 30 225 270 120 270 105 210 60 180 45 30 105 60 105 30 Polygon -8716033 true false 195 75 195 120 240 120 240 75 Polygon -8716033 true false 195 225 195 180 240 180 240 225 truck-left false 0 Polygon -7566196 true true 120 135 225 135 225 210 75 210 75 165 105 165 Polygon -8716033 true false 90 210 105 225 120 210 Polygon -8716033 true false 180 210 195 225 210 210 truck-right false 0 Polygon -7566196 true true 180 135 75 135 75 210 225 210 225 165 195 165 Polygon -8716033 true false 210 210 195 225 180 210 Polygon -8716033 true false 120 210 105 225 90 210 turtle true 0 Polygon -7566196 true true 138 75 162 75 165 105 225 105 225 142 195 135 195 187 225 195 225 225 195 217 195 202 105 202 105 217 75 225 75 195 105 187 105 135 75 142 75 105 135 105 @#$#@#$#@ NetLogo 2.0beta4 @#$#@#$#@ set num-turtles 100 setup set f0x 12 set f0y 10 set f1x 0 set f1y -13 ask patches [ ifelse (patch-pos f0x f0y) or (pycor = f1y) [set pcolor white] [set pcolor black] ] ask turtles [ repeat 25 [ move-turtles ] ] @#$#@#$#@ @#$#@#$#@