Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
summer_2018:vpython_tips [2021/06/24 15:17]
bott123 [Common Commands]
summer_2018:vpython_tips [2021/06/24 16:03] (current)
pwirving
Line 63: Line 63:
 print(CD) ​ #This will print out the vector (-8, 9, -8) print(CD) ​ #This will print out the vector (-8, 9, -8)
 </​code>​ </​code>​
-  ​* **Graphing** - There are a few ways to graph in python, but a common method is via gcurve. If the values you wish to plot are changing over time in a loop, be sure to put the plot command in the loop with them, and plot each point for each iteration of the loop. + 
-<​code>​ + 
-ExampleGraph = gcurve(color=color.green,​ label = 'Data Points'​) ​ #First, define the graph.  +  ​* **Graphing** - One method of graphing involves using physutil, which is a library that needs to be imported. From there, the syntax is similar to gcurve. MUST use GlowScript 2.9 or lower; anything higher will not import properly.
-ExampleGraph.plot([1,​2],​[3,​4],​[5,​6]) ​ #This will plot the three points listed, connected by a line. +
-</​code>​ +
-Another ​method of graphing involves using physutil, which is a library that needs to be imported. From there, the syntax is similar to gcurve. MUST use GlowScript 2.9 or lower; anything higher will not import properly.+
 <​code>​ <​code>​
 get_library('​https://​cdn.rawgit.com/​PERLMSU/​physutil/​master/​js/​physutil.js'​) ​ #Imports physutil get_library('​https://​cdn.rawgit.com/​PERLMSU/​physutil/​master/​js/​physutil.js'​) ​ #Imports physutil
  
-ball = sphere(pos=vector(0,​0,​0),​ radius=0.5, color=color.red) +MassOfBall ​= 20 
-ball.mass ​= 20 +SpeedOfBall ​= 10
-ball.speed ​= 10+
  
 t=0 t=0
Line 80: Line 76:
 tf=10 tf=10
  
-ExampleGraph2 = PhysGraph(numPlots = 1)+ExampleGraph2 = PhysGraph(numPlots = 1)   #Defines graph window
  
 while t < tf: while t < tf:
-    KineticEnergy = 0.5*ball.mass*ball.speed**2 +    ​rate(50) 
-    ExampleGraph2.plot(t,​ KineticEnergy) +     
-    ​ball.speed ​ball.speed ​- 0.5+    ​KineticEnergy = 0.5*MassOfBall*SpeedOfBall**2 
 +    ExampleGraph2.plot(t,​ KineticEnergy) ​  #Plot function is identical 
 +    ​SpeedOfBall ​SpeedOfBall ​- 0.5 
 +     
 +    t = t+ dt
 </​code>​ </​code>​
   * **MotionMaps** - MotionMaps track an object and plant arrows in a trail behind the object. The size and direction of the arrows is controllable,​ so it can be a useful method to demonstrate any vector quantity of an object, such as velocity or Force. MUST use GlowScript 2.9 or lower; anything higher will not import properly.   * **MotionMaps** - MotionMaps track an object and plant arrows in a trail behind the object. The size and direction of the arrows is controllable,​ so it can be a useful method to demonstrate any vector quantity of an object, such as velocity or Force. MUST use GlowScript 2.9 or lower; anything higher will not import properly.
  • summer_2018/vpython_tips.1624547830.txt.gz
  • Last modified: 2021/06/24 15:17
  • by bott123