Inner Tube River Crossing
It is a hot summer day, and you are meeting your friends for a picnic lunch down by the river. When you get to the river, you discover you are on the wrong side, 20 meters from the picnic site. As an experienced inner tuber, you know that you can paddle your tube at a speed of 2.0 m/s. Additionally, you know the river moves westward at a speed of 1.5 m/s. Your friends have already started the grill and your meal will be ready in 15 seconds.
You have an app that lets you enter your velocity and the velocity of the river to determine your net velocity. For the following questions, calculate the answer and check your results with the code.
You would like to paddle across the river to get to your friends at the picnic site, but you don't want to hike back upriver once you paddle across.
After lunch, you decide to cool off by floating in the river. You want to chat with your friends on the shore while you float, so you need to paddle in such a way that you remain stationary.
Coding questions:
GlowScript 2.7 VPython get_library('https://rawgit.com/perlatmsu/physutil/master/js/physutil.js') #Window setup scene.range = 20 scene.width = 900 scene.height = 500 scene.background=vector(0,0.7,0.1) #Objects w=20 river = box(pos=vector(0,0,-1), length=200, height=w, width=1, color=color.blue, texture=textures.rough) #southshore = box(pos=vector(0,-100,0), length=600, height=50, width=1, color=vector(0.4,0.6, 0.2)) #northshore = box(pos=vector(0,100,0), length=600, height=50, width=1, color=vector(0.4,0.6, 0.2)) tube = ring(pos=vector(0,-w/2,0), axis=vector(0,0,180), radius=2, thickness=0.8, color=color.black, make_trail=False,) #target= text(text='X', align='center', color=color.red) 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 ) #Parameters and Initial Conditions tubes=0 riverv = vector(0.5,0,0) degrees=0 theta=degrees*pi/180 tubesx=tubes*sin(theta) tubesy=tubes*cos(theta) tubev=vec(tubesx,tubesy,0) scale=1.0 #Time and time step t = 0 tf = 3 dt = 0.01 tubeMotionMapx = MotionMap(tube, tf, 2, markerScale=scale, markerColor=color.blue, 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) ev = scene.waitfor('click') #Calculation Loop while tube.pos.y<w/2: rate(500) tube.pos = tube.pos + tubev*dt tube.pos = tube.pos + riverv*dt #Set up motion map relv = riverv + tubev tubeMotionMapr.update(t, relv) tubeMotionMapx.update(t, tubev) tubeMotionMapy.update(t, riverv) t = t + dt #determine angle angle=atan(mag(riverv)/mag(tubev))*(180/pi) #label print("time to cross =", t , "s") print("tube velocity=",mag(relv),"m/s at", angle, "degrees")
Link
Note: No lines of code are added, only modified on a problem-to-problem basis, and these are what are highlighted below.
GlowScript 2.7 VPython get_library('https://rawgit.com/perlatmsu/physutil/master/js/physutil.js') #Window setup scene.range = 20 scene.width = 900 scene.height = 500 scene.background=vector(0,0.7,0.1) #Objects w=20 #the width of the river river = box(pos=vector(0,0,-1), length=200, height=w, width=1, color=color.blue, texture=textures.rough) #southshore = box(pos=vector(0,-100,0), length=600, height=50, width=1, color=vector(0.4,0.6, 0.2)) #northshore = box(pos=vector(0,100,0), length=600, height=50, width=1, color=vector(0.4,0.6, 0.2)) tube = ring(pos=vector(0,-w/2,0), axis=vector(0,0,180), radius=2, thickness=0.8, color=color.black, make_trail=False,) #target= text(text='X', align='center', color=color.red) 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 ) #Parameters and Initial Conditions tubes=2 #the magnitude of the tube's velocity riverv = vector(-1.5,0,0) #the velocity of the river degrees=0 #the launch angle with respect to the shore theta=degrees*pi/180 tubesx=tubes*sin(theta) tubesy=tubes*cos(theta) tubev=vec(tubesx,tubesy,0) scale=1.0 #Time and time step t = 0 tf = 3 dt = 0.01 #adjusts the smoothness of motion tubeMotionMapx = MotionMap(tube, tf, 2, markerScale=scale, markerColor=color.blue, 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) ev = scene.waitfor('click') #Calculation Loop while tube.pos.y<w/2: rate(500) tube.pos = tube.pos + tubev*dt tube.pos = tube.pos + riverv*dt #Set up motion map relv = riverv + tubev tubeMotionMapr.update(t, relv) tubeMotionMapx.update(t, tubev) tubeMotionMapy.update(t, riverv) t = t + dt #determine angle angle=atan(mag(riverv)/mag(tubev))*(180/pi) #label print("time to cross =", t , "s") print("tube velocity=",mag(relv),"m/s at", angle, "degrees")