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 [2018/06/20 17:15]
tallpaul
summer_2018:vpython_tips [2021/06/24 16:03] (current)
pwirving
Line 49: Line 49:
 print(A) #This will then print out the number 21 print(A) #This will then print out the number 21
 </​code>​ </​code>​
-  * **Dot Product** - the dot product is a way to [[184_notes:​math_review#​Vector Multiplication|multiply two vectors]]. Python has this command already programmed in:+  * **Dot Product** - the dot product is a way to [[http://​p3server.pa.msu.edu/​coursewiki/​doku.php?​id=184_notes:​math_review#​Vector Multiplication|multiply two vectors]]. Python has this command already programmed in:
 <​code>​ <​code>​
 A=vec(1,​2,​3) A=vec(1,​2,​3)
Line 62: Line 62:
 CD=cross(C,​D) ​ #This will calculate (6*1-2*7)i-hat - (5*1-7*2)j-hat + (5*2-6*3)k-hat CD=cross(C,​D) ​ #This will calculate (6*1-2*7)i-hat - (5*1-7*2)j-hat + (5*2-6*3)k-hat
 print(CD) ​ #This will print out the vector (-8, 9, -8) print(CD) ​ #This will print out the vector (-8, 9, -8)
 +</​code>​
 +
 +
 +  * **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.
 +<​code>​
 +get_library('​https://​cdn.rawgit.com/​PERLMSU/​physutil/​master/​js/​physutil.js'​) ​ #Imports physutil
 +
 +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(t,​ KineticEnergy) ​  #Plot function is identical
 +    SpeedOfBall = SpeedOfBall - 0.5
 +    ​
 +    t = t+ dt
 +</​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.
 +<​code>​
 +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 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.
 +
 +Setting up time parameters for the motion
 +t=0
 +dt=0.1
 +tf=10
 +
 +#Creating the MotionMap via MotionMap(object,​ stop time, number of arrows, arrow size, arrow color, number labels on arrows or not)
 +Moving_Sphere_MotionMap = MotionMap(Moving_Sphere,​ tf, 5, markerScale=1,​ markerColor=color.orange,​ labelMarkerOrder=False)
 +
 +while t < tf:
 +    rate(100)
 +    ​
 +    Moving_Sphere.pos = Moving_Sphere.pos + Sphere_velocity * dt   #​Sphere is moving according to its velocity
 +    Moving_Sphere_MotionMap.update(t,​Sphere_velocity) ​  #​MotionMap update function plots the vector as time goes by
 +    ​
 +    t = t + dt
 </​code>​ </​code>​
  • summer_2018/vpython_tips.1529514929.txt.gz
  • Last modified: 2018/06/20 17:15
  • by tallpaul