Project 1 Solution: Part B: Voyager collision course
Link to starter code: https://www.glowscript.org/#/user/pcubed/folder/incompleteprograms/program/SatteliteCode
This is the students first introduction to VPython. In it, they must identify a few lines of code, write a few new lines, and discuss why those lines are written the way they are. Many students are often trepadatious to engage in computational modeling at first. You will need to encourage and coach them (computational anxiety is well-documented in the literature). Students often get the motion of the objects going fairly quickly, but the struggle with the graph. This calculation can really take their time away, but fortunately it is at the end. Encourage them to do this last after they have a working model. Also, encourage saving and “versioning” when they reach a key milestone, so they can always go back to a working model.
Identifying parameters
The students need to recognize that they must ask for a measurement of both the position and velocity of the asteroid as measured relative to the Voyager: $\vec{r}_{\rm A/V}=\langle-3{\rm e}10,8{\rm e}10,3{\rm e}9\rangle\,{\rm m}$ and $\vec{v}_{\rm A/V}=\langle1{\rm e}5,-9{\rm e}4,0\rangle\,{\rm m/s}.$ They can then use these to add in the initial position and the velocity of the asteroid, relative to ground control:
#Objects Asteroid = sphere(pos = Voyager.pos + vector(-3e10,8e10,3e9), radius=5e9) #Parameters and Initial Conditions vAsteroid = vVoyager + vector(1e5,-9e4,0)
Updating the loop
Given this new position and velocity of the asteroid, we need to incorporate a position update in the while loop:
#Calculation loop Asteroid.pos = Asteroid.pos + vAsteroid*dt
Tutor Questions
- Question: What does each line/segment of code do?
- Expected Answer: …
- Question: How did you determine the velocity and position of the asteroid relative to ground control?
- Expected Answer: We had to add the relative vectors.
- Question: How do you know the asteroid and Voyager are moving with constant velocity
- Expected Answer: No forces to cause a change in velocity.
- Tutor Question: Could you have done this problem pen-and-paper style? Would you have wanted to?
- Expected Answer: Could have, wouldn't want to. Very tedious
- Tutor Question: Are there any parts of the code that are particularly troublesome/confusing/difficult? Were there any parts that were intuitive/easy?
- Expected Answer: …
Adding the separation graph
In adding the graph, the group should use the PhysGraph bookmark in Safari to figure out how to plot.
#MotionMap/Graph separation = PhysGraph(numPlots=1) #Calculation Loop separation.plot(t,mag(Voyager.pos-Asteroid.pos))
Tutor Questions
- Question: How did you determine the separation between the asteroid and Voyager over time?
- Expected Answer: Not only the difference between the two, but the magnitude.
- voyager.sol.py
GlowScript 2.9 VPython get_library('https://cdn.rawgit.com/PERLMSU/physutil/master/js/physutil.js') #Objects Voyager = sphere(pos=vector(-5e10,-2e10,-3e9), radius=3e9, color=color.green, make_trail=True) Asteroid = sphere(pos = Voyager.pos + vector(-3e10,8e10,3e9), radius=5e9, color=color.red, make_trail=True) #Parameters and Initial Conditions vVoyager = vector(1e5, 1e4, 1e4) vAsteroid = vVoyager + vector(1e5,-9e4,0) #Time and time step dt = .25e6 t = 0 tf = 1e6 #MotionMap/Graph trackVoyager = MotionMap(Voyager, tf, 5, markerScale=1e5) trackAsteroid = MotionMap(Asteroid, tf, 5, markerSacale=1e5) separation = PhysGraph(numPlots=1) #Calculation Loop while t < tf: rate(10) Voyager.pos = Voyager.pos + vVoyager*dt Asteroid.pos = Asteroid.pos + vAsteroid*dt trackVoyager.update(t,vVoyager) trackAsteroid.update(t,vAsteroid) separation.plot(t,mag(Voyager.pos-Asteroid.pos)) t = t + dt
Link to solution: https://www.glowscript.org/#/user/pcubed/folder/solutions/program/SatteliteCodeSolution
Tutor Questions
- Question: How does the code predict the motion of Voyager/asteroid? What is the code actually calcuating?
- Expected Answer: It is iteratively calculating a new position based on small step forward in time deltat and the known constant velocity of Voyager/asteroid.
- Question: What are you leaving out of this model? What makes it the simplest model?
- Expected Answer: There's no interaction between Voyager and the asteroid.
- Question: Why is the calculation of the separation vector magnitude in the loop?
- Expected answer: Becasue it changes in every time step and needs to be recalculated each time
- Question: I noticed your group working hard to understand (NOTICED COMPUTING CONCEPT; eg., iteration, variable assignment, coding physics into program, etc.). CAn you tell me about how your group worked to make sense of (NOTICED COMPUTING CONCEPT)?
Main Points
- Students should be able to identify and discuss all relevant physical variables and how they appear in the code.
- Students should have completed the iterative calculation for both Voyager/asteroid and be able to tell you what they did and why. This should include a clear discussion of how the code predicts the motion of the asteroid/Voyager.
- (“BONUS”), If they have time Students should have a plot of the separation between Voyager and the asteroid vs time. This will be tough because they have to perform the calculation in the loop and they might not realize this concept.
Common difficulties
- Student groups usually can model the motion of the objects fine. It's a copy-and-paste situtation. They might struggle a bit with identifying the relevant lines to copy-and-paste, but it's usually not bad. They will misspell variables and cause syntax or runtime errors - so look for that.
- A larger challenge is the calcualtion of the separation vector; encourage whiteboarding that first then trying to translate to code. The struggle with both syntax and placement, so they should be encourage to think about both.