<< Chapter < Page | Chapter >> Page > |
Screen output
The text shown in Figure 4 should appear in your browser window when the html file is opened in your browser.
Figure 4 . Screen output for Listing #2. |
---|
Start Script
Time for leg A = 0.30 secondsTime for leg B = 0.33 seconds
Displacement magnitude = 25.00 feetDisplacement angle = 98.13 degrees
Total time = 0.63 secondsAverage velocity magnitude = 39.47 feet/second
Average velocity angle = 98.13 degreesEnd Script |
Analysis of the code
In this exercise, the puck makes a journey across the ice consisting of two sequential legs in different directions with different magnitudes ofvelocity. Although each leg involves motion along a line, the total trip is not along a line.
The objective of the script is to
The getAngle function
The code in Listing 2 begins with the getAngle function that we developed and used an earlier module. The purpose of the function is to receive the adjacentand opposite side values for a right triangle as parameters and to return the angle in degrees in the correct quadrant.
I explained this function in an earlier module and won't repeat that explanation in this module.
Compute the time for each leg
Following the definition of the getAngle function, Listing 2 computes the time required to traverse each leg of the trip. For variable naming purposes, the two legs are identified as A and B.
Variable names that end with "mag" contain vector magnitudes. Variable names that end with "ang" contain vector angles. Variable names that endwith "vel" contain the magnitudes of straight-line, uniform velocities.
The time to complete each leg of the trip is computed by dividing the magnitude of the displacement vector for that leg by the magnitude of thestraight-line velocity for that leg. The resulting times have units of seconds, and are saved in the variables named timeA and timeB .
The overall displacement
The magnitude and angle of the overall displacement for the two-leg trip (identified by the variables named vecResultMag and vecResultAng respectively) are computed using procedures that were explained in an earlier module. Therefore, I won't repeat that explanation inthis module.
The magnitude of the overall displacement is stored in the variable named vecResultMag , and the angle for the overall displacement is stored in the variable named vecResultAng .
The total time
The total time for the trip, identified by the variable named totalTime , is computed as the sum of the times for the individual legs.
Magnitude of the average velocity vector
Notification Switch
Would you like to follow the 'Accessible physics concepts for blind students' conversation and receive update notifications?