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:00]
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 few ways to graph in pythonbut a common method ​is via gcurve:+ 
 + 
 +  ​* **Graphing** - One method of graphing involves using physutil, which is library that needs to be imported. From therethe syntax ​is similar to gcurve. MUST use GlowScript 2.9 or lower; anything higher will not import properly.
 <​code>​ <​code>​
-ExampleGraph = gcurve()  #First, define the graph.  +get_library('​https://​cdn.rawgit.com/​PERLMSU/​physutil/​master/​js/​physutil.js'​)  #Imports physutil 
-ExampleGraph.plot([1,2],​[3,​4],​[5,​6] #This will plot the three points listed, connected by a line.+ 
 +MassOfBall = 20 
 +SpeedOfBall = 10 
 + 
 +t=0 
 +dt=0.1 
 +tf=10 
 + 
 +ExampleGraph2 = PhysGraph(numPlots = 1)   #​Defines ​graph window 
 + 
 +while t < tf: 
 +    rate(50) 
 +     
 +    KineticEnergy = 0.5*MassOfBall*SpeedOfBall**2 
 +    ​ExampleGraph2.plot(tKineticEnergy  ​#Plot function is identical 
 +    SpeedOfBall = SpeedOfBall - 0.
 +     
 +    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 ​version ​2.7, 2.8, or 2.9any later versions ​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.or loweranything higher ​will not import properly.
 <​code>​ <​code>​
-get_library('​https://​cdn.rawgit.com/​PERLMSU/​physutil/​master/​js/​physutil.js'​) ​ #​Imports ​the MotionMap code from its source+get_library('​https://​cdn.rawgit.com/​PERLMSU/​physutil/​master/​js/​physutil.js'​) ​ #​Imports ​physutil
  
-Moving_Sphere = sphere(pos=vector(0,​0,​0),​ radius = 0.5, color = color.cyan) ​ #The object we want to plant arrows for, a cyan sphere.+Moving_Sphere = sphere(pos=vector(0,​0,​0),​ radius = 0.5, color = color.cyan) ​ #The object we want to place arrows for, a cyan sphere.
 Sphere_velocity = vector(5,​5,​0) ​ #Let's say we want a MotionMap for the velocity of this sphere. Sphere_velocity = vector(5,​5,​0) ​ #Let's say we want a MotionMap for the velocity of this sphere.
  
  • summer_2018/vpython_tips.1624546849.txt.gz
  • Last modified: 2021/06/24 15:00
  • by bott123