====== Project 1: Part B: River Boat Crossing ====== 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 ====== Project 1: Part B: River Boat Crossing Solution ====== 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 == Tutor Questions == * **Question**: How did you know you needed to modify the position update of the boat? * **Expected Answer**: ...the boat was not being dragged by the water... * **Question**: Of what use is the while loop? * **Expected Answer**: ...it allows you to increment to the position in the form $dx=v\,dt$... * **Question**: What analytical equation gives the same result as the computational position update? * **Expected Answer**: ...$x(t)=x_{0}+v_{0}t$ where $t$ is the total time elapsed... * **Question**: Can you add in the velocity vector of the boat with respect to the water $\vec{v}_{\rm b/w}$, the velocity vector of the boat with respect to the shore $\vec{v}_{\rm b/s}$, and the velocity vector of the water with respect to the shore $\vec{v}_{\rm w/s}$)? * **Expected Answer**: Adding in the relative velocity vectors is as easy as copying the MotionMap for the water with respect to the shore and making the necessary substitutions: 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) /* * **Question**: Say you want to release the boat $10\,{\rm m}$ to the right of the origin on the bottom shore. At what angle must you release the boat so that it passes to the **left** of the origin, with a distance of closest approach equal to $5\,{\rm m}$? * **Expected Answer**: The students should **not** do any algebra. They should guess and check using their code (use the graph along with honing the angle so that the dip approaches $5\,{\rm m}$) to figure out the angle. Should be $\theta\approx 141.5\,^{\circ}.$ */ ==Main Points:== * Comprehend what each line/variable represents physically. * The calculation loop is where quantities that change with time must go. * Quantities are updated through the form $a=a+da$. ==Common Difficulties:== * Time. Since the day is split in half, not all students will make serious progress on this half. * Syntax. Encourage Googling/just help with syntax mistakes. 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