Your company, Zevo Simulations, tasks you with the completion of a “projected trajectory simulator” for your boat crossing the river. You are not sure why this would be necessary, but you decide to proceed with the project. This simulator must display the motion of the boat crossing the river, with respect to the shore. The previous design team has already done the majority of the work, but they mysteriously disappeared without completing it… The head of the division suggests you complete the project as quickly as possible!
https://www.glowscript.org/#/user/pcubed/folder/incompleteprograms/program/RiverCrossing
Running the original code, we should notice that even though the boat is being directed perpendicularly to the shore, it should be carried sideways by the water. This ought to prompt students to add in the velocity of the boat relative to the shore and to modify the position update of the boat:
vboatshore = vboatwater + vwatershore boat.pos = boat.pos + vboatshore*dt
vboatshoreMotionMap = MotionMap(boat, tf, 15, markerScale=0.5, labelMarkerOrder=False, markerColor=color.white) vwatershoreMotionMap = MotionMap(boat, tf, 15, markerScale=0.5, labelMarkerOrder=False, markerColor=color.blue)
vboatshoreMotionMap.update(t, vboatshore) vwatershoreMotionMap.update(t, vwatershore)
GlowScript 2.9 VPython get_library('https://cdn.rawgit.com/PERLMSU/physutil/master/js/physutil.js') scene.width = 900 scene.height = 500 scene.range = 20 #Objects W = 20 origin = cylinder(pos=vector(0,0,0), axis=vector(0,0,5), radius=0.2, color=color.red) water = box(pos=vector(-30,0,0), height=W, width=0, length=200, color=color.blue, opacity=0.4) boat = sphere(pos=vector(0,-W/2,0), radius=0.4, color=color.white) #Parameters and Initial Conditions sboatwater = 10 thetaindegrees = 90 thetainrad = thetaindegrees*2*pi/360 dirboat = vector(cos(thetainrad),sin(thetainrad),0) vboatwater = sboatwater*dirboat vwatershore = vector(5,0,0) vboatshore = vboatwater + vwatershore #Time and time step t=0 tf=10 dt=0.01 #MotionMap/Graph vboatwaterMotionMap = MotionMap(boat, tf, 15, markerScale=0.5, labelMarkerOrder=False, markerColor=color.orange) vboatshoreMotionMap = MotionMap(boat, tf, 15, markerScale=0.5, labelMarkerOrder=False, markerColor=color.orange) vwatershoreMotionMap = MotionMap(boat, tf, 15, markerScale=0.5, labelMarkerOrder=False, markerColor=color.orange) #Calculation Loop while boat.pos.y <= W/2: rate(100) water.pos = water.pos + vwatershore*dt boat.pos = boat.pos + vboatshore*dt vboatwaterMotionMap.update(t, vboatwater) vboatshoreMotionMap.update(t, vboatshore) vwatershoreMotionMap.update(t, vwatershore) t = t + dt
https://www.glowscript.org/#/user/pcubed/folder/solutions/program/RiverCrossingSolution