Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
repository:inner_tube_river_crossing [2021/02/18 19:46]
porcaro1 [Activity]
repository:inner_tube_river_crossing [2021/02/18 19:54] (current)
porcaro1 [Answer Key]
Line 152: Line 152:
   - They never appear because these prompts only show once the while loop is completed. Since the tube never crosses the river, the while loop never stops   - They never appear because these prompts only show once the while loop is completed. Since the tube never crosses the river, the while loop never stops
 ===Code=== ===Code===
-[[https://​www.glowscript.org/#/​user/​jbennett/folder/Private/program/relativemotionstudentversion ​| Link]] +[[https://​www.glowscript.org/#/​user/​porcaro1/folder/RepositoryPrograms/program/InnerTubeRiverCrossing-Solution ​| Link]] ​\\ 
-Note: No lines of code are added, only modified on a problem-to-problem basis, and these are what are highlighted below.+**Note**: No lines of code are added, only modified on a problem-to-problem basis, and these are what are highlighted below.
 <code Python [enable_line_numbers="​true",​ highlight_lines_extra="​12,​23,​24,​25,​37"​]>​ <code Python [enable_line_numbers="​true",​ highlight_lines_extra="​12,​23,​24,​25,​37"​]>​
 GlowScript 2.7 VPython GlowScript 2.7 VPython
 get_library('​https://​rawgit.com/​perlatmsu/​physutil/​master/​js/​physutil.js'​) get_library('​https://​rawgit.com/​perlatmsu/​physutil/​master/​js/​physutil.js'​)
 + 
 #Window setup #Window setup
 scene.range = 20 scene.range = 20
Line 163: Line 163:
 scene.height = 500 scene.height = 500
 scene.background=vector(0,​0.7,​0.1) scene.background=vector(0,​0.7,​0.1)
- +  
 + 
 #Objects #Objects
 w=20   #the width of the river w=20   #the width of the river
Line 174: Line 174:
 label(pos=vec(tube.pos.x,​w/​2,​0),​ text='​picnic site', color=color.black ) label(pos=vec(tube.pos.x,​w/​2,​0),​ text='​picnic site', color=color.black )
 label(pos=vec(-10,​-10,​0),​ text='​click to run', color=color.black ) label(pos=vec(-10,​-10,​0),​ text='​click to run', color=color.black )
- +  
 + 
 #Parameters and Initial Conditions #Parameters and Initial Conditions
-tubes=  #the magnitude of the tube's velocity +tubes=  #the magnitude of the tube's velocity 
-riverv = vector(0.5,​0,​0) ​  #the velocity of the river+riverv = vector(-1.5,​0,​0) ​  #the velocity of the river
 degrees=0 ​  #the launch angle with respect to the shore degrees=0 ​  #the launch angle with respect to the shore
 theta=degrees*pi/​180 theta=degrees*pi/​180
Line 185: Line 185:
 tubev=vec(tubesx,​tubesy,​0) tubev=vec(tubesx,​tubesy,​0)
 scale=1.0 scale=1.0
- +  
- +  
 + 
 #Time and time step #Time and time step
 t = 0 t = 0
 tf = 3 tf = 3
 dt = 0.01   #​adjusts the smoothness of motion dt = 0.01   #​adjusts the smoothness of motion
 + 
 tubeMotionMapx = MotionMap(tube,​ tf, 2, markerScale=scale,​ markerColor=color.blue,​ labelMarkerOrder=False) tubeMotionMapx = MotionMap(tube,​ tf, 2, markerScale=scale,​ markerColor=color.blue,​ labelMarkerOrder=False)
 tubeMotionMapy= MotionMap(tube,​ tf, 2, markerScale=scale,​ markerColer=color.red,​ labelMarkerOrder=False,​ ) tubeMotionMapy= MotionMap(tube,​ tf, 2, markerScale=scale,​ markerColer=color.red,​ labelMarkerOrder=False,​ )
 tubeMotionMapr= MotionMap(tube,​ tf, 2, markerScale=scale,​ markerColor=color.green,​ labelMarkerOrder=False) tubeMotionMapr= MotionMap(tube,​ tf, 2, markerScale=scale,​ markerColor=color.green,​ labelMarkerOrder=False)
 + 
 ev = scene.waitfor('​click'​) ev = scene.waitfor('​click'​)
 + 
 #​Calculation Loop #​Calculation Loop
 while tube.pos.y<​w/​2: ​ while tube.pos.y<​w/​2: ​
Line 205: Line 205:
     tube.pos = tube.pos + tubev*dt     tube.pos = tube.pos + tubev*dt
     tube.pos = tube.pos + riverv*dt     tube.pos = tube.pos + riverv*dt
 + 
 #Set up motion map #Set up motion map
     relv = riverv + tubev     relv = riverv + tubev
Line 211: Line 211:
     tubeMotionMapx.update(t,​ tubev)     tubeMotionMapx.update(t,​ tubev)
     tubeMotionMapy.update(t,​ riverv)     tubeMotionMapy.update(t,​ riverv)
- +  
 + 
     t = t + dt     t = t + dt
-    ​+ 
 #determine angle #determine angle
 angle=atan(mag(riverv)/​mag(tubev))*(180/​pi) angle=atan(mag(riverv)/​mag(tubev))*(180/​pi)
 + 
 #label #label
 print("​time to cross =", t , "​s"​) print("​time to cross =", t , "​s"​)
  • repository/inner_tube_river_crossing.1613677608.txt.gz
  • Last modified: 2021/02/18 19:46
  • by porcaro1