This is an old revision of the document!


Triathlete's Dilemma

Activity Information

Learning Goals

  • Analyze constant motion
  • Use geometry/trigonometry to determine distance
  • Analyze graphs
  • Examine effect of changing variables in a problem situation

Prior Knowledge Required

  • 2-D vectors
  • Pythagorean Theorem

Code Manipulation

  • Modify existing code
  • Copy and paste code
  • Create and use while loops
  • Translate physical quantities and equations into code

—-

Activity

Handout

Triathlete's Dilemma

You are a triathlete in the water and you need to get to your bike parked in a rack at a specific location on the shore in the shortest amount of time possible. You can run faster than you can swim. Do you swim directly to the shore, then run to your bike? Do you swim to a point closer to your bike, then run? How do you solve this dilemma? Here are the specific parameters:

  • The shoreline is linear and coincident with the x-axis
  • You are in the water at the following coordinates, labeled “Start”: (-50,120)
  • Your bike is parked at these coordinates, labelled “End: (100,-50)
  • You are a well-conditioned athlete and can swim at 2 m/s and run at 9 m/s

Your goal is to determine the optimal x-coordinate shore point to swim towards to get to your bike in the shortest possible time. Using the starter code below, decide what you need in order to compute the sim time and corresponding run time. You are probably aware that there is no reason to swim away from your bike or beyond your bike, so limit your shore point analysis to the x-axis range established by the initial x-coordinates of the Start and End locations. As a starting point, you should consider every half meter point along the shoreline.

You will examine your total time results graphically. Notice in the code, that the graph commands are already there, but the graph won't be generated until you produce some data. Your “while” loop should include a calculation for the swim time, run time, and total time for each half-meter position along the beach. Your graph will plot corresponding shore positions versus total time.

Extension questions:

  1. How could you modify your code to get greater precision in your answer? What specific changes would you make?
  2. What happens to the critical shore point if you swim faster?
  3. What happens if you change this situation? Suppose it's a sea lion in the water trying to get to the bike! Reverse your original speeds—Make the swim speed 9 m/s and the run speed 2 m/s. What is the new shore point for the fastest travel time now?

Code

  1. GlowScript 2.8 VPython
  2.  
  3. #scene attributes
  4. scene.width = 750
  5. scene.height = 568
  6. scene.fov = .3
  7. scene.align = "left"
  8.  
  9. ## Objects for the lake, beach, start and end points, and labels
  10. lake = box(pos=vector(0,100,0), size=vector(300,200,2), axis=vector(1,0,0), color=color.cyan, texture=textures.rough)
  11. beach = box(pos=vector(0,-50,0), size=vector(300,100,2), axis=vector(1,0,0), color=color.yellow, texture=textures.stucco)
  12. start = sphere(pos=vec(-50,120,0), radius=10, color=color.green)
  13. end = sphere(pos=vec(100,-50,0), radius=10, color=color.red)
  14. starttext = text(pos=vec(-65,130,0), text='Start', depth=2, height=10, color=color.green)
  15. endtext = text(pos=vec(90,-70,0), text='End', depth=2, height=10, color=color.red)
  16.  
  17. #Initial swim speed and run speed
  18. swimv = 2
  19. runv = 9
  20.  
  21. #Calculations to determine the amount of time for swim and amount of time for run--think distance/speed...
  22. swimtime = 0
  23. runtime = 0
  24. totaltime = swimtime+runtime
  25.  
  26. #this draws a line from start to shore point and from shore point to end
  27. shorepoint = 0
  28. swimroute = cylinder(pos=vec(start.pos.x,start.pos.y,1), axis=vector(shorepoint-start.pos.x,0-start.pos.y,1), radius=1, color=color.green)
  29. runroute = cylinder(pos=vec(end.pos.x,end.pos.y,1), axis=vec(shorepoint-end.pos.x,0-end.pos.y,1), radius=1, color=color.red)
  30.  
  31. ##graph total time vs shore point position
  32. Grph1 = graph(title='Finding Optimal Path', xtitle='Shoreline Coordinate (m)', ytitle='Total Time (s)', fast=False, align="right", ymin=0, ymax=200, xmin=-50, xmax=100)
  33. TimeOpt = gcurve(color=color.red, label='Optimal Path')
  34.  
  35. while shorepoint<0:
  36. rate(120)
  37. swimtime =
  38. runtime =
  39. totaltime = swimtime+runtime
  40. swimroute.axis = vec(shorepoint-start.pos.x,0-start.pos.y,1)
  41. runroute.axis = vec(shorepoint-end.pos.x,0-end.pos.y,1)
  42. TimeOpt.plot(target,totaltime)
  43. target = target + dt

Answer Key

Handout

Code

  1. GlowScript 2.8 VPython
  2.  
  3. scene.width = 750
  4. scene.height = 568
  5. scene.fov = .3
  6. scene.align = "left"
  7.  
  8. ## Objects for the lake and beach
  9. lake = box(pos=vector(0,100,0), size=vector(300,200,2), axis=vector(1,0,0), color=color.cyan, texture=textures.rough)
  10. beach = box(pos=vector(0,-50,0), size=vector(300,100,2), axis=vector(1,0,0), color=color.yellow, texture=textures.stucco)
  11. start = sphere(pos=vec(-50,120,0), radius=10, color=color.green)
  12. end = sphere(pos=vec(100,-50,0), radius=10, color=color.red)
  13. starttext = text(pos=vec(-65,130,0), text='Start', depth=2, height=10, color=color.green)
  14. endtext = text(pos=vec(90,-70,0), text='End', depth=2, height=10, color=color.red)
  15.  
  16. #Initial swim speed and run speed
  17. target = -50
  18. dt = 0.5
  19. final = 100
  20. swimv = 2
  21. runv = 9
  22.  
  23. #Calculations to determine the amount of time for swim and amount of time for run--think distance/speed...
  24. swimtime = sqrt(start.pos.y**2 + (target-start.pos.x)**2)/swimv
  25. runtime = sqrt(end.pos.y**2 + (end.pos.x-target)**2)/runv
  26. totaltime = swimtime+runtime
  27. swimroute = cylinder(pos=vec(start.pos.x,start.pos.y,1), axis=vector(target-start.pos.x,0-start.pos.y,1), radius=1, color=color.green)
  28. runroute = cylinder(pos=vec(end.pos.x,end.pos.y,1), axis=vec(target-end.pos.x,0-end.pos.y,1), radius=1, color=color.red)
  29.  
  30. ##graph net force vs position
  31. Grph1 = graph(title='Finding Optimal Path', xtitle='Shoreline Coordinate (m)', ytitle='Total Time (s)', fast=False, align="right", ymin=0, ymax=300, xmin=-50, xmax=100)
  32. TimeOpt = gcurve(color=color.red, label='Optimal Path')
  33.  
  34. while target<final:
  35. rate(120)
  36. swimtime = sqrt(start.pos.y**2 + (target-start.pos.x)**2)/swimv
  37. runtime = sqrt(end.pos.y**2 + (end.pos.x-target)**2)/runv
  38. totaltime = swimtime+runtime
  39. swimroute.axis = vec(target-start.pos.x,0-start.pos.y,1)
  40. runroute.axis = vec(target-end.pos.x,0-end.pos.y,1)
  41. TimeOpt.plot(target,totaltime)
  42. target = target + dt

See Also

  • repository/triathlete_s_dilemma.1611708305.txt.gz
  • Last modified: 2021/01/27 00:45
  • by porcaro1