<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>http://www.physicsbook.gatech.edu/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Smaji7</id>
	<title>Physics Book - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="http://www.physicsbook.gatech.edu/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Smaji7"/>
	<link rel="alternate" type="text/html" href="http://www.physicsbook.gatech.edu/Special:Contributions/Smaji7"/>
	<updated>2026-05-01T04:36:37Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.42.7</generator>
	<entry>
		<id>http://www.physicsbook.gatech.edu/index.php?title=VPython&amp;diff=20722</id>
		<title>VPython</title>
		<link rel="alternate" type="text/html" href="http://www.physicsbook.gatech.edu/index.php?title=VPython&amp;diff=20722"/>
		<updated>2016-04-04T04:15:06Z</updated>

		<summary type="html">&lt;p&gt;Smaji7: /* Useful built-in functions */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Claimed by Nathan Cheek&lt;br /&gt;
&lt;br /&gt;
VPython is a Python graphics module used for modeling objects in 3-dimensional space.  In the field of physics, this is especially useful for calculating and modeling complex relationships between objects and their properties.&lt;br /&gt;
&lt;br /&gt;
[[File:VPythonMagneticForceAnimated.gif|thumb|VPython modeling the magnetic force on a moving particle]]&lt;br /&gt;
&lt;br /&gt;
==Installation==&lt;br /&gt;
&lt;br /&gt;
VPython is compatible with Windows, OSX, and Linux.  While there is an older VPython version available that supports Python 3, the Georgia Tech physics courses use Python 2 syntax so it is recommended to install the latest version of VPython as outlined below.&lt;br /&gt;
&lt;br /&gt;
===Windows===&lt;br /&gt;
[[File:VPythonWindows.png|thumb|VPython running in Windows 7]]&lt;br /&gt;
&lt;br /&gt;
1. Install [http://python.org/ftp/python/2.7.9/python-2.7.9.amd64.msi Python-2.7].&lt;br /&gt;
&lt;br /&gt;
2. Download and install VPython from [http://sourceforge.net/projects/vpythonwx/files/6.11-release/VPython-Win-64-Py2.7-6.11.exe/download Sourceforge].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
To troubleshoot any installation issues, look at the extensive [http://vpython.org/contents/download_windows.html VPython Windows installation guide].&lt;br /&gt;
&lt;br /&gt;
===OSX===&lt;br /&gt;
[[File:VPythonOSX.png|thumb|VPython running in OSX 10.10]]&lt;br /&gt;
&lt;br /&gt;
1. Install [https://www.python.org/ftp/python/2.7.9/python-2.7.9-macosx10.6.pkg Python-2.7].  This is required as the version of Python that Apple provides is not compatible.&lt;br /&gt;
&lt;br /&gt;
2. Download and install the VPython package from [http://sourceforge.net/projects/vpythonwx/files/6.11-release/VPython-Mac-Py2.7-6.11.dmg/download Sourceforge].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
To troubleshoot installation issues, see the extensive [http://vpython.org/contents/download_mac.html VPython Mac installation guide].&lt;br /&gt;
&lt;br /&gt;
===GNU/Linux===&lt;br /&gt;
[[File:VPythonUbuntu.png|thumb|VPython running in Ubuntu 15.04]]&lt;br /&gt;
&lt;br /&gt;
Some Linux distributions include VPython in their repositories.  For example, to install VPython in Ubuntu 15.04:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;sudo apt-get install python-visual&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
If your Linux distribution&#039;s repository does not have the latest version of VPython, you can run the Windows version using [https://www.winehq.org/ Wine].  The [http://vpython.org/contents/download_linux.html VPython Linux installation guide] contains detailed instructions.&lt;br /&gt;
&lt;br /&gt;
==Getting started with VPython==&lt;br /&gt;
The easiest way to use VPython is with VIDLE.  VIDLE is a development environment and is the most useful for editing and running code.  To start, open the VIDLE application (it may be called something like VIDLE-Py2.7).  A blank file should open.  Type the following two lines in:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;from __future__ import division&lt;br /&gt;
&lt;br /&gt;
from visual import *&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The first line tells Python to not use integer division, which would result in &amp;lt;code&amp;gt;1/3&amp;lt;/code&amp;gt; returning the floor &amp;lt;code&amp;gt;0&amp;lt;/code&amp;gt; instead of &amp;lt;code&amp;gt;0.3333333333333333&amp;lt;/code&amp;gt;.  The second line tells Python to import everything from the visual (VPython) library for you to use.&lt;br /&gt;
&lt;br /&gt;
After these two lines, you can create objects, assign variables, do calculations, and much more.  You can also run VPython from the command line, although it may require additional setup so Python can locate the &amp;lt;code&amp;gt;visual&amp;lt;/code&amp;gt; module.&lt;br /&gt;
&lt;br /&gt;
==Creating VPython Objects==&lt;br /&gt;
When you create objects, it is often useful to assign them to variables so you can reference them later to either get or set values describing for example the position and size of the object.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Sphere&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;particle = sphere(pos=(0,0,0), radius=4, color=color.blue)&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This creates a blue sphere centered at the origin &amp;lt;0,0,0&amp;gt; with radius 4.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Arrow&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;arrowToOrigin = arrow(pos=(0,2,0), axis=(0,8,0), color=color.green)&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This creates a green arrow pointing from &amp;lt;0,2,0&amp;gt; to &amp;lt;0,10,0&amp;gt;.  Note that &amp;lt;code&amp;gt;axis&amp;lt;/code&amp;gt; is always relative to the start of the arrow, not the origin &amp;lt;0,0,0&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Cylinder&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;wire = cylinder(pos=(0,0,0), axis=(20,0,0), radius=1, color=color.yellow)&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This creates a yellow cylinder starting at the origin &amp;lt;0,0,0&amp;gt; and extending to &amp;lt;20,0,0&amp;gt; with radius 1.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example&#039;&#039;&#039;&lt;br /&gt;
[[File:VPythonObjects.png|thumb|Result of example code]]&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;&lt;br /&gt;
from __future__ import division&lt;br /&gt;
from visual import *&lt;br /&gt;
&lt;br /&gt;
particle = sphere(pos=(0,0,0), radius=4, color=color.blue)&lt;br /&gt;
arrowToOrigin = arrow(pos=(0,2,0), axis=(0,8,0), color=color.green)&lt;br /&gt;
wire = cylinder(pos=(0,0,0), axis=(20,0,0), radius=1, color=color.yellow)&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Updating objects&#039;&#039;&#039;&lt;br /&gt;
If you assign an object to a variable (such as &amp;lt;code&amp;gt;particle&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;arrowToOrigin&amp;lt;/code&amp;gt; above) you can adjust its parameters such as its location.  For the above sphere, you can change its location to &amp;lt;-5,-5,0&amp;gt; with:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;particle.pos=(-5,-5,0)&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To change the axis of the above arrow to point to &amp;lt;-10,5,0&amp;gt;, use:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;arrowToOrigin.axis=(-10,5,0)&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To change the radius of the above cylinder to 3, use:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;wire.radius=3&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example&#039;&#039;&#039;&lt;br /&gt;
[[File:VPythonObjectsChanged.png|thumb|Result of example code]]&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;&lt;br /&gt;
from __future__ import division&lt;br /&gt;
from visual import *&lt;br /&gt;
&lt;br /&gt;
particle = sphere(pos=(0,0,0), radius=4, color=color.blue)&lt;br /&gt;
arrowToOrigin = arrow(pos=(0,2,0), axis=(0,8,0), color=color.green)&lt;br /&gt;
wire = cylinder(pos=(0,0,0), axis=(20,0,0), radius=1, color=color.yellow)&lt;br /&gt;
&lt;br /&gt;
particle.pos=(-5,-5,0)&lt;br /&gt;
arrowToOrigin.axis=(-10,5,0)&lt;br /&gt;
wire.radius=3&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Useful built-in functions==&lt;br /&gt;
&lt;br /&gt;
VPython includes various functions that can make your calculations much easier.  The following functions simplify mathematical operations on vectors and will come in handy very often.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Cross-multiply two vectors&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;cross(vectorA, vectorB)&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Magnitude of a vector&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;mag(vector)&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Square of the Magnitude of a vector&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;mag2(vector)&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Unit vector of a vector&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;norm(vector)&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Connectedness==&lt;br /&gt;
&lt;br /&gt;
I am very interested in programming.  I have used Python for years, so translating Physics problems into VPython code is a great way to cement the fundamental ideas in my mind.&lt;br /&gt;
&lt;br /&gt;
VPython is a great tool to bridge the worlds of Computer Science and Physics.  Many of the calculations required to model a physical object would be tedious if done by hand.  Yet with often a few lines of code, this work can be reduced to almost nothing.&lt;br /&gt;
&lt;br /&gt;
NASA has published [http://gcmd.gsfc.nasa.gov/KeywordSearch/Metadata.do?Portal=GCMD&amp;amp;MetadataType=1&amp;amp;MetadataView=Full&amp;amp;KeywordPath=&amp;amp;EntryId=3-D_ES-Models VPython models].  However, VPython is still primarily used in an educational context.&lt;br /&gt;
&lt;br /&gt;
==History==&lt;br /&gt;
&lt;br /&gt;
VPython was originally released in 2000 by David Scherer after he took an introductory physics class at Carnegie Mellon University.  At the time, the school used the cT programming language for 2D modeling, and David saw the need for something better.  Working with several people including professors Ruth Chabay and Bruce Sherwood, he developed a Python module called Visual.  Visual Python or VPython featured 3D modeling, as well as an easier-to-understand object-oriented syntax.  Beginning in 2002, the National Science Foundation had awarded $292,286.00 as of December 2015 for the further development of this tool.  VPython is released under an Open Source license, and development continues today.&lt;br /&gt;
&lt;br /&gt;
== See also ==&lt;br /&gt;
&lt;br /&gt;
If you have never used Python, the [[VPython_basics| VPython Basics]] wiki page has information for getting started with Python programming.&lt;br /&gt;
&lt;br /&gt;
===Further reading===&lt;br /&gt;
&lt;br /&gt;
Aiken, John M (2013). &#039;&#039;Transforming High School Physics With Modeling And Computation&#039;&#039;. Georgia State University.&lt;br /&gt;
&lt;br /&gt;
===External links===&lt;br /&gt;
&lt;br /&gt;
[http://www.wired.com/2015/08/coding-physics-course/ You Should Be Coding in Your Physics Course]&lt;br /&gt;
&lt;br /&gt;
[http://vpython.wikidot.com/ VPython Wiki Site]&lt;br /&gt;
&lt;br /&gt;
[https://groups.google.com/forum/#!forum/vpython-users VPython user group]&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
This section contains the the references you used while writing this page&lt;br /&gt;
&lt;br /&gt;
[http://vpython.org/contents/cTsource/cToverview.html The cT Programming Language]&lt;br /&gt;
&lt;br /&gt;
[https://wiki.python.org/moin/VPython/ VPython - Python Wiki]&lt;br /&gt;
&lt;br /&gt;
[http://www.nsf.gov/awardsearch/showAward?AWD_ID=0237132 VPython NSF Award]&lt;br /&gt;
&lt;br /&gt;
[[Category:VPython]]&lt;/div&gt;</summary>
		<author><name>Smaji7</name></author>
	</entry>
</feed>