VPython 3D Objects: Difference between revisions

From Physics Book
Jump to navigation Jump to search
No edit summary
No edit summary
Line 1: Line 1:
'''Claimed by Do Won Kim (Fall 2017)'''
'''Claimed by Do Won Kim (Fall 2017)'''


The main purpose of the VPython programming language is to create 3D simulation with creating the 3D objects. To achieve this purpose, VPython already contains a number of built-in 3-dimensional objects, and these objects are displayed in a 3D graphics module called Visual. Familiarizing with these objects is important for lab coding.
The main purpose of the VPython programming language is to create 3D simulation with creating the 3D objects. To achieve this purpose, VPython already contains a number of built-in 3-dimensional objects, and these objects are displayed in a 3D graphics module called Visual. Familiarizing with these objects is important for lab coding.
 
Before start coding, make sure to have
 
from __future__ import division
from visual import *
 
on the top of your script.


==List of 3D Objects==
==List of 3D Objects==


VPython is packaged with a variety of 3-Dimensional objects. These objects include:
VPython is packaged with a variety of 3-Dimensional objects. These objects include:
#[http://www.glowscript.org/docs/VPythonDocs/arrow.html Arrow]
 
#[http://www.glowscript.org/docs/VPythonDocs/box.html Box]
[http://www.glowscript.org/docs/VPythonDocs/arrow.html Arrow]
#[http://www.glowscript.org/docs/VPythonDocs/cone.html Cone]
[[File:RedArrow.png|thumb|none|alt=Yellow Arrow|The example arrow]]
#[http://www.glowscript.org/docs/VPythonDocs/convex.html Convex]
 
#[http://www.glowscript.org/docs/VPythonDocs/curve.html Curve]
[http://www.glowscript.org/docs/VPythonDocs/box.html Box]
#[http://www.glowscript.org/docs/VPythonDocs/cylinder.html Cylinder]
[[File:RedArrow.png|thumb|none|alt=Yellow Arrow|The example arrow]]
#[http://www.glowscript.org/docs/VPythonDocs/ellipsoid.html Ellipsoid]
 
#[http://www.glowscript.org/docs/VPythonDocs/extrusion.html Extrusion]
 
#[http://www.glowscript.org/docs/VPythonDocs/faces.html Faces]
[http://www.glowscript.org/docs/VPythonDocs/cone.html Cone]
#[http://www.glowscript.org/docs/VPythonDocs/helix.html Helix]
 
#[http://www.glowscript.org/docs/VPythonDocs/label.html Label]
[http://www.glowscript.org/docs/VPythonDocs/convex.html Convex]
#[http://www.glowscript.org/docs/VPythonDocs/points.html Points]
 
#[http://www.glowscript.org/docs/VPythonDocs/pyramid.html Pyramid]
[http://www.glowscript.org/docs/VPythonDocs/curve.html Curve]
#[http://www.glowscript.org/docs/VPythonDocs/ring.html Ring]
 
#[http://www.glowscript.org/docs/VPythonDocs/sphere.html Sphere]
[http://www.glowscript.org/docs/VPythonDocs/cylinder.html Cylinder]
#[http://www.glowscript.org/docs/VPythonDocs/text.html Text]
 
The ease with which these objects can be manipulated using python makes them popular in physics classes.
[http://www.glowscript.org/docs/VPythonDocs/ellipsoid.html Ellipsoid]
 
[http://www.glowscript.org/docs/VPythonDocs/extrusion.html Extrusion]
 
[http://www.glowscript.org/docs/VPythonDocs/faces.html Faces]
 
[http://www.glowscript.org/docs/VPythonDocs/helix.html Helix]
 
[http://www.glowscript.org/docs/VPythonDocs/label.html Label]
 
[http://www.glowscript.org/docs/VPythonDocs/points.html Points]
 
[http://www.glowscript.org/docs/VPythonDocs/pyramid.html Pyramid]
 
[http://www.glowscript.org/docs/VPythonDocs/ring.html Ring]
 
[http://www.glowscript.org/docs/VPythonDocs/sphere.html Sphere]
 
[http://www.glowscript.org/docs/VPythonDocs/text.html Text]




==Important Objects==
==Commonly Used Objects==
The following objects appear often in Physics 2.
The following objects are often used in class lab.


===Sphere===
===Sphere===

Revision as of 02:29, 28 November 2017

Claimed by Do Won Kim (Fall 2017)

The main purpose of the VPython programming language is to create 3D simulation with creating the 3D objects. To achieve this purpose, VPython already contains a number of built-in 3-dimensional objects, and these objects are displayed in a 3D graphics module called Visual. Familiarizing with these objects is important for lab coding.

Before start coding, make sure to have

from __future__ import division
from visual import *

on the top of your script.

List of 3D Objects

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

Arrow

Error creating thumbnail: sh: /usr/bin/convert: No such file or directory Error code: 127
The example arrow

Box

Error creating thumbnail: sh: /usr/bin/convert: No such file or directory Error code: 127
The example arrow


Cone

Convex

Curve

Cylinder

Ellipsoid

Extrusion

Faces

Helix

Label

Points

Pyramid

Ring

Sphere

Text


Commonly Used Objects

The following objects are often used in class lab.

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