Home > Uncategorized > GlowScript Tutorial 3: Graphing

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.

GlowScript_IDE

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:

GlowScript_IDE

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.

GlowScript_IDE

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.

GlowScript Tutorial 4: Mass on a Spring

Advertisements
Categories: Uncategorized
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: