GlowScript Tutorial 3: Graphing
Let’s go back to the program from tutorial 2 (projectile motion). What if you want to know how high the ball goes (the highest point)? You can’t use the print trick like you did in the last tutorial since you are only printing the vertical position at the end of the motion. There are some other tricks you could use to print the highest point, but what you really want is a graph.
Here is the first part of the projectile motion problem with a graph added.
The f1=series() tells glowscript that we are going to make a graph. However, it doesn’t tell it what to plot. We need to add a data point to the graph during each step of the calculation. I can do this by adding a line inside the loop (and thus indented) like this:
This will add a data point with the time in the horizontal axis and the y-position of the ball in the vertical axis. Here is what that looks like when I run it.
From this plot, you could easily find the highest point the ball traveled. As you move your mouse over the graph in GlowScript, it will show you the x-y coordinates of your mouse. This can be helpful in examining the data (and finding out the highest point of the ball). Here are some other things to try.
- Make a plot of the trajectory of the ball. This would be x vs. y.
- What about the vertical velocity as a function of time.
- Plot the horizontal velocity as a function of time.
One final note. If you have made graphs in VPython, you can use the exact same method for creating graphs in GlowScript.