VPython 3D Objects

From Physics Book
Revision as of 19:07, 5 December 2015 by Ctanzman10 (talk | contribs) (Created page with "The VPython programming language contains a number of 3-dimensional objects that can be displayed in a 3D graphics module called Visual. ==Overview== VPython is packaged wit...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

The VPython programming language contains a number of 3-dimensional objects that can be displayed in a 3D graphics module called Visual.

Overview

VPython is packaged with a variety of 3-Dimensional objects. These objects include:

  1. Arrow
  2. Box
  3. Cone
  4. Convex
  5. Curve
  6. Cylinder
  7. Ellipsoid
  8. Extrusion
  9. Faces
  10. Helix
  11. Label
  12. Points
  13. Pyramid
  14. Ring
  15. Sphere
  16. Text

The ease with which these objects can be manipulated using python makes them popular in physics classes.


Important Objects

The following objects appear often in Physics 2.

Sphere

The sphere object can be used to represent a wide variety of things, but perhaps the most important for use in Physics 2 is point charges and protons/electrons. Two things must be set; the position, a vector; and the radius, a numerical value.

Arrow

The arrow is perhaps the most important object for Physics 2. It can be used to represent Electric and magnetic fields as well as visualizing vectors. To create an arrow the position (a vector), axis (a vector), and the shaftwidth (a numerical value) must be set.

Object Uses

Examples of Simple Objects

sphere1 = sphere(pos=vector(4,8,15), radius=16)
arrow1 = arrow(pos=vector(4,8,15), axis=vector(16,23,42)
helix1 = helix(pos=vector(4,8,15), axis=vector(16,23,42) radius=.23)

Modeling Fields

from visual import *
mzofp = 1e-7
oofpez = 9e9
qe = 1.6e-19
proton = sphere(pos=vector(3e-10,0,0), radius=1e-11, color=color.red)
velocity = vector(-5.2e4,0,0) #The proton's velocity
r_obs = vector(0,8e-11,0) #The observation location
deltat = 1e-19 #Timestep
while proton.x < 5e-10:
r = r_obs - proton.pos
rhat = r/mag(r)
Efield = oofpez*qe*rhat/(mag(r)**2)
Bfield = mzofp*qe*cross(velocity,that)/(mag(r)**2)

See also

  1. VPython Basics
  2. VPython
  3. VPython Animation

Further reading

  1. 3D object details
  2. VPython Information


References

http://www.glowscript.org/docs/VPythonDocs/primitives.html http://vpython.org/contents/docs/shapes.html