<?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=Mmorris83</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=Mmorris83"/>
	<link rel="alternate" type="text/html" href="http://www.physicsbook.gatech.edu/Special:Contributions/Mmorris83"/>
	<updated>2026-05-03T10:30:32Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.42.7</generator>
	<entry>
		<id>http://www.physicsbook.gatech.edu/index.php?title=GlowScript&amp;diff=38310</id>
		<title>GlowScript</title>
		<link rel="alternate" type="text/html" href="http://www.physicsbook.gatech.edu/index.php?title=GlowScript&amp;diff=38310"/>
		<updated>2019-11-25T04:51:16Z</updated>

		<summary type="html">&lt;p&gt;Mmorris83: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;GlowScript IDE is an environment where people can create 3D animations and share them on web.&amp;lt;br&amp;gt;&lt;br /&gt;
Scripts can be written in VPython.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Commands ==&lt;br /&gt;
&lt;br /&gt;
=== Header ===&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;b&amp;gt;GlowScript 2.7 VPython&amp;lt;/b&amp;gt; is required in header to run Vpython.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;GlowScript 2.7 JavaScript&amp;lt;/b&amp;gt; is required in header to run javascript.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Initialize new Variables ===&lt;br /&gt;
----&lt;br /&gt;
Use &amp;lt;b&amp;gt;var&amp;lt;/b&amp;gt; and assign values.&amp;lt;br&amp;gt;&lt;br /&gt;
 var x, y&lt;br /&gt;
 x = 2&lt;br /&gt;
 y = 3&lt;br /&gt;
&lt;br /&gt;
Unlike Java, with Python there is no need to put semi-colon in the end of a line.&lt;br /&gt;
&lt;br /&gt;
=== 3D Objects ===&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;b&amp;gt;Arrow&amp;lt;/b&amp;gt;&lt;br /&gt;
 newArrow = arrow(pos=vec(x0, y0, z0), shaftwidth=1, axis_and_length=vec(x1, y1, z1))&lt;br /&gt;
This creates arrow that starts at point &amp;lt;x0, y0, z0&amp;gt; that points &amp;lt;x1, y1, z1&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Box&amp;lt;/b&amp;gt;&lt;br /&gt;
 newBox = box(pos=vec(x0, y0, z0), size=vec(L, H, W))&lt;br /&gt;
This creates a box with a center &amp;lt;x0, y0, z0&amp;gt; and with size &amp;lt;L, H, W&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Sphere&amp;lt;/b&amp;gt;&lt;br /&gt;
 newSphere = sphere(pos=vec(x0, y0, z0), size=vec(x1, y1, z1) )&lt;br /&gt;
This creates a box with a center &amp;lt;x0, y0, z0&amp;gt; and with size &amp;lt;x1, y1, z1&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can learn more by clicking this. [https://www.glowscript.org/docs/GlowScriptDocs/index.html]&lt;br /&gt;
&lt;br /&gt;
=== Customizing Objects ===&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;b&amp;gt;Color&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
There are 10 default colors that can be used.&lt;br /&gt;
 color.red, color.yellow, color.green, color.orange&lt;br /&gt;
 color.blue, color.cyan, color.magenta, color.purple&lt;br /&gt;
 color.black, color.white&lt;br /&gt;
Colors can be customized by user by using following code.&lt;br /&gt;
 vec(1, 0.5, 0.3)&lt;br /&gt;
In this case, R is 1, G = 0.7, and B = 0.2, which has color of pastel orange.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Animation Speed&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
 rate(50)&lt;br /&gt;
This line will halt each computations to have interval of 1.0/50.0 second.&lt;br /&gt;
&lt;br /&gt;
== Supported Environments ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Browsers&amp;lt;/b&amp;gt;: Chrome, Firefox, Safari, Internet Explorer, and Edge.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;Devices&amp;lt;/b&amp;gt;: Most smart devices running Android or iOS.&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Mmorris83</name></author>
	</entry>
	<entry>
		<id>http://www.physicsbook.gatech.edu/index.php?title=Python_Syntax&amp;diff=38152</id>
		<title>Python Syntax</title>
		<link rel="alternate" type="text/html" href="http://www.physicsbook.gatech.edu/index.php?title=Python_Syntax&amp;diff=38152"/>
		<updated>2019-11-24T21:27:52Z</updated>

		<summary type="html">&lt;p&gt;Mmorris83: /* Equal Signs */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&#039;&#039;&#039;Claimed by Miriam Morris for Fall 2019&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==The Main Idea==&lt;br /&gt;
VPython is an extension of the Python programming language that contains a 3D graphics module called Visual, which allows users to create simple simulations of physics problems. Its primary use is for educational purposes, although it has been used in research before in the past. Although it is slightly different from the actual Python program, it is similar enough for the purpose of this class. Most of the labs done this year will be done using the vPython program.&lt;br /&gt;
&lt;br /&gt;
==Downloading vPython==&lt;br /&gt;
In all cases you will need to have Python 2.7.9 installed. Future versions may also work, but be warned that it may cause VPython to behave erratically.&lt;br /&gt;
&lt;br /&gt;
[http://vpython.org/contents/download_windows.html For Windows]&lt;br /&gt;
&lt;br /&gt;
[http://vpython.org/contents/download_mac.html For Mac]&lt;br /&gt;
&lt;br /&gt;
[http://vpython.org/contents/download_linux.html For Linux]&lt;br /&gt;
&lt;br /&gt;
Note for Linux: You can only install Classic VPython, which is no longer supported and may be missing some features and bug fixes that are present in the current version of VPython.&lt;br /&gt;
&lt;br /&gt;
Alternatively, you can use GlowScript, a virtual environment that allows you to execute VPython code in your browser. You can create an account at [http://www.glowscript.org/ http://www.glowscript.org/]. Although this is useful, keep in mind that not all labs can be completed through GlowScript.&lt;br /&gt;
&lt;br /&gt;
=Python Basics=&lt;br /&gt;
&lt;br /&gt;
==Variables==&lt;br /&gt;
&lt;br /&gt;
A variable is an item within your code that has information stored in it. This information can be a number, a string of letters, or anything really. &amp;lt;br&amp;gt;&lt;br /&gt;
Variables are identified by a name. The names of your variables should be simple, but logical. Avoid names that include spaces or dots, because Python does not like this syntax. Rather, it is best to separate two words in a variable name by capitalizing the second word, such as “myVariable”, or an underscore, such as “my_variable”. &amp;lt;br&amp;gt;&lt;br /&gt;
Storing items as a variable allows for easy access when they are needed later in your program. &amp;lt;br&amp;gt;&lt;br /&gt;
One last thing that is important to note is that you can reassign variables. For example, the code below is completely valid.&amp;lt;br&amp;gt;&lt;br /&gt;
 x = 5&lt;br /&gt;
 x = x + 2&lt;br /&gt;
When this code is finished running, x will equal 7. Although this is counterintuitive at first, it’s easy to get used to.&lt;br /&gt;
&lt;br /&gt;
==Comments==&lt;br /&gt;
&lt;br /&gt;
Comments are useful when you want to include a note or a quick explanation in your code that will make it easier to understand later. Comments are sections of code that the computer will skip in execution, so it will not actually be executed when your program runs. There are two types of comments that Python uses, single line comments and multi-line comments.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Single Line Comments&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
To create a single line comment (the most common comments in Python) type a hash character (#) at the beginning of anything you would like to comment out. Note, when &amp;quot;#&amp;quot; is in a line of code, the rest of the code following the # will be ignored by the computer when your code runs.&lt;br /&gt;
&lt;br /&gt;
 # This is a comment.&lt;br /&gt;
 &lt;br /&gt;
 a = 4 # and so is this&lt;br /&gt;
 &lt;br /&gt;
 # b = 4 # and so is this entire line, be careful!&lt;br /&gt;
&lt;br /&gt;
Here is an example of comment use that you might see in a lab:&lt;br /&gt;
&lt;br /&gt;
 myTemp = 4 #This is the temperature in Celsius.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Multi-line Comments&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
To create a multi-line comment (usually reserved for longer explanations or instructions that cannot fit on one line) type three opening and closing quotation marks, like so:&lt;br /&gt;
&lt;br /&gt;
 &amp;quot;&amp;quot;&amp;quot; this &lt;br /&gt;
     is&lt;br /&gt;
     a&lt;br /&gt;
     multi-line&lt;br /&gt;
     comment &lt;br /&gt;
     example &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
 &amp;quot;&amp;quot;&amp;quot; this is also an example, but on only one line&amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Be careful! Unlike the single line comments, multi-line comments require a start and a stop (if you forget to close your comment or forget the third quotation mark then that will cause an error in your code).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Main Uses&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
- Longer variable explanation (units, where the data comes from, etc)&lt;br /&gt;
&lt;br /&gt;
- Comment out code (to save for later, instead of deleting it)&lt;br /&gt;
&lt;br /&gt;
- Instructions&lt;br /&gt;
&lt;br /&gt;
- Notes to self&lt;br /&gt;
&lt;br /&gt;
==Math Operations==&lt;br /&gt;
&lt;br /&gt;
Math operations are simple in Python. The simple operations, as you might expect, are as follows:&lt;br /&gt;
 #Addition: &lt;br /&gt;
 1+2 #This will equal 3.&lt;br /&gt;
 &lt;br /&gt;
 #Subtraction: &lt;br /&gt;
 2-1 #This will equal 1.&lt;br /&gt;
 &lt;br /&gt;
 #Multiplication: &lt;br /&gt;
 2*1 #This will equal 2.&lt;br /&gt;
 &lt;br /&gt;
 #Division: &lt;br /&gt;
 2/1 #This will equal 2.&lt;br /&gt;
&lt;br /&gt;
There are other operations, that you may want to pay closer attention to.&lt;br /&gt;
 &lt;br /&gt;
 #Exponentiation: &lt;br /&gt;
 2**2    #This will equal 4.&lt;br /&gt;
 &lt;br /&gt;
 #Square root: &lt;br /&gt;
 sqrt(4) #This will equal 2.&lt;br /&gt;
 &lt;br /&gt;
 #Remainder: &lt;br /&gt;
 5%4     #This will equal 1.&lt;br /&gt;
&lt;br /&gt;
==Print Function==&lt;br /&gt;
&lt;br /&gt;
In order to see any of the information we’ve listed above, you have to actually print it. For example, the code below will run but will not provide you with an output.&lt;br /&gt;
 x = 1 + 1&lt;br /&gt;
Instead, you have to print this information in order to see the answer when the code is finished running. You can do this in two ways. First, you can directly imbed the code in your print statement.&lt;br /&gt;
 print(1 + 1)&lt;br /&gt;
Or, you can create the variable and then print the variable.&lt;br /&gt;
 x = 1 + 1&lt;br /&gt;
 print(x)&lt;br /&gt;
Either one is valid!&lt;br /&gt;
If you would like to print something other than a variable, include quotations around it. For example, if you wanted to print the typical “Hello, world!”, you would code:&lt;br /&gt;
 print(“Hello, world!”)&lt;br /&gt;
The quotations are the important takeaway here.&lt;br /&gt;
&lt;br /&gt;
==Conditional==&lt;br /&gt;
A conditional involves an “if” statement. “If this thing is true, do this”, for example. Conditionals are useful in physics if you want to perform different things on a variable, depending on certain conditions.&lt;br /&gt;
 if x &amp;gt; 1:&lt;br /&gt;
 	print(“x is greater than 1”)&lt;br /&gt;
 elif x = 1:&lt;br /&gt;
 	print(“x is equal to 1”)&lt;br /&gt;
 else:&lt;br /&gt;
 	print(“x is less than 1”)&lt;br /&gt;
Above is the typical syntax you would see for a conditional. Notice the conditional starts with an if statement, followed by a colon. The next line is indented, and then tells that if statement what to do if the if statement is true. If it is not true, it moves on to the elif statement. Elif statements are used after if statements, but when there is still an if statement involved. There can be endless elif statements. Notice this uses the same syntax as the regular if statement. Lastly, if neither the if nor the elif statement(s) are true, there is an else statement. This will print if nothing above was true.&lt;br /&gt;
&lt;br /&gt;
==Loop==&lt;br /&gt;
A loop iterates through each item in a list or range. Loops can be useful in physics because they are vital to update equations. Loops will automatically update the information for you, rather than having to write out the long iterative process yourself. Below are examples of for loops and while loops.&lt;br /&gt;
 for i in range(1,11):&lt;br /&gt;
 	print(i)&lt;br /&gt;
The statement above will print:&lt;br /&gt;
 1&lt;br /&gt;
 2&lt;br /&gt;
 3&lt;br /&gt;
 4&lt;br /&gt;
 5&lt;br /&gt;
 6&lt;br /&gt;
 7&lt;br /&gt;
 8&lt;br /&gt;
 9&lt;br /&gt;
 10&lt;br /&gt;
Notice it does not print 11. When inputting a range in Python, the last number is not included. Notice how the for loop states “for”, and then a variable, and then a range, and then a colon. This is then followed by a statement that tells what to do for each iteration in the loop. Notice it is indented!&lt;br /&gt;
 while i &amp;gt; 1:&lt;br /&gt;
 	print(i)&lt;br /&gt;
This is an example of a while loop. While i is greater than 1, the code will print i. The syntax is similar to the for loop.&lt;br /&gt;
&lt;br /&gt;
==Equal Signs==&lt;br /&gt;
&lt;br /&gt;
“=” and “==” mean two different things in Python. When assigning a variable to a value, you use one equal sign:&lt;br /&gt;
 x = 2&lt;br /&gt;
However, when you are using it to check if something is equal to another thing (i.e. in an if statement), you use two equal signs:&lt;br /&gt;
 if x == 2:&lt;br /&gt;
 	print(“x equals 2)&lt;br /&gt;
&lt;br /&gt;
=VPython Basics=&lt;br /&gt;
&lt;br /&gt;
In this section we will analyze some of the objects utilized by VPython. Each object is more or less self-explanatory with equally clear fields within.&lt;br /&gt;
&lt;br /&gt;
==Starting Your VPython Program==&lt;br /&gt;
To begin with, note that every VPython program must begin with these two lines of code:&lt;br /&gt;
 from__future__ import division&lt;br /&gt;
 from visual import*&lt;br /&gt;
    &lt;br /&gt;
The scene, or visual where you see your code occur, has a width and a height. You can alter them, as seen below.&lt;br /&gt;
 scene.width = 1024&lt;br /&gt;
 scene.height = 760&lt;br /&gt;
&lt;br /&gt;
==Vectors==&lt;br /&gt;
You can access each component of the vector with pos.x, pos.y, or pos.z, depending on which component you want. You access an object&#039;s field with a period following the variable name.&lt;br /&gt;
&lt;br /&gt;
 pos = vector(1, 2, 3)&lt;br /&gt;
 xComponent = pos.x  #This value would be 1&lt;br /&gt;
 yComponent = pos.y  #This value would be 2&lt;br /&gt;
 zComponent = pos.z. #This value would be 3&lt;br /&gt;
&lt;br /&gt;
You can add two or more vectors together and you can multiply a vector by a scalar. Keep in mind you cannot add a vector and a scalar.&lt;br /&gt;
&lt;br /&gt;
 #Adding&lt;br /&gt;
 A = vector(1, 2, 3)&lt;br /&gt;
 B = vector(4, 5, 6)&lt;br /&gt;
 C = A + B  # The value of C is now (5, 7, 9)&lt;br /&gt;
 &lt;br /&gt;
 # Multiplying&lt;br /&gt;
 D = 5 * C. # The value of D is now (25, 35, 45)&lt;br /&gt;
&lt;br /&gt;
To get the magnitude of or to normalize a vector, use the appropriate function.&lt;br /&gt;
&lt;br /&gt;
 initialPos = vector(10, 3, 0)&lt;br /&gt;
 finalPos = vector(30, 15, 0)&lt;br /&gt;
 deltaR = finalPos - initialPos # -&amp;gt; vector(20, 12, 0)&lt;br /&gt;
 rMag = mag(finalPos)&lt;br /&gt;
 rHat = norm(finalPos)&lt;br /&gt;
 errorDemo = magR + finalPos # -&amp;gt; error; causes your program to crash&lt;br /&gt;
&lt;br /&gt;
==Shapes==&lt;br /&gt;
&lt;br /&gt;
There are a number of different shapes you can create for visual reference in the vPython program. These will be used quite frequently in lab to observe things like momentum, force, etc. If you were to make, say, a ball, you would want to draw a sphere. It has a position field, a radius field, and a color field. When creating a new instance of an object, each field is comma separated. You access each field the same way as we did with the position vector.&lt;br /&gt;
 ball = sphere(pos = vector(10, 10, 10), radius = 9e2, color = color.red)&lt;br /&gt;
 ballColor = ball.color&lt;br /&gt;
 ballPos = ball.pos&lt;br /&gt;
 ballRadius = ball.radius&lt;br /&gt;
&lt;br /&gt;
You can draw arrows. These also have a color and position field, but instead of a radius, they have an axis that determines their length. These arrows can be used to represent the magnitude of the force or the momentum or anything else the lab asks you to make. &lt;br /&gt;
 velocityArrow = arrow(color = color.blue, pos = vector(-10, -10, -10), axis = velocity * vScale)&lt;br /&gt;
&lt;br /&gt;
There are also boxes. They have a position vector and a size vector.&lt;br /&gt;
 myBox = box(pos = vector(50, 50, 50), size = vector(20, 15, 12))&lt;br /&gt;
&lt;br /&gt;
You can draw helixes, which are useful for depicting springs. They have a position field, a color field, a thickness field, a radius field, and a field for the number of coils.&lt;br /&gt;
 spring = helix(pos=ceiling.pos, color=color.cyan, thickness=.003, coils=40, radius=0.015)&lt;br /&gt;
&lt;br /&gt;
==Tracing==&lt;br /&gt;
&lt;br /&gt;
If you want to trace a moving object, you can have a curve follow it by adding to it every time step. This will show the entire path the object has traveled during the simulation.&lt;br /&gt;
 posTrace = curve(color = color.yellow)&lt;br /&gt;
 trail.append(ball.pos)&lt;br /&gt;
&lt;br /&gt;
==Graphs==&lt;br /&gt;
&lt;br /&gt;
You also have the option of making graphs as your program progresses; this is particularly useful for potential vs kinetic energy.&lt;br /&gt;
 Kgraph = gcurve(color = color.cyan)&lt;br /&gt;
 Ugraph = gcurve(color = color.yellow)&lt;br /&gt;
 KplusUgraph = gcurve(color = color.red)&lt;br /&gt;
 # For each time step...&lt;br /&gt;
 Kgraph.plot(pos = (t, Kenergy))&lt;br /&gt;
 Ugraph.plot(pos = (t, Uenergy))&lt;br /&gt;
 KplusUgraph.plot(pos = (t, Kenergy + Uenergy))&lt;br /&gt;
&lt;br /&gt;
By updating the fields of whatever objects you decide to use and by using any intermediate variables necessary, you&#039;re able to draw and compute what you&#039;ll need for this course.&lt;/div&gt;</summary>
		<author><name>Mmorris83</name></author>
	</entry>
	<entry>
		<id>http://www.physicsbook.gatech.edu/index.php?title=GlowScript&amp;diff=38151</id>
		<title>GlowScript</title>
		<link rel="alternate" type="text/html" href="http://www.physicsbook.gatech.edu/index.php?title=GlowScript&amp;diff=38151"/>
		<updated>2019-11-24T21:26:27Z</updated>

		<summary type="html">&lt;p&gt;Mmorris83: /* Initialize new Variables */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&#039;&#039;&#039;Claimed by Miriam Morris for Fall 2019&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
GlowScript IDE is an environment where people can create 3D animations and share them on web.&amp;lt;br&amp;gt;&lt;br /&gt;
Scripts can be written in VPython.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Commands ==&lt;br /&gt;
&lt;br /&gt;
=== Header ===&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;b&amp;gt;GlowScript 2.7 VPython&amp;lt;/b&amp;gt; is required in header to run Vpython.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;GlowScript 2.7 JavaScript&amp;lt;/b&amp;gt; is required in header to run javascript.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Initialize new Variables ===&lt;br /&gt;
----&lt;br /&gt;
Use &amp;lt;b&amp;gt;var&amp;lt;/b&amp;gt; and assign values.&amp;lt;br&amp;gt;&lt;br /&gt;
 var x, y&lt;br /&gt;
 x = 2&lt;br /&gt;
 y = 3&lt;br /&gt;
&lt;br /&gt;
Unlike Java, with Python there is no need to put semi-colon in the end of a line.&lt;br /&gt;
&lt;br /&gt;
=== 3D Objects ===&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;b&amp;gt;Arrow&amp;lt;/b&amp;gt;&lt;br /&gt;
 newArrow = arrow(pos=vec(x0, y0, z0), shaftwidth=1, axis_and_length=vec(x1, y1, z1))&lt;br /&gt;
This creates arrow that starts at point &amp;lt;x0, y0, z0&amp;gt; that points &amp;lt;x1, y1, z1&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Box&amp;lt;/b&amp;gt;&lt;br /&gt;
 newBox = box(pos=vec(x0, y0, z0), size=vec(L, H, W))&lt;br /&gt;
This creates a box with a center &amp;lt;x0, y0, z0&amp;gt; and with size &amp;lt;L, H, W&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Sphere&amp;lt;/b&amp;gt;&lt;br /&gt;
 newSphere = sphere(pos=vec(x0, y0, z0), size=vec(x1, y1, z1) )&lt;br /&gt;
This creates a box with a center &amp;lt;x0, y0, z0&amp;gt; and with size &amp;lt;x1, y1, z1&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can learn more by clicking this. [https://www.glowscript.org/docs/GlowScriptDocs/index.html]&lt;br /&gt;
&lt;br /&gt;
=== Customizing Objects ===&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;b&amp;gt;Color&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
There are 10 default colors that can be used.&lt;br /&gt;
 color.red, color.yellow, color.green, color.orange&lt;br /&gt;
 color.blue, color.cyan, color.magenta, color.purple&lt;br /&gt;
 color.black, color.white&lt;br /&gt;
Colors can be customized by user by using following code.&lt;br /&gt;
 vec(1, 0.5, 0.3)&lt;br /&gt;
In this case, R is 1, G = 0.7, and B = 0.2, which has color of pastel orange.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Animation Speed&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
 rate(50)&lt;br /&gt;
This line will halt each computations to have interval of 1.0/50.0 second.&lt;br /&gt;
&lt;br /&gt;
== Supported Environments ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Browsers&amp;lt;/b&amp;gt;: Chrome, Firefox, Safari, Internet Explorer, and Edge.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;Devices&amp;lt;/b&amp;gt;: Most smart devices running Android or iOS.&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Mmorris83</name></author>
	</entry>
	<entry>
		<id>http://www.physicsbook.gatech.edu/index.php?title=Python_Syntax&amp;diff=38119</id>
		<title>Python Syntax</title>
		<link rel="alternate" type="text/html" href="http://www.physicsbook.gatech.edu/index.php?title=Python_Syntax&amp;diff=38119"/>
		<updated>2019-11-24T06:24:05Z</updated>

		<summary type="html">&lt;p&gt;Mmorris83: /* Math Operations */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&#039;&#039;&#039;Claimed by Miriam Morris for Fall 2019&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==The Main Idea==&lt;br /&gt;
VPython is an extension of the Python programming language that contains a 3D graphics module called Visual, which allows users to create simple simulations of physics problems. Its primary use is for educational purposes, although it has been used in research before in the past. Although it is slightly different from the actual Python program, it is similar enough for the purpose of this class. Most of the labs done this year will be done using the vPython program.&lt;br /&gt;
&lt;br /&gt;
==Downloading vPython==&lt;br /&gt;
In all cases you will need to have Python 2.7.9 installed. Future versions may also work, but be warned that it may cause VPython to behave erratically.&lt;br /&gt;
&lt;br /&gt;
[http://vpython.org/contents/download_windows.html For Windows]&lt;br /&gt;
&lt;br /&gt;
[http://vpython.org/contents/download_mac.html For Mac]&lt;br /&gt;
&lt;br /&gt;
[http://vpython.org/contents/download_linux.html For Linux]&lt;br /&gt;
&lt;br /&gt;
Note for Linux: You can only install Classic VPython, which is no longer supported and may be missing some features and bug fixes that are present in the current version of VPython.&lt;br /&gt;
&lt;br /&gt;
Alternatively, you can use GlowScript, a virtual environment that allows you to execute VPython code in your browser. You can create an account at [http://www.glowscript.org/ http://www.glowscript.org/]. Although this is useful, keep in mind that not all labs can be completed through GlowScript.&lt;br /&gt;
&lt;br /&gt;
=Python Basics=&lt;br /&gt;
&lt;br /&gt;
==Variables==&lt;br /&gt;
&lt;br /&gt;
A variable is an item within your code that has information stored in it. This information can be a number, a string of letters, or anything really. &amp;lt;br&amp;gt;&lt;br /&gt;
Variables are identified by a name. The names of your variables should be simple, but logical. Avoid names that include spaces or dots, because Python does not like this syntax. Rather, it is best to separate two words in a variable name by capitalizing the second word, such as “myVariable”, or an underscore, such as “my_variable”. &amp;lt;br&amp;gt;&lt;br /&gt;
Storing items as a variable allows for easy access when they are needed later in your program. &amp;lt;br&amp;gt;&lt;br /&gt;
One last thing that is important to note is that you can reassign variables. For example, the code below is completely valid.&amp;lt;br&amp;gt;&lt;br /&gt;
 x = 5&lt;br /&gt;
 x = x + 2&lt;br /&gt;
When this code is finished running, x will equal 7. Although this is counterintuitive at first, it’s easy to get used to.&lt;br /&gt;
&lt;br /&gt;
==Comments==&lt;br /&gt;
&lt;br /&gt;
Comments are useful when you want to include a note or a quick explanation in your code that will make it easier to understand later. Comments are sections of code that the computer will skip in execution, so it will not actually be executed when your program runs. There are two types of comments that Python uses, single line comments and multi-line comments.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Single Line Comments&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
To create a single line comment (the most common comments in Python) type a hash character (#) at the beginning of anything you would like to comment out. Note, when &amp;quot;#&amp;quot; is in a line of code, the rest of the code following the # will be ignored by the computer when your code runs.&lt;br /&gt;
&lt;br /&gt;
 # This is a comment.&lt;br /&gt;
 &lt;br /&gt;
 a = 4 # and so is this&lt;br /&gt;
 &lt;br /&gt;
 # b = 4 # and so is this entire line, be careful!&lt;br /&gt;
&lt;br /&gt;
Here is an example of comment use that you might see in a lab:&lt;br /&gt;
&lt;br /&gt;
 myTemp = 4 #This is the temperature in Celsius.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Multi-line Comments&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
To create a multi-line comment (usually reserved for longer explanations or instructions that cannot fit on one line) type three opening and closing quotation marks, like so:&lt;br /&gt;
&lt;br /&gt;
 &amp;quot;&amp;quot;&amp;quot; this &lt;br /&gt;
     is&lt;br /&gt;
     a&lt;br /&gt;
     multi-line&lt;br /&gt;
     comment &lt;br /&gt;
     example &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
 &amp;quot;&amp;quot;&amp;quot; this is also an example, but on only one line&amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Be careful! Unlike the single line comments, multi-line comments require a start and a stop (if you forget to close your comment or forget the third quotation mark then that will cause an error in your code).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Main Uses&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
- Longer variable explanation (units, where the data comes from, etc)&lt;br /&gt;
&lt;br /&gt;
- Comment out code (to save for later, instead of deleting it)&lt;br /&gt;
&lt;br /&gt;
- Instructions&lt;br /&gt;
&lt;br /&gt;
- Notes to self&lt;br /&gt;
&lt;br /&gt;
==Math Operations==&lt;br /&gt;
&lt;br /&gt;
Math operations are simple in Python. The simple operations, as you might expect, are as follows:&lt;br /&gt;
 #Addition: &lt;br /&gt;
 1+2 #This will equal 3.&lt;br /&gt;
 &lt;br /&gt;
 #Subtraction: &lt;br /&gt;
 2-1 #This will equal 1.&lt;br /&gt;
 &lt;br /&gt;
 #Multiplication: &lt;br /&gt;
 2*1 #This will equal 2.&lt;br /&gt;
 &lt;br /&gt;
 #Division: &lt;br /&gt;
 2/1 #This will equal 2.&lt;br /&gt;
&lt;br /&gt;
There are other operations, that you may want to pay closer attention to.&lt;br /&gt;
 &lt;br /&gt;
 #Exponentiation: &lt;br /&gt;
 2**2    #This will equal 4.&lt;br /&gt;
 &lt;br /&gt;
 #Square root: &lt;br /&gt;
 sqrt(4) #This will equal 2.&lt;br /&gt;
 &lt;br /&gt;
 #Remainder: &lt;br /&gt;
 5%4     #This will equal 1.&lt;br /&gt;
&lt;br /&gt;
==Print Function==&lt;br /&gt;
&lt;br /&gt;
In order to see any of the information we’ve listed above, you have to actually print it. For example, the code below will run but will not provide you with an output.&lt;br /&gt;
 x = 1 + 1&lt;br /&gt;
Instead, you have to print this information in order to see the answer when the code is finished running. You can do this in two ways. First, you can directly imbed the code in your print statement.&lt;br /&gt;
 print(1 + 1)&lt;br /&gt;
Or, you can create the variable and then print the variable.&lt;br /&gt;
 x = 1 + 1&lt;br /&gt;
 print(x)&lt;br /&gt;
Either one is valid!&lt;br /&gt;
If you would like to print something other than a variable, include quotations around it. For example, if you wanted to print the typical “Hello, world!”, you would code:&lt;br /&gt;
 print(“Hello, world!”)&lt;br /&gt;
The quotations are the important takeaway here.&lt;br /&gt;
&lt;br /&gt;
==Conditional==&lt;br /&gt;
A conditional involves an “if” statement. “If this thing is true, do this”, for example. Conditionals are useful in physics if you want to perform different things on a variable, depending on certain conditions.&lt;br /&gt;
 if x &amp;gt; 1:&lt;br /&gt;
 	print(“x is greater than 1”)&lt;br /&gt;
 elif x = 1:&lt;br /&gt;
 	print(“x is equal to 1”)&lt;br /&gt;
 else:&lt;br /&gt;
 	print(“x is less than 1”)&lt;br /&gt;
Above is the typical syntax you would see for a conditional. Notice the conditional starts with an if statement, followed by a colon. The next line is indented, and then tells that if statement what to do if the if statement is true. If it is not true, it moves on to the elif statement. Elif statements are used after if statements, but when there is still an if statement involved. There can be endless elif statements. Notice this uses the same syntax as the regular if statement. Lastly, if neither the if nor the elif statement(s) are true, there is an else statement. This will print if nothing above was true.&lt;br /&gt;
&lt;br /&gt;
==Loop==&lt;br /&gt;
A loop iterates through each item in a list or range. Loops can be useful in physics because they are vital to update equations. Loops will automatically update the information for you, rather than having to write out the long iterative process yourself. Below are examples of for loops and while loops.&lt;br /&gt;
 for i in range(1,11):&lt;br /&gt;
 	print(i)&lt;br /&gt;
The statement above will print:&lt;br /&gt;
 1&lt;br /&gt;
 2&lt;br /&gt;
 3&lt;br /&gt;
 4&lt;br /&gt;
 5&lt;br /&gt;
 6&lt;br /&gt;
 7&lt;br /&gt;
 8&lt;br /&gt;
 9&lt;br /&gt;
 10&lt;br /&gt;
Notice it does not print 11. When inputting a range in Python, the last number is not included. Notice how the for loop states “for”, and then a variable, and then a range, and then a colon. This is then followed by a statement that tells what to do for each iteration in the loop. Notice it is indented!&lt;br /&gt;
 while i &amp;gt; 1:&lt;br /&gt;
 	print(i)&lt;br /&gt;
This is an example of a while loop. While i is greater than 1, the code will print i. The syntax is similar to the for loop.&lt;br /&gt;
&lt;br /&gt;
==Equal Signs==&lt;br /&gt;
&lt;br /&gt;
“=” and “==” mean two different things in Python. When setting a variable equal to something, you use one equal sign:&lt;br /&gt;
 x = 2&lt;br /&gt;
However, when you are using it in something like an if statement, use two equal signs:&lt;br /&gt;
 if x == 2:&lt;br /&gt;
 	print(“x equals 2)&lt;br /&gt;
&lt;br /&gt;
=VPython Basics=&lt;br /&gt;
&lt;br /&gt;
In this section we will analyze some of the objects utilized by VPython. Each object is more or less self-explanatory with equally clear fields within.&lt;br /&gt;
&lt;br /&gt;
==Starting Your VPython Program==&lt;br /&gt;
To begin with, note that every VPython program must begin with these two lines of code:&lt;br /&gt;
 from__future__ import division&lt;br /&gt;
 from visual import*&lt;br /&gt;
    &lt;br /&gt;
The scene, or visual where you see your code occur, has a width and a height. You can alter them, as seen below.&lt;br /&gt;
 scene.width = 1024&lt;br /&gt;
 scene.height = 760&lt;br /&gt;
&lt;br /&gt;
==Vectors==&lt;br /&gt;
You can access each component of the vector with pos.x, pos.y, or pos.z, depending on which component you want. You access an object&#039;s field with a period following the variable name.&lt;br /&gt;
&lt;br /&gt;
 pos = vector(1, 2, 3)&lt;br /&gt;
 xComponent = pos.x  #This value would be 1&lt;br /&gt;
 yComponent = pos.y  #This value would be 2&lt;br /&gt;
 zComponent = pos.z. #This value would be 3&lt;br /&gt;
&lt;br /&gt;
You can add two or more vectors together and you can multiply a vector by a scalar. Keep in mind you cannot add a vector and a scalar.&lt;br /&gt;
&lt;br /&gt;
 #Adding&lt;br /&gt;
 A = vector(1, 2, 3)&lt;br /&gt;
 B = vector(4, 5, 6)&lt;br /&gt;
 C = A + B  # The value of C is now (5, 7, 9)&lt;br /&gt;
 &lt;br /&gt;
 # Multiplying&lt;br /&gt;
 D = 5 * C. # The value of D is now (25, 35, 45)&lt;br /&gt;
&lt;br /&gt;
To get the magnitude of or to normalize a vector, use the appropriate function.&lt;br /&gt;
&lt;br /&gt;
 initialPos = vector(10, 3, 0)&lt;br /&gt;
 finalPos = vector(30, 15, 0)&lt;br /&gt;
 deltaR = finalPos - initialPos # -&amp;gt; vector(20, 12, 0)&lt;br /&gt;
 rMag = mag(finalPos)&lt;br /&gt;
 rHat = norm(finalPos)&lt;br /&gt;
 errorDemo = magR + finalPos # -&amp;gt; error; causes your program to crash&lt;br /&gt;
&lt;br /&gt;
==Shapes==&lt;br /&gt;
&lt;br /&gt;
There are a number of different shapes you can create for visual reference in the vPython program. These will be used quite frequently in lab to observe things like momentum, force, etc. If you were to make, say, a ball, you would want to draw a sphere. It has a position field, a radius field, and a color field. When creating a new instance of an object, each field is comma separated. You access each field the same way as we did with the position vector.&lt;br /&gt;
 ball = sphere(pos = vector(10, 10, 10), radius = 9e2, color = color.red)&lt;br /&gt;
 ballColor = ball.color&lt;br /&gt;
 ballPos = ball.pos&lt;br /&gt;
 ballRadius = ball.radius&lt;br /&gt;
&lt;br /&gt;
You can draw arrows. These also have a color and position field, but instead of a radius, they have an axis that determines their length. These arrows can be used to represent the magnitude of the force or the momentum or anything else the lab asks you to make. &lt;br /&gt;
 velocityArrow = arrow(color = color.blue, pos = vector(-10, -10, -10), axis = velocity * vScale)&lt;br /&gt;
&lt;br /&gt;
There are also boxes. They have a position vector and a size vector.&lt;br /&gt;
 myBox = box(pos = vector(50, 50, 50), size = vector(20, 15, 12))&lt;br /&gt;
&lt;br /&gt;
You can draw helixes, which are useful for depicting springs. They have a position field, a color field, a thickness field, a radius field, and a field for the number of coils.&lt;br /&gt;
 spring = helix(pos=ceiling.pos, color=color.cyan, thickness=.003, coils=40, radius=0.015)&lt;br /&gt;
&lt;br /&gt;
==Tracing==&lt;br /&gt;
&lt;br /&gt;
If you want to trace a moving object, you can have a curve follow it by adding to it every time step. This will show the entire path the object has traveled during the simulation.&lt;br /&gt;
 posTrace = curve(color = color.yellow)&lt;br /&gt;
 trail.append(ball.pos)&lt;br /&gt;
&lt;br /&gt;
==Graphs==&lt;br /&gt;
&lt;br /&gt;
You also have the option of making graphs as your program progresses; this is particularly useful for potential vs kinetic energy.&lt;br /&gt;
 Kgraph = gcurve(color = color.cyan)&lt;br /&gt;
 Ugraph = gcurve(color = color.yellow)&lt;br /&gt;
 KplusUgraph = gcurve(color = color.red)&lt;br /&gt;
 # For each time step...&lt;br /&gt;
 Kgraph.plot(pos = (t, Kenergy))&lt;br /&gt;
 Ugraph.plot(pos = (t, Uenergy))&lt;br /&gt;
 KplusUgraph.plot(pos = (t, Kenergy + Uenergy))&lt;br /&gt;
&lt;br /&gt;
By updating the fields of whatever objects you decide to use and by using any intermediate variables necessary, you&#039;re able to draw and compute what you&#039;ll need for this course.&lt;/div&gt;</summary>
		<author><name>Mmorris83</name></author>
	</entry>
	<entry>
		<id>http://www.physicsbook.gatech.edu/index.php?title=Python_Syntax&amp;diff=38032</id>
		<title>Python Syntax</title>
		<link rel="alternate" type="text/html" href="http://www.physicsbook.gatech.edu/index.php?title=Python_Syntax&amp;diff=38032"/>
		<updated>2019-10-22T06:56:13Z</updated>

		<summary type="html">&lt;p&gt;Mmorris83: /* Vectors */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&#039;&#039;&#039;Claimed by Miriam Morris for Fall 2019&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==The Main Idea==&lt;br /&gt;
VPython is an extension of the Python programming language that contains a 3D graphics module called Visual, which allows users to create simple simulations of physics problems. Its primary use is for educational purposes, although it has been used in research before in the past. Although it is slightly different from the actual Python program, it is similar enough for the purpose of this class. Most of the labs done this year will be done using the vPython program.&lt;br /&gt;
&lt;br /&gt;
==Downloading vPython==&lt;br /&gt;
In all cases you will need to have Python 2.7.9 installed. Future versions may also work, but be warned that it may cause VPython to behave erratically.&lt;br /&gt;
&lt;br /&gt;
[http://vpython.org/contents/download_windows.html For Windows]&lt;br /&gt;
&lt;br /&gt;
[http://vpython.org/contents/download_mac.html For Mac]&lt;br /&gt;
&lt;br /&gt;
[http://vpython.org/contents/download_linux.html For Linux]&lt;br /&gt;
&lt;br /&gt;
Note for Linux: You can only install Classic VPython, which is no longer supported and may be missing some features and bug fixes that are present in the current version of VPython.&lt;br /&gt;
&lt;br /&gt;
Alternatively, you can use GlowScript, a virtual environment that allows you to execute VPython code in your browser. You can create an account at [http://www.glowscript.org/ http://www.glowscript.org/]. Although this is useful, keep in mind that not all labs can be completed through GlowScript.&lt;br /&gt;
&lt;br /&gt;
=Python Basics=&lt;br /&gt;
&lt;br /&gt;
==Variables==&lt;br /&gt;
&lt;br /&gt;
A variable is an item within your code that has information stored in it. This information can be a number, a string of letters, or anything really. &amp;lt;br&amp;gt;&lt;br /&gt;
Variables are identified by a name. The names of your variables should be simple, but logical. Avoid names that include spaces or dots, because Python does not like this syntax. Rather, it is best to separate two words in a variable name by capitalizing the second word, such as “myVariable”, or an underscore, such as “my_variable”. &amp;lt;br&amp;gt;&lt;br /&gt;
Storing items as a variable allows for easy access when they are needed later in your program. &amp;lt;br&amp;gt;&lt;br /&gt;
One last thing that is important to note is that you can reassign variables. For example, the code below is completely valid.&amp;lt;br&amp;gt;&lt;br /&gt;
 x = 5&lt;br /&gt;
 x = x + 2&lt;br /&gt;
When this code is finished running, x will equal 7. Although this is counterintuitive at first, it’s easy to get used to.&lt;br /&gt;
&lt;br /&gt;
==Comments==&lt;br /&gt;
&lt;br /&gt;
Comments are useful when you want to include a note or a quick explanation in your code that will make it easier to understand later. Comments are sections of code that the computer will skip in execution, so it will not actually be executed when your program runs. There are two types of comments that Python uses, single line comments and multi-line comments.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Single Line Comments&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
To create a single line comment (the most common comments in Python) type a hash character (#) at the beginning of anything you would like to comment out. Note, when &amp;quot;#&amp;quot; is in a line of code, the rest of the code following the # will be ignored by the computer when your code runs.&lt;br /&gt;
&lt;br /&gt;
 # This is a comment.&lt;br /&gt;
 &lt;br /&gt;
 a = 4 # and so is this&lt;br /&gt;
 &lt;br /&gt;
 # b = 4 # and so is this entire line, be careful!&lt;br /&gt;
&lt;br /&gt;
Here is an example of comment use that you might see in a lab:&lt;br /&gt;
&lt;br /&gt;
 myTemp = 4 #This is the temperature in Celsius.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Multi-line Comments&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
To create a multi-line comment (usually reserved for longer explanations or instructions that cannot fit on one line) type three opening and closing quotation marks, like so:&lt;br /&gt;
&lt;br /&gt;
 &amp;quot;&amp;quot;&amp;quot; this &lt;br /&gt;
     is&lt;br /&gt;
     a&lt;br /&gt;
     multi-line&lt;br /&gt;
     comment &lt;br /&gt;
     example &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
 &amp;quot;&amp;quot;&amp;quot; this is also an example, but on only one line&amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Be careful! Unlike the single line comments, multi-line comments require a start and a stop (if you forget to close your comment or forget the third quotation mark then that will cause an error in your code).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Main Uses&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
- Longer variable explanation (units, where the data comes from, etc)&lt;br /&gt;
&lt;br /&gt;
- Comment out code (to save for later, instead of deleting it)&lt;br /&gt;
&lt;br /&gt;
- Instructions&lt;br /&gt;
&lt;br /&gt;
- Notes to self&lt;br /&gt;
&lt;br /&gt;
==Math Operations==&lt;br /&gt;
&lt;br /&gt;
Math operations are simple in Python. The simple operations, as you might expect, are as follows:&lt;br /&gt;
 #Addition: &lt;br /&gt;
 1+2 #This will equal 3.&lt;br /&gt;
 &lt;br /&gt;
 #Subtraction: &lt;br /&gt;
 2-1 #This will equal 1.&lt;br /&gt;
 &lt;br /&gt;
 #Multiplication: &lt;br /&gt;
 2*1 #This will equal 2.&lt;br /&gt;
 &lt;br /&gt;
 #Division: &lt;br /&gt;
 2/1 #This will equal 2.&lt;br /&gt;
&lt;br /&gt;
There are other operations, that you may want to pay closer attention to.&lt;br /&gt;
 &lt;br /&gt;
 #Exponentiation: &lt;br /&gt;
 2**2 #This will equal 4.&lt;br /&gt;
 &lt;br /&gt;
 #Square root: &lt;br /&gt;
 sqrt(4) #This will equal 2.&lt;br /&gt;
 &lt;br /&gt;
 #Remainder: &lt;br /&gt;
 5%4 #This will equal 1.&lt;br /&gt;
&lt;br /&gt;
==Print Function==&lt;br /&gt;
&lt;br /&gt;
In order to see any of the information we’ve listed above, you have to actually print it. For example, the code below will run but will not provide you with an output.&lt;br /&gt;
 x = 1 + 1&lt;br /&gt;
Instead, you have to print this information in order to see the answer when the code is finished running. You can do this in two ways. First, you can directly imbed the code in your print statement.&lt;br /&gt;
 print(1 + 1)&lt;br /&gt;
Or, you can create the variable and then print the variable.&lt;br /&gt;
 x = 1 + 1&lt;br /&gt;
 print(x)&lt;br /&gt;
Either one is valid!&lt;br /&gt;
If you would like to print something other than a variable, include quotations around it. For example, if you wanted to print the typical “Hello, world!”, you would code:&lt;br /&gt;
 print(“Hello, world!”)&lt;br /&gt;
The quotations are the important takeaway here.&lt;br /&gt;
&lt;br /&gt;
==Conditional==&lt;br /&gt;
A conditional involves an “if” statement. “If this thing is true, do this”, for example. Conditionals are useful in physics if you want to perform different things on a variable, depending on certain conditions.&lt;br /&gt;
 if x &amp;gt; 1:&lt;br /&gt;
 	print(“x is greater than 1”)&lt;br /&gt;
 elif x = 1:&lt;br /&gt;
 	print(“x is equal to 1”)&lt;br /&gt;
 else:&lt;br /&gt;
 	print(“x is less than 1”)&lt;br /&gt;
Above is the typical syntax you would see for a conditional. Notice the conditional starts with an if statement, followed by a colon. The next line is indented, and then tells that if statement what to do if the if statement is true. If it is not true, it moves on to the elif statement. Elif statements are used after if statements, but when there is still an if statement involved. There can be endless elif statements. Notice this uses the same syntax as the regular if statement. Lastly, if neither the if nor the elif statement(s) are true, there is an else statement. This will print if nothing above was true.&lt;br /&gt;
&lt;br /&gt;
==Loop==&lt;br /&gt;
A loop iterates through each item in a list or range. Loops can be useful in physics because they are vital to update equations. Loops will automatically update the information for you, rather than having to write out the long iterative process yourself. Below are examples of for loops and while loops.&lt;br /&gt;
 for i in range(1,11):&lt;br /&gt;
 	print(i)&lt;br /&gt;
The statement above will print:&lt;br /&gt;
 1&lt;br /&gt;
 2&lt;br /&gt;
 3&lt;br /&gt;
 4&lt;br /&gt;
 5&lt;br /&gt;
 6&lt;br /&gt;
 7&lt;br /&gt;
 8&lt;br /&gt;
 9&lt;br /&gt;
 10&lt;br /&gt;
Notice it does not print 11. When inputting a range in Python, the last number is not included. Notice how the for loop states “for”, and then a variable, and then a range, and then a colon. This is then followed by a statement that tells what to do for each iteration in the loop. Notice it is indented!&lt;br /&gt;
 while i &amp;gt; 1:&lt;br /&gt;
 	print(i)&lt;br /&gt;
This is an example of a while loop. While i is greater than 1, the code will print i. The syntax is similar to the for loop.&lt;br /&gt;
&lt;br /&gt;
==Equal Signs==&lt;br /&gt;
&lt;br /&gt;
“=” and “==” mean two different things in Python. When setting a variable equal to something, you use one equal sign:&lt;br /&gt;
 x = 2&lt;br /&gt;
However, when you are using it in something like an if statement, use two equal signs:&lt;br /&gt;
 if x == 2:&lt;br /&gt;
 	print(“x equals 2)&lt;br /&gt;
&lt;br /&gt;
=VPython Basics=&lt;br /&gt;
&lt;br /&gt;
In this section we will analyze some of the objects utilized by VPython. Each object is more or less self-explanatory with equally clear fields within.&lt;br /&gt;
&lt;br /&gt;
==Starting Your VPython Program==&lt;br /&gt;
To begin with, note that every VPython program must begin with these two lines of code:&lt;br /&gt;
 from__future__ import division&lt;br /&gt;
 from visual import*&lt;br /&gt;
    &lt;br /&gt;
The scene, or visual where you see your code occur, has a width and a height. You can alter them, as seen below.&lt;br /&gt;
 scene.width = 1024&lt;br /&gt;
 scene.height = 760&lt;br /&gt;
&lt;br /&gt;
==Vectors==&lt;br /&gt;
You can access each component of the vector with pos.x, pos.y, or pos.z, depending on which component you want. You access an object&#039;s field with a period following the variable name.&lt;br /&gt;
&lt;br /&gt;
 pos = vector(1, 2, 3)&lt;br /&gt;
 xComponent = pos.x  #This value would be 1&lt;br /&gt;
 yComponent = pos.y  #This value would be 2&lt;br /&gt;
 zComponent = pos.z. #This value would be 3&lt;br /&gt;
&lt;br /&gt;
You can add two or more vectors together and you can multiply a vector by a scalar. Keep in mind you cannot add a vector and a scalar.&lt;br /&gt;
&lt;br /&gt;
 #Adding&lt;br /&gt;
 A = vector(1, 2, 3)&lt;br /&gt;
 B = vector(4, 5, 6)&lt;br /&gt;
 C = A + B  # The value of C is now (5, 7, 9)&lt;br /&gt;
 &lt;br /&gt;
 # Multiplying&lt;br /&gt;
 D = 5 * C. # The value of D is now (25, 35, 45)&lt;br /&gt;
&lt;br /&gt;
To get the magnitude of or to normalize a vector, use the appropriate function.&lt;br /&gt;
&lt;br /&gt;
 initialPos = vector(10, 3, 0)&lt;br /&gt;
 finalPos = vector(30, 15, 0)&lt;br /&gt;
 deltaR = finalPos - initialPos # -&amp;gt; vector(20, 12, 0)&lt;br /&gt;
 rMag = mag(finalPos)&lt;br /&gt;
 rHat = norm(finalPos)&lt;br /&gt;
 errorDemo = magR + finalPos # -&amp;gt; error; causes your program to crash&lt;br /&gt;
&lt;br /&gt;
==Shapes==&lt;br /&gt;
&lt;br /&gt;
There are a number of different shapes you can create for visual reference in the vPython program. These will be used quite frequently in lab to observe things like momentum, force, etc. If you were to make, say, a ball, you would want to draw a sphere. It has a position field, a radius field, and a color field. When creating a new instance of an object, each field is comma separated. You access each field the same way as we did with the position vector.&lt;br /&gt;
 ball = sphere(pos = vector(10, 10, 10), radius = 9e2, color = color.red)&lt;br /&gt;
 ballColor = ball.color&lt;br /&gt;
 ballPos = ball.pos&lt;br /&gt;
 ballRadius = ball.radius&lt;br /&gt;
&lt;br /&gt;
You can draw arrows. These also have a color and position field, but instead of a radius, they have an axis that determines their length. These arrows can be used to represent the magnitude of the force or the momentum or anything else the lab asks you to make. &lt;br /&gt;
 velocityArrow = arrow(color = color.blue, pos = vector(-10, -10, -10), axis = velocity * vScale)&lt;br /&gt;
&lt;br /&gt;
There are also boxes. They have a position vector and a size vector.&lt;br /&gt;
 myBox = box(pos = vector(50, 50, 50), size = vector(20, 15, 12))&lt;br /&gt;
&lt;br /&gt;
You can draw helixes, which are useful for depicting springs. They have a position field, a color field, a thickness field, a radius field, and a field for the number of coils.&lt;br /&gt;
 spring = helix(pos=ceiling.pos, color=color.cyan, thickness=.003, coils=40, radius=0.015)&lt;br /&gt;
&lt;br /&gt;
==Tracing==&lt;br /&gt;
&lt;br /&gt;
If you want to trace a moving object, you can have a curve follow it by adding to it every time step. This will show the entire path the object has traveled during the simulation.&lt;br /&gt;
 posTrace = curve(color = color.yellow)&lt;br /&gt;
 trail.append(ball.pos)&lt;br /&gt;
&lt;br /&gt;
==Graphs==&lt;br /&gt;
&lt;br /&gt;
You also have the option of making graphs as your program progresses; this is particularly useful for potential vs kinetic energy.&lt;br /&gt;
 Kgraph = gcurve(color = color.cyan)&lt;br /&gt;
 Ugraph = gcurve(color = color.yellow)&lt;br /&gt;
 KplusUgraph = gcurve(color = color.red)&lt;br /&gt;
 # For each time step...&lt;br /&gt;
 Kgraph.plot(pos = (t, Kenergy))&lt;br /&gt;
 Ugraph.plot(pos = (t, Uenergy))&lt;br /&gt;
 KplusUgraph.plot(pos = (t, Kenergy + Uenergy))&lt;br /&gt;
&lt;br /&gt;
By updating the fields of whatever objects you decide to use and by using any intermediate variables necessary, you&#039;re able to draw and compute what you&#039;ll need for this course.&lt;/div&gt;</summary>
		<author><name>Mmorris83</name></author>
	</entry>
	<entry>
		<id>http://www.physicsbook.gatech.edu/index.php?title=VPython_3D_Objects&amp;diff=38030</id>
		<title>VPython 3D Objects</title>
		<link rel="alternate" type="text/html" href="http://www.physicsbook.gatech.edu/index.php?title=VPython_3D_Objects&amp;diff=38030"/>
		<updated>2019-10-22T06:52:59Z</updated>

		<summary type="html">&lt;p&gt;Mmorris83: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;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. &lt;br /&gt;
&lt;br /&gt;
Before start coding, make sure to have &lt;br /&gt;
&lt;br /&gt;
 from __future__ import division&lt;br /&gt;
 from visual import *&lt;br /&gt;
&lt;br /&gt;
on the top of your script.&lt;br /&gt;
&lt;br /&gt;
This document is written based on VPython 7.&lt;br /&gt;
==List of 3D Objects==&lt;br /&gt;
===Image of Each Objects===&lt;br /&gt;
VPython is packaged with a variety of 3-Dimensional objects. By clicking each names of the objects, you can go to the official description of each objects from Glowscript.&lt;br /&gt;
The objects are listed in alphabetical order.&lt;br /&gt;
&lt;br /&gt;
[http://www.glowscript.org/docs/VPythonDocs/arrow.html Arrow]&lt;br /&gt;
[[File:RedArrow.png|thumb|none|alt=Yellow Arrow|Example arrow]]&lt;br /&gt;
&lt;br /&gt;
[http://www.glowscript.org/docs/VPythonDocs/box.html Box]&lt;br /&gt;
[[File:OrangeBox.png|thumb|none|alt=Yellow Arrow|Example box]]&lt;br /&gt;
&lt;br /&gt;
[http://www.glowscript.org/docs/VPythonDocs/cone.html Cone]&lt;br /&gt;
[[File:YellowCone.png|thumb|none|alt=Yellow Arrow|Example cone]]&lt;br /&gt;
&lt;br /&gt;
[http://www.glowscript.org/docs/VPythonDocs/curve.html Curve]&lt;br /&gt;
[[File:GreenCurve.png|thumb|none|alt=Yellow Arrow|Example curve]]&lt;br /&gt;
&lt;br /&gt;
[http://www.glowscript.org/docs/VPythonDocs/cylinder.html Cylinder]&lt;br /&gt;
[[File:CyanCylinder.png|thumb|none|alt=Yellow Arrow|Example cylinder]]&lt;br /&gt;
&lt;br /&gt;
[http://www.glowscript.org/docs/VPythonDocs/ellipsoid.html Ellipsoid]&lt;br /&gt;
[[File:BlueEllipsoid.png|thumb|none|alt=Yellow Arrow|Example ellipsoid]]&lt;br /&gt;
&lt;br /&gt;
[http://www.glowscript.org/docs/VPythonDocs/extrusion.html Extrusion]&lt;br /&gt;
[[File:MagentaExtrusion.png|thumb|none|alt=Yellow Arrow|Example extrusion]]&lt;br /&gt;
&lt;br /&gt;
[http://www.glowscript.org/docs/VPythonDocs/helix.html Helix]&lt;br /&gt;
[[File:GoldHelix.png|thumb|none|alt=Yellow Arrow|Example helix]]&lt;br /&gt;
&lt;br /&gt;
[http://www.glowscript.org/docs/VPythonDocs/label.html Label]&lt;br /&gt;
[[File:WhiteLabel.png|thumb|none|alt=Yellow Arrow|Example label]]&lt;br /&gt;
&lt;br /&gt;
[http://www.glowscript.org/docs/VPythonDocs/points.html Points]&lt;br /&gt;
[[File:IvoryPoints.png|thumb|none|alt=Yellow Arrow|Example points]]&lt;br /&gt;
&lt;br /&gt;
[http://www.glowscript.org/docs/VPythonDocs/pyramid.html Pyramid]&lt;br /&gt;
[[File:BrownPyramid.png|thumb|none|alt=Yellow Arrow|Example pyramid]]&lt;br /&gt;
&lt;br /&gt;
[http://www.glowscript.org/docs/VPythonDocs/ring.html Ring]&lt;br /&gt;
[[File:AquaMarineRing.png|thumb|none|alt=Yellow Arrow|Example ring]]&lt;br /&gt;
&lt;br /&gt;
[http://www.glowscript.org/docs/VPythonDocs/sphere.html Sphere]&lt;br /&gt;
[[File:LightGreenSphere.png|thumb|none|alt=Yellow Arrow|Example sphere]]&lt;br /&gt;
&lt;br /&gt;
[http://www.glowscript.org/docs/VPythonDocs/text.html Text]&lt;br /&gt;
[[File:KhakiText.png|thumb|none|alt=Yellow Arrow|Example text]]&lt;br /&gt;
&lt;br /&gt;
===Example Code of Each Objects ===&lt;br /&gt;
Arrow&lt;br /&gt;
 a = arrow(pos=(0,2,1),axis=(5,0,0), color = color.red)&lt;br /&gt;
&lt;br /&gt;
Box&lt;br /&gt;
 b = box(pos=(0,0,0),length=3, height=3, width=3, color = color.orange)&lt;br /&gt;
&lt;br /&gt;
Cone&lt;br /&gt;
 c = cone(pos=(0,0,0),axis=vector(2,0,0), radius=1, color = color.yellow)&lt;br /&gt;
&lt;br /&gt;
Curve&lt;br /&gt;
 c = curve(pos=[(-1,-1,0), (1,-1,0)], color = color.green) #create object&lt;br /&gt;
 c.append(pos=(3,2,-2)) #append next position vector&lt;br /&gt;
 c.append(pos=(4,1,2))&lt;br /&gt;
&lt;br /&gt;
Cylinder&lt;br /&gt;
 c = cylinder(pos=vector(0,2,1), axis=vector(5,0,0), radius=1, color=color.cyan)&lt;br /&gt;
&lt;br /&gt;
Ellipsoid&lt;br /&gt;
 e = ellipsoid(pos=vector(0,0,0), length=3, height=5, width=7, color=color.blue)&lt;br /&gt;
&lt;br /&gt;
Extrusion&lt;br /&gt;
 #define polygons first&lt;br /&gt;
 tri = Polygon( [(-2,0), (0,4), (2,0)] )&lt;br /&gt;
 circ = shapes.circle(pos=(0,1.5), radius=0.8)&lt;br /&gt;
 straight = [(0,0,0),(0,0,-4)]&lt;br /&gt;
 #create extrusion&lt;br /&gt;
 e = extrusion(pos=straight, shape=tri-circ, color=color.magenta)&lt;br /&gt;
&lt;br /&gt;
Helix&lt;br /&gt;
 h = helix(pos=vector(0,2,1), axis=vector(5,0,0), radius=0.5, color=(0.96,0.73,0.14))&lt;br /&gt;
&lt;br /&gt;
Label&lt;br /&gt;
 l = label(pos=vector(0,0.25,0), text=&#039;This is a Label&#039;, xoffset=20, yoffset=50, space=30, height=16, border=4,font=&#039;sans&#039;)&lt;br /&gt;
&lt;br /&gt;
Points&lt;br /&gt;
 p = points(pos=[vector(-1,0,0), vector(1,0,0)], radius=50, color=(1,1,.94))&lt;br /&gt;
&lt;br /&gt;
Pyramid&lt;br /&gt;
 p = pyramid(pos=vector(5,2,0), size=vector(3,3,2), color=(0.82, 0.41, 0.12))&lt;br /&gt;
&lt;br /&gt;
Ring&lt;br /&gt;
 r = ring(pos=vector(1,1,1), axis=vector(0,1,0),radius=0.5, thickness=0.1, color=(0.14, 1, 0.83))&lt;br /&gt;
&lt;br /&gt;
Sphere&lt;br /&gt;
 s = sphere(pos=vector(1,1,1), radius=5, color=(0.5, 1, 0.5))&lt;br /&gt;
&lt;br /&gt;
Text&lt;br /&gt;
 t = text(text=&#039;This is \ntext&#039;, #use \n for changing line&lt;br /&gt;
     align=&#039;center&#039;, color=(0.94, 0.90, 0.55))&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Commonly Used Objects==&lt;br /&gt;
The following objects are often used in class lab.&lt;br /&gt;
&lt;br /&gt;
===Sphere===&lt;br /&gt;
The sphere object can be used to represent a wide variety of things, but it is mostly used to represent spherical objects such as planets or particles such as protons and electrons. Two things must be set; the position (vector), and the radius (numerical value).&lt;br /&gt;
&lt;br /&gt;
===Arrow===&lt;br /&gt;
The arrow is perhaps the most important object for physics simulation. It can be used to represent various forces as well as visualizing vectors. To create an arrow, the position (vector), axis (vector), and the shaftwidth (a numerical value) must be set.&lt;br /&gt;
&lt;br /&gt;
===Curve===&lt;br /&gt;
The curve is often used to create a trail mark that represents a path that the object has moved, and it is also frequently used to create graphs. To create a curve, put the initial position vector of the curve, and append the next positions while updating the position in the while loop.&lt;br /&gt;
&lt;br /&gt;
==Application==&lt;br /&gt;
Following code is an example usage and application of object creation for lab simulations.&lt;br /&gt;
&lt;br /&gt;
 ## objects&lt;br /&gt;
 ceiling = box(pos=vector(0,0,0), size = vector(0.2, 0.01, 0.2))         # origin is at ceiling&lt;br /&gt;
 ball = sphere(pos=vector(.1,-.2,.3), radius=0.025, color=color.orange) # note: spring initially compressed&lt;br /&gt;
 spring = helix(pos=ceiling.pos, color=color.cyan, thickness=.003, coils=40, radius=0.015)&lt;br /&gt;
 parrow = arrow(color=color.magenta, pos=ball.pos, axis=vector(0,0,0))&lt;br /&gt;
 farrow = arrow(color=color.red, pos=ball.pos, axis=vector(0,0,0))&lt;br /&gt;
 trail = curve(color=ball.color)&lt;br /&gt;
 &lt;br /&gt;
 #graphs&lt;br /&gt;
 Kgraph=gcurve(color=color.red)&lt;br /&gt;
 Ugraph=gcurve(color=color.cyan)&lt;br /&gt;
 KUgraph=gcurve(color=color.yellow)&lt;br /&gt;
&lt;br /&gt;
 #graph updates are done in the while loop.&lt;br /&gt;
&lt;br /&gt;
== See also ==&lt;br /&gt;
&lt;br /&gt;
#[http://www.physicsbook.gatech.edu/VPython_basics VPython Basics]&lt;br /&gt;
#[http://www.physicsbook.gatech.edu/VPython VPython]&lt;br /&gt;
#[http://www.physicsbook.gatech.edu/VPython_Animation VPython Animation]&lt;br /&gt;
#[http://www.physicsbook.gatech.edu/VPython_Objects VPython Objects]&lt;br /&gt;
&lt;br /&gt;
===Further reading===&lt;br /&gt;
&lt;br /&gt;
#[http://www.glowscript.org/docs/VPythonDocs/primitives.html 3D object details]&lt;br /&gt;
#[http://vpython.org VPython Information]&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
http://www.glowscript.org/docs/VPythonDocs/primitives.html&lt;br /&gt;
&lt;br /&gt;
http://vpython.org/contents/docs/shapes.html&lt;br /&gt;
&lt;br /&gt;
http://vpython.org/&lt;/div&gt;</summary>
		<author><name>Mmorris83</name></author>
	</entry>
	<entry>
		<id>http://www.physicsbook.gatech.edu/index.php?title=VPython_Object&amp;diff=38029</id>
		<title>VPython Object</title>
		<link rel="alternate" type="text/html" href="http://www.physicsbook.gatech.edu/index.php?title=VPython_Object&amp;diff=38029"/>
		<updated>2019-10-22T06:52:49Z</updated>

		<summary type="html">&lt;p&gt;Mmorris83: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;A VPython Object is a representation of data in a specific in VPython both visually and numerically. Each object represents data through its attributes, specific characteristics assigned to each individual object. Objects play an essential role in the necessary knowledge for the coding portion of PHYS 2211 and 2212, as most of your programs will require the extensive usage and manipulation of objects. This page is intended to provide you a background on these objects, especially if you have no prior knowledge of coding or VPython.&lt;br /&gt;
&lt;br /&gt;
In this class, you should know how to create sphere objects and set their positions, and how to use arrows to show forces, fields, velocities, etc. &lt;br /&gt;
&lt;br /&gt;
==The Main Idea==&lt;br /&gt;
&lt;br /&gt;
Objects in VPython are intended to represent data in ways that can be easily visualized and understood by both the user and the computer. Each object has a type it belongs to, which determines its default attributes, as well as how the computer will choose to display it when the program runs. Objects must be uniquely named if you wish to refer to them again later in your program, and any graphical object you create (spheres, boxes, curves, arrows, etc.) continue to exist for as long as your program remains running - VPython will continue to display them regardless of where they are positioned. If you change an attribute of an object, such as its position or color, VPython will automatically display the object in its new location and/or with its new color.&lt;br /&gt;
&lt;br /&gt;
For example, let&#039;s say you create a sphere called &#039;ball&#039; - by default, ball has attributes pre-assigned to it, such as ball.pos (the .pos attribute signifies the position of the sphere) or ball.color (the .color attribute allows you to change the color of the sphere). Also, in addition to the preset attributes, you can also create new ones. Besides the position and radius, you can also create attributes for mass (ball.mass), velocity (ball.vel), momentum (ball.momentum), or anything else you see fit. Of course, not all attributes need to be added manually. They can be left blank and filled in with a default value which the program automatically assigns them &lt;br /&gt;
&lt;br /&gt;
==Basics==&lt;br /&gt;
To make an object and visualize it, it is required to import functions by writing following lines on the top of the code. If you are using Glowscript, these imports are not required.&lt;br /&gt;
&lt;br /&gt;
 from __future__ import division&lt;br /&gt;
 from visual import *&lt;br /&gt;
&lt;br /&gt;
Then, by writing following line on your code, you can instantiate &lt;br /&gt;
&lt;br /&gt;
 [variable name] = [object type]([attribute1].[attribute1 type], ... ,[attribute n].[attribute n type])&lt;br /&gt;
&lt;br /&gt;
For an object of type sphere, attributes might include position (pos), color, and size. You can also add attributes such as charge or material.&lt;br /&gt;
For an arrow, typical attributes are position (pos), the axis vector, and color.&lt;br /&gt;
&lt;br /&gt;
You can also change attributes of the certain objects after they have been created.&lt;br /&gt;
&lt;br /&gt;
 [variable name].[attribute] = [new attribute type]&lt;br /&gt;
&lt;br /&gt;
==Attributes==&lt;br /&gt;
Many objects in VPython carry common attributes regardless of their type. This section will cover the attributes you will be utilizing the most in this class. &lt;br /&gt;
&lt;br /&gt;
===Position===&lt;br /&gt;
The position attribute is common to almost every single object, and is probably the most important of the attributes. It determines the position of the object&#039;s center (in the case of spheres, boxes, etc.) or the object&#039;s endpoint (arrows, curves, etc.). It is of the vector type. To access and/or edit this attribute, it can be accessed using objectName.pos. Returning to the example from the above section, we can access the position of our sphere called &#039;ball&#039; by typing&lt;br /&gt;
&lt;br /&gt;
 ball.pos&lt;br /&gt;
&lt;br /&gt;
This would return the position of the ball in vector form, or allow you to refer to said position in calculations.&lt;br /&gt;
&lt;br /&gt;
In addition, because this is a vector, the position attribute has three components of its own, which can be accessed by typing:&lt;br /&gt;
&lt;br /&gt;
 ball.pos.x&lt;br /&gt;
 ball.pos.y&lt;br /&gt;
 ball.pos.z&lt;br /&gt;
&lt;br /&gt;
depending on the desired component of the position. The same rules apply as to ball.pos, however they are returned as single numbers instead of as a vector.&lt;br /&gt;
&lt;br /&gt;
To set the position of an object, one must first set the type of the object and then type pos([vector coordinates]). For instance, if we wanted to create an object called ball centered at (4,2,0), we would type&lt;br /&gt;
&lt;br /&gt;
 ball = objectType(pos(4,2,0))&lt;br /&gt;
&lt;br /&gt;
===Color===&lt;br /&gt;
The color attribute defines the object&#039;s color when it appears in the display window. This attribute is not important for data but more for display - it is simply to distinguish objects from one another, which is especially useful if you are working with a multitude of objects at once. &lt;br /&gt;
&lt;br /&gt;
Color can be assigned in one of two ways. The first way it can be assigned is through a preset color. The preset colors in VPython are blue, orange, green, red, purple, brown, pink, gray, olive, and cyan - any of these can be inserted to create the desired color. For instance, the syntax for creating a red color is:&lt;br /&gt;
&lt;br /&gt;
 color = color.red&lt;br /&gt;
 &lt;br /&gt;
Another way of assigning color is through an RGB vector, an additive form of assigning color. Red, green and blue layers are added together in various saturations and opacities to reproduce a broad array of colors. The vector contains three numbers from 0 to 255 - The first number represents the red, the second represents the green, and the third represents the blue. The higher the value of the number, the more it resembles that particular color. For instance, if we wanted to assign cyan to color, we would type&lt;br /&gt;
 color = (0, 255, 255)&lt;br /&gt;
&lt;br /&gt;
To set the color of an object, one must first set the type of the object and then set the color within the parentheses. For instance, if we wanted to create an object called ball which was cyan, we would type either&lt;br /&gt;
&lt;br /&gt;
 ball = objectType(color = color(cyan))&lt;br /&gt;
 ball = objectType(color = (0,255,255))&lt;br /&gt;
&lt;br /&gt;
===Axis===&lt;br /&gt;
The axis attribute is important specifically for arrows, as it determines the direction which the arrow points and how long it is. For instance, if you wanted to create an arrow parallel to the x-axis with a length of 5, the syntax could be:&lt;br /&gt;
&lt;br /&gt;
 myArrow = arrow(pos=vec(5, 0, 0), axis=vec(1, 1, 1), color=color.green)&lt;br /&gt;
&lt;br /&gt;
meaning the arrow points 5 units along the x axis and is perpendicular to the y and z axes. You will often use arrows to represent forces and fields, where the position will be the observation point, and the axis will the vector value of the force/field/etc.&lt;br /&gt;
&lt;br /&gt;
The axis attribute also determines orientation of other objects, such as rings or cylinders, but arrows are the only object whose size is specifically tied to the axis attribute.&lt;br /&gt;
&lt;br /&gt;
===Setting Attributes in a Loop===&lt;br /&gt;
Sometimes, the position vector will be given, and will be easy to set. In other cases, you may want to create, say 12 spheres in a circle, all a distance 2 from the origin. A quick way to do this is by by using a [http://physicsbook.gatech.edu/VPython_Loops loop] or a [http://physicsbook.gatech.edu/VPython_Lists list].&lt;br /&gt;
&lt;br /&gt;
For example: &lt;br /&gt;
&lt;br /&gt;
    i = 0&lt;br /&gt;
    while i &amp;lt; 2*pi:&lt;br /&gt;
        sphere(pos=vec(2*cos(i), 2*sin(i), 0), radius=0.5, color=color.green)&lt;br /&gt;
        i = i + 2*pi/12&lt;br /&gt;
&lt;br /&gt;
This would create 12 green spheres of radius .5 in a circle 2 units from the origin:&lt;br /&gt;
[[File:12circles.png|right]]&lt;br /&gt;
&lt;br /&gt;
===Material/Texture===&lt;br /&gt;
One of the main purposes of VPython programming is to help people&#039;s understanding on a physical principle or phenomenon by displaying an animation describing the principle or phenomenon. To achieve this, various objects are used in the program, and various attributes such as color and shape are used to distinguish them. Material is also one of that attributes, which does not change the essence of the phenomenon but helps people&#039;s understanding on the phenomenon.&lt;br /&gt;
&lt;br /&gt;
====Basic Materials====&lt;br /&gt;
&#039;&#039;&#039;Wood&#039;&#039;&#039;&lt;br /&gt;
 materials.wood&lt;br /&gt;
&lt;br /&gt;
 woodsphere = sphere(pos = (-2,0,0), radius = 1, material = materials.wood)&lt;br /&gt;
 woodbox = box(pos = (2,0,0), length=1, height=1, width=1, material = materials.wood)&lt;br /&gt;
&lt;br /&gt;
[[File:Wood.JPG]]&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Rough&#039;&#039;&#039;&lt;br /&gt;
 materials.rough&lt;br /&gt;
&lt;br /&gt;
 roughsphere = sphere(pos = (-2,0,0), radius = 1, material = materials.rough)&lt;br /&gt;
 roughbox = box(pos = (2,0,0), length=1, height=1, width=1, material = materials.rough)&lt;br /&gt;
&lt;br /&gt;
[[File:Rough.JPG]]&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;Marble&#039;&#039;&lt;br /&gt;
 materials.marble&lt;br /&gt;
&lt;br /&gt;
 marblesphere = sphere(pos = (-2,0,0), radius = 1, material = materials.marble)&lt;br /&gt;
 marblebox = box(pos = (2,0,0), length=1, height=1, width=1, material = materials.marble)&lt;br /&gt;
&lt;br /&gt;
[[File:Marble.JPG]]&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Plastic&#039;&#039;&#039;&lt;br /&gt;
 materials.plastic&lt;br /&gt;
&lt;br /&gt;
 plasticsphere = sphere(pos = (-2,0,0), radius = 1, material = materials.plastic)&lt;br /&gt;
 plasticbox = box(pos = (2,0,0), length=1, height=1, width=1, material = materials.plastic)&lt;br /&gt;
&lt;br /&gt;
[[File:Plastic.JPG]]&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Earth&#039;&#039;&#039;&lt;br /&gt;
 materials.earth&lt;br /&gt;
&lt;br /&gt;
 earthsphere = sphere(pos = (-2,0,0), radius = 1, material = materials.earth)&lt;br /&gt;
 earthbox = box(pos = (2,0,0), length=1, height=1, width=1, material = materials.earth)&lt;br /&gt;
&lt;br /&gt;
[[File:Earth.JPG]]&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Diffuse&#039;&#039;&#039;&lt;br /&gt;
 materials.diffuse&lt;br /&gt;
&lt;br /&gt;
 diffusesphere = sphere(pos = (-2,0,0), radius = 1, material = materials.diffuse)&lt;br /&gt;
 diffusebox = box(pos = (2,0,0), length=1, height=1, width=1, material = materials.diffuse)&lt;br /&gt;
&lt;br /&gt;
[[File:Diffuse.JPG]]&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Emissive&#039;&#039;&#039;&lt;br /&gt;
Material which looks like it glows&lt;br /&gt;
&lt;br /&gt;
 materials.emissive&lt;br /&gt;
&lt;br /&gt;
 emissivesphere = sphere(pos = (-2,0,0), radius = 1, material = materials.emissive)&lt;br /&gt;
 emissivebox = box(pos = (2,0,0), length=1, height=1, width=1, material = materials.emissive)&lt;br /&gt;
&lt;br /&gt;
[[File:Emissive.JPG]]&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Unshaded&#039;&#039;&#039;&lt;br /&gt;
Material which does not affected by lighting&lt;br /&gt;
&lt;br /&gt;
 materials.unshaded&lt;br /&gt;
&lt;br /&gt;
 unshadedsphere = sphere(pos = (-2,0,0), radius = 1, material = materials.unshaded)&lt;br /&gt;
 unshadedbox = box(pos = (2,0,0), length=1, height=1, width=1, material = materials.unshaded)&lt;br /&gt;
&lt;br /&gt;
[[File:Unshaded.JPG]]&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Shiny&#039;&#039;&#039;&lt;br /&gt;
 materials.shiny&lt;br /&gt;
&lt;br /&gt;
 shinysphere = sphere(pos = (-2,0,0), radius = 1, material = materials.shiny)&lt;br /&gt;
 shinybox = box(pos = (2,0,0), length=1, height=1, width=1, material = materials.shiny)&lt;br /&gt;
&lt;br /&gt;
[[File:Shiny.JPG]]&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Chrome&#039;&#039;&#039;&lt;br /&gt;
 materials.chrome&lt;br /&gt;
&lt;br /&gt;
 chromesphere = sphere(pos = (-2,0,0), radius = 1, material = materials.chrome)&lt;br /&gt;
 chromebox = box(pos = (2,0,0), length=1, height=1, width=1, material = materials.chrome)&lt;br /&gt;
&lt;br /&gt;
[[File:Chrome.JPG]]&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Blazed&#039;&#039;&#039;&lt;br /&gt;
 materials.blazed&lt;br /&gt;
&lt;br /&gt;
 blazedsphere = sphere(pos = (-2,0,0), radius = 1, material = materials.blazed)&lt;br /&gt;
 blazedbox = box(pos = (2,0,0), length=1, height=1, width=1, material = materials.blazed)&lt;br /&gt;
&lt;br /&gt;
[[File:Blazed.JPG]]&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Silver&#039;&#039;&#039;&lt;br /&gt;
 materials.silver&lt;br /&gt;
&lt;br /&gt;
 silversphere = sphere(pos = (-2,0,0), radius = 1, material = materials.silver)&lt;br /&gt;
 silverbox = box(pos = (2,0,0), length=1, height=1, width=1, material = materials.silver)&lt;br /&gt;
&lt;br /&gt;
[[File:Silver.JPG]]&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;BlueMarble&#039;&#039;&#039;&lt;br /&gt;
Earth with clouds&lt;br /&gt;
&lt;br /&gt;
 materials.BlueMarble&lt;br /&gt;
&lt;br /&gt;
 BlueMarblesphere = sphere(pos = (-2,0,0), radius = 1, material = materials.BlueMarble)&lt;br /&gt;
 BlueMarblebox = box(pos = (2,0,0), length=1, height=1, width=1, material = materials.BlueMarble)&lt;br /&gt;
&lt;br /&gt;
[[File:BlueMarble.JPG]]&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Bricks&#039;&#039;&#039;&lt;br /&gt;
 materials.bricks&lt;br /&gt;
&lt;br /&gt;
 brickssphere = sphere(pos = (-2,0,0), radius = 1, material = materials.bricks)&lt;br /&gt;
 bricksbox = box(pos = (2,0,0), length=1, height=1, width=1, material = materials.bricks)&lt;br /&gt;
&lt;br /&gt;
[[File:Bricks.JPG]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====Creating your own texture====&lt;br /&gt;
=====Making a text from a photo=====&lt;br /&gt;
&lt;br /&gt;
You can create a texture with a image file, using PIL, the Python Image Library.&lt;br /&gt;
To do this,PIL must be installed on the computer and the function &amp;quot;Image&amp;quot; should be imported.&lt;br /&gt;
&lt;br /&gt;
[http://www.pythonware.com/products/pil/#pil117]&lt;br /&gt;
&lt;br /&gt;
 from visual import *&lt;br /&gt;
 import Image # Must install PIL&lt;br /&gt;
&lt;br /&gt;
And the basic syntax is&lt;br /&gt;
&lt;br /&gt;
 name = &amp;quot;buzz&amp;quot;&lt;br /&gt;
 width = 64 # must be power of 2&lt;br /&gt;
 height = 64 # must be power of 2&lt;br /&gt;
 im = Image.open(name+&amp;quot;.jpg&amp;quot;)&lt;br /&gt;
 #print(im.size) # optionally, see size of image&lt;br /&gt;
 # Optional cropping:&lt;br /&gt;
 #im = im.crop((x1,y1,x2,y2)) # (0,0) is upper left&lt;br /&gt;
 im = im.resize((width,height), Image.ANTIALIAS)&lt;br /&gt;
 materials.saveTGA(name,im)&lt;br /&gt;
&lt;br /&gt;
You can use the texture &amp;quot;im&amp;quot;, which is created with an image file &amp;quot;buzz&amp;quot;, using following code&lt;br /&gt;
&lt;br /&gt;
 tex = materials.texture(data=im, mapping=&amp;quot;rectangular&amp;quot;) &lt;br /&gt;
 buzzbox = box(pos = (2,0,0), length=1, height=1, width=1, material = tex)&lt;br /&gt;
 buzzsphere = sphere(pos = (-2,0,0), radius = 1, material = tex)&lt;br /&gt;
&lt;br /&gt;
[[File:BuzzTexture.JPG]]&lt;br /&gt;
&lt;br /&gt;
===Other Attributes===&lt;br /&gt;
There are other attributes which are also important but not as essential (or common) as position/color/axis, such as radius and make_trail, among others. Most of these attributes are self-explanatory or will not be used in the course, so if you would like full descriptions of these attributes, refer to the [http://vpython.org/contents/docs/index.html VPython Documentation].&lt;br /&gt;
&lt;br /&gt;
==Common Objects==&lt;br /&gt;
In order to display and understand your code effectively, there are a certain few objects which will be essential, especially for this class.&lt;br /&gt;
&lt;br /&gt;
===Sphere===&lt;br /&gt;
[[File:Sphere.jpg|thumb|right|alt=Yellow Arrow|The example sphere]]&lt;br /&gt;
Spheres are the most basic but also very useful objects. A sphere object is a representation of a sphere with a set radius, position, and color. Spheres are commonly used to represent particles in assignments and labs, and are generally assigned a velocity / momentum / etc. in problems. Spheres generally have three properties which should be set when creating them - radius, position, and color, in any order within the parentheses. Only the position is required  -  note that the position attribute for a cylinder, arrow, cone, and pyramid corresponds to one end of the object, whereas for a sphere it corresponds to the center of the object. If a radius and color are not specified, VPython will set the radius to 1 and the color to the current foreground color.&lt;br /&gt;
&lt;br /&gt;
For instance, if we wanted to create a yellow sphere at the origin with a radius of ten, we would type&lt;br /&gt;
&lt;br /&gt;
 yellowSphere = sphere(radius = 10, pos = vector(0,0,0), color=color.yellow)&lt;br /&gt;
&lt;br /&gt;
===Arrow===&lt;br /&gt;
[[File:arrowW.png|thumb|right|alt=Yellow Arrow|The example arrow]]&lt;br /&gt;
Arrows are just as multipurpose as spheres, if not more so. In this class, arrows will be used to represent vector quantities visually. For instance, you can use arrows to show the velocity/acceleration/momentum of a particle, the electric field direction around a charged particle, etc. Arrow objects are created with a position which represents the starting point of the arrow - not the center - and an axis which represents the arrow&#039;s direction and length. Both the position and the length are vector quantities. The color is again not essential as VPython will set it to a default value if left out. The arrow object itself features a straight box-shaped shaft with a 3d pyramid-shaped arrowhead at one end.&lt;br /&gt;
&lt;br /&gt;
For instance, to create an white arrow based at (4,2,0) pointing in the direction of (-2,2,-4), we would type&lt;br /&gt;
&lt;br /&gt;
 nameArrow = arrow(pos=(4,2,0), axis=(-2,2,-4), color=color.white)&lt;br /&gt;
&lt;br /&gt;
===Box===&lt;br /&gt;
[[File:ArrowV.jpg|thumb|right|alt=Yellow Arrow|The example box]]&lt;br /&gt;
Boxes will feature more in Physics 1 during the kinematics and dynamics sections. While the position attribute is the center of the box as with a sphere, the other attributes of boxes are more complex than spheres or arrows, and particular heed must be paid to the axis attribute, as the box&#039;s rotation and orientation depends on it. The axis attribute sets the direction of the length of the box, assuming the length, width and height of the box are set before. If they are not given, the length is automatically set to the magnitude of the axis vector. &lt;br /&gt;
&lt;br /&gt;
To create a green cube with its corner at the origin and a side length of 5 (pictured), we would type&lt;br /&gt;
&lt;br /&gt;
 greenbox = box(pos=(2.5, 2.5, 2.5), length=5, height=5, width=5) &lt;br /&gt;
&lt;br /&gt;
The axis attribute can also be added to tilt the box by changing the angle of the length. For example, this would cause the box from the previous step to be tipped at a 45 degree angle:&lt;br /&gt;
&lt;br /&gt;
 tippedbox = box(pos=(2.5, 2.5, 2.5), axis(1,1,0), length=5, height=5, width=5)&lt;br /&gt;
&lt;br /&gt;
The box can also be rotated around its own axis by changing which way is &amp;quot;up&amp;quot; for the box, by specifying an up attribute for the box that is different from the up vector of the coordinate system. For instance, this would take the tipped box from the previous step and rotate it so that the top face of the box is perpendicular to the vector in question.&lt;br /&gt;
&lt;br /&gt;
 rotatedbox = box(pos=(2.5, 2.5, 2.5), axis(1,1,0), length=5, height=5, width=5, up=(2, 3, 1))&lt;br /&gt;
&lt;br /&gt;
===Cylinder===&lt;br /&gt;
[[File:Cyl.jpg|thumb|right|alt=Yellow Arrow|The example cylinder]]&lt;br /&gt;
Cylinders are useful wherever a rod comes into play. For instance, in Physics 2, you may see problems regarding charged rods or something of the sort. The cylinder&#039;s attributes are a bit different and incorporate elements of most of the other shapes. As such, knowing cylinder syntax gives you a good basis for any object you need to create. The position vector determines the center of the cylinder&#039;s base (similar to a cone&#039;s pos attribute) and not the center of the object, while the axis determines the direction and length of the cylinder (similar to the arrow&#039;s axis attribute). The radius is self-explanatory.&lt;br /&gt;
&lt;br /&gt;
For example, to make a red cylinder with the base centered at (4,1,3) which is 6 units tall, has a radius of 2, and is laying parallel to the x-axis, you would type&lt;br /&gt;
&lt;br /&gt;
 cyl = cylinder(pos=(4,1,3), axis=(6,0,0), radius=2, color=color.red)&lt;br /&gt;
&lt;br /&gt;
===Other===&lt;br /&gt;
Aside from the four main objects listed above, there are many more objects which can be used in your programs. You will not need the majority of them for this class, but they do exist, and you may want to learn about them and their attributes. Visit the VPython Documentation for more information on the following objects:&lt;br /&gt;
&lt;br /&gt;
{|style=&amp;quot;margin: 0 auto;&amp;quot;&lt;br /&gt;
| [[File:EllipseB.jpg|thumb|center|alt=Yellow Arrow|Ellipse]]&lt;br /&gt;
| [[File:RingB.jpg|thumb|center|alt=Yellow Arrow|Ring]]&lt;br /&gt;
| [[File:PyramidG.jpg|thumb|center|alt=Yellow Arrow|Pyramid]]&lt;br /&gt;
| [[File:HelixO.jpg|thumb|center|alt=Yellow Arrow|Helix]]&lt;br /&gt;
| [[File:FacesR.jpg|thumb|center|alt=Yellow Arrow|Face]]&lt;br /&gt;
| [[File:Curve.jpg|thumb|center|alt=Yellow Arrow|Curve]]&lt;br /&gt;
| [[File:ConeB.jpg|thumb|center|alt=Yellow Arrow|Cone]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Examples==&lt;br /&gt;
===Simple===&lt;br /&gt;
Create a green sphere named &amp;quot;greenSphere&amp;quot; with a radius of 5 located at the origin. &lt;br /&gt;
&lt;br /&gt;
{| role=&amp;quot;presentation&amp;quot; class=&amp;quot;wikitable mw-collapsible mw-collapsed&amp;quot;&lt;br /&gt;
| &amp;lt;strong&amp;gt;Solution&amp;lt;/strong&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;greenSphere = sphere(radius=5, pos=vector(0,0,0), color=color.green)&amp;lt;/code&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Middling===&lt;br /&gt;
Create two objects. &lt;br /&gt;
* Object 1: A magenta sphere of radius 3 named sphereOne at the position (9,0,8)&lt;br /&gt;
* Object 2: A cyan arrow named arrowTwo that points from the origin to the center of sphereOne.&lt;br /&gt;
&lt;br /&gt;
{| role=&amp;quot;presentation&amp;quot; class=&amp;quot;wikitable mw-collapsible mw-collapsed&amp;quot;&lt;br /&gt;
| &amp;lt;strong&amp;gt;Solution&amp;lt;/strong&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
! scope=&amp;quot;row&amp;quot; | &amp;lt;code&amp;gt;sphereOne = sphere(radius=3.5, pos=vector(9,0,8), color=color.magenta)&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
! scope=&amp;quot;row&amp;quot; | &amp;lt;code&amp;gt;position = vector(0,0,0)&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
! scope=&amp;quot;row&amp;quot; | &amp;lt;code&amp;gt;arrow(pos=position, axis=(sphereOne.pos - position), color = color.cyan)&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
! scope=&amp;quot;row&amp;quot; | Note: the position vector is used in the second line, because arrowTwo.pos cannot be called yet. The arrow has yet to be created - it is created in line 3.&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Difficult===&lt;br /&gt;
Create three objects. &lt;br /&gt;
* Object 1: Sphere, radius of 2, located at (-4,-3,8)&lt;br /&gt;
* Object 2: Sphere, radius of 1, located at (6,11,0)&lt;br /&gt;
* Object 3: Curve, starting at origin, moving to first sphere, then to second&lt;br /&gt;
&lt;br /&gt;
{| role=&amp;quot;presentation&amp;quot; class=&amp;quot;wikitable mw-collapsible mw-collapsed&amp;quot;&lt;br /&gt;
| &amp;lt;strong&amp;gt;Solution&amp;lt;/strong&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
! scope=&amp;quot;row&amp;quot; | &amp;lt;code&amp;gt;sphereOne = sphere(radius = 2, pos=vector(-4,-3,8))&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
! scope=&amp;quot;row&amp;quot; | &amp;lt;code&amp;gt;sphereTwo = sphere(radius = 1, pos=vector(6,11,0))&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
! scope=&amp;quot;row&amp;quot; | &amp;lt;code&amp;gt;curveOne = curve(color=color.red, pos = (0,0,0))&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
! scope=&amp;quot;row&amp;quot; | &amp;lt;code&amp;gt;curveOne.append(sphereOne.pos)&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
! scope=&amp;quot;row&amp;quot; | &amp;lt;code&amp;gt;curveOne.append(sphereOne.pos)&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Applying Texture&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
[[File:EarthandMoon.GIF]]&lt;br /&gt;
&lt;br /&gt;
Trinket Link&lt;br /&gt;
[https://trinket.io/glowscript/6ddb3d237e]&lt;br /&gt;
&lt;br /&gt;
VPython code&lt;br /&gt;
 &lt;br /&gt;
 from __future__ import division&lt;br /&gt;
 from visual import *&lt;br /&gt;
 from visual.graph import *&lt;br /&gt;
 scene.width=1024&lt;br /&gt;
 scene.height=760&lt;br /&gt;
&lt;br /&gt;
 # CONSTANTS&lt;br /&gt;
 G = 6.7e-11&lt;br /&gt;
 mEarth = 6e24&lt;br /&gt;
 mcraft = 15000&lt;br /&gt;
 deltat = 60&lt;br /&gt;
 t = 0&lt;br /&gt;
 mMoon = 7e22&lt;br /&gt;
 scale = 800000&lt;br /&gt;
 c=2.99792e8&lt;br /&gt;
&lt;br /&gt;
 #OBJECTS AND INITIAL VALUES&lt;br /&gt;
 Earth = sphere(pos=vector(0,0,0), radius=15e6, material = materials.BlueMarble)&lt;br /&gt;
 # Add a radius for the spacecraft. It should be BIG, so it can be seen.&lt;br /&gt;
 craft = sphere(pos=vector(-60160000,-192000,0), radius=2e6, material = materials.marble)&lt;br /&gt;
 Moon =  sphere(pos=vector(4e8,0,0), radius=1.75e6, material = materials.marble)&lt;br /&gt;
 vcraft = vector(735,2849,0)&lt;br /&gt;
 pcraft = mcraft*vcraft&lt;br /&gt;
&lt;br /&gt;
 trail = curve(color=craft.color)    # This creates a trail for the spacecraft&lt;br /&gt;
 #scene.autoscale = 1000000                 # And this prevents zooming in or out&lt;br /&gt;
&lt;br /&gt;
 pscale = Earth.radius / mag(pcraft)&lt;br /&gt;
 fscale = Earth.radius/ ((G*mEarth*mcraft)/mag(craft.pos-Earth.pos)**2)&lt;br /&gt;
 dpscale = 500 * Earth.radius/mag(pcraft)&lt;br /&gt;
&lt;br /&gt;
 r_EarthMoon = Moon.pos - Earth.pos #Relative position vector from Earth to Moon&lt;br /&gt;
 r_EarthMoon_mag = mag(r_EarthMoon)&lt;br /&gt;
 F_EarthMoon_mag = (G*mcraft*mEarth)/(r_EarthMoon_mag**2)&lt;br /&gt;
 r_EarthMoon_hat = r_EarthMoon/r_EarthMoon_mag&lt;br /&gt;
&lt;br /&gt;
 Force_EarthMoon = (-r_EarthMoon_hat)*F_EarthMoon_mag #Force on Moon due to Earth&lt;br /&gt;
 pMoon = Force_EarthMoon / deltat&lt;br /&gt;
&lt;br /&gt;
 # CALCULATIONS&lt;br /&gt;
 print(&amp;quot;p=&amp;quot;,  pcraft)&lt;br /&gt;
 while t &amp;lt; (10e10):&lt;br /&gt;
    rate(500)   # This slows down the animation (runs faster with bigger number)&lt;br /&gt;
    rE =  craft.pos - Earth.pos&lt;br /&gt;
    rEmag = mag(rE)&lt;br /&gt;
    FEmag = (G*mcraft*mEarth)/(rEmag**2)&lt;br /&gt;
    rEhat = rE/rEmag&lt;br /&gt;
    FEnet = (-rEhat)*FEmag&lt;br /&gt;
&lt;br /&gt;
    rM =  craft.pos - Moon.pos&lt;br /&gt;
    rMmag = mag(rM)&lt;br /&gt;
    FMmag = (G*mcraft*mMoon)/(rMmag**2)&lt;br /&gt;
    rMhat = rM/rMmag&lt;br /&gt;
    FMnet = (-rMhat)*FMmag&lt;br /&gt;
    &lt;br /&gt;
    Fnet = FMnet+FEnet&lt;br /&gt;
&lt;br /&gt;
    pcraft_i = pcraft + vector(0,0,0)&lt;br /&gt;
    pcraft_ii = mag(pcraft_i)    &lt;br /&gt;
    pcraft = pcraft + ((Fnet)*deltat)&lt;br /&gt;
    pcraft_f = pcraft&lt;br /&gt;
    pcraft_ff = mag(pcraft)&lt;br /&gt;
    vavg = pcraft/mcraft&lt;br /&gt;
    speedcraft = mag(vavg)&lt;br /&gt;
    craft.pos = craft.pos + vavg*deltat&lt;br /&gt;
&lt;br /&gt;
    Fnet_tangent = ((pcraft_ff-pcraft_ii)/deltat)*(pcraft/mag(pcraft))*pscale&lt;br /&gt;
    Fnet_perp = Fnet - Fnet_tangent&lt;br /&gt;
&lt;br /&gt;
    r_EarthMoon = Moon.pos - Earth.pos #Relative position vector from Earth to Moon&lt;br /&gt;
    r_EarthMoon_mag = mag(r_EarthMoon)&lt;br /&gt;
    F_EarthMoon_mag = (G*mcraft*mEarth)/(r_EarthMoon_mag**2)&lt;br /&gt;
    r_EarthMoon_hat = r_EarthMoon/r_EarthMoon_mag&lt;br /&gt;
    &lt;br /&gt;
    r_craftMoon = Moon.pos - craft.pos#Relative position vector from spacecraft to Moon&lt;br /&gt;
    r_craftMoon_mag = mag(r_craftMoon)&lt;br /&gt;
    F_craftMoon_mag = (G*mcraft*mEarth)/(r_craftMoon_mag**2)&lt;br /&gt;
    r_craftMoon_hat = r_craftMoon/r_craftMoon_mag    &lt;br /&gt;
&lt;br /&gt;
    Force_EarthMoon = (-r_EarthMoon_hat)*F_EarthMoon_mag #Force on Moon due to Earth&lt;br /&gt;
    Force_craftMoon = (-r_craftMoon_hat)*F_craftMoon_mag#Force on Moon due to spacecraft&lt;br /&gt;
    Fnet_Moon = Force_EarthMoon + Force_craftMoon #Net force on Moon&lt;br /&gt;
&lt;br /&gt;
    momentum_Moon = pMoon + Fnet_Moon*deltat#Update momentum of Moon&lt;br /&gt;
    vavg_Moon = momentum_Moon/mMoon&lt;br /&gt;
    Moon.pos = Moon.pos + vavg_Moon * deltat #Update momentum of Moon&lt;br /&gt;
&lt;br /&gt;
    trail.append(pos=craft.pos)  &lt;br /&gt;
    t = t+deltat&lt;br /&gt;
    pcraft = pcraft_f&lt;br /&gt;
    deltap = pcraft - pcraft_i&lt;br /&gt;
&lt;br /&gt;
==Connectedness ==&lt;br /&gt;
How is this topic connected to something that you are interested in?&lt;br /&gt;
* I quite enjoy coding myself on my own time; I have taken a couple online classes outside of Tech on Java and a class here on MATLAB. However, Python and its variants are still far and away my favorite languages to code in, and the one I am most knowledgeable in. I believe the inclusion of VPython in the Physics curriculum is overall a benefit to us students as it allows us to both learn the physics and visualize them by creating the models we do in Labs on VPython.&lt;br /&gt;
  &lt;br /&gt;
How is it connected to your major?&lt;br /&gt;
* As a Business Admin major I&#039;ll be doing IT Management, which requires me to have an understanding of computer systems at the very least. While VPython may not be quite what I need in the future, it is still a good basis in learning the ins and outs of a major programming language long before I have to delve into serious CS training - plus it lets me keep my coding skills sharp!&lt;br /&gt;
&lt;br /&gt;
Is there an interesting industrial application?&lt;br /&gt;
* Of course! Whereas the simplicity of Python/VPython have made it effective to illustrate simple physics as we do, it&#039;s also powerful elsewhere. VPython is being used by some as a [https://www.youtube.com/watch?v=hK60VT0c8eI simulation tool for robotics] among other things, while Python itself is the backbone for thousands of industrial softwares and applications. In addition, agencies such as NASA use Python and VPython in their labs - I used both programs during my two separate internships at NASA Glenn Research Center in Cleveland, OH.&lt;br /&gt;
&lt;br /&gt;
==See Also==&lt;br /&gt;
[http://www.physicsbook.gatech.edu/VPython VPython] - VPython&#039;s biography, if you will&lt;br /&gt;
&lt;br /&gt;
[http://www.physicsbook.gatech.edu/VPython_basics VPython Basics] - Especially if you&#039;re totally new to coding as a whole, this page will bolster your learning&lt;br /&gt;
 &lt;br /&gt;
[http://www.physicsbook.gatech.edu/VPython_Functions VPython Functions] - Working with functions, assuming you understand the basics of coding&lt;br /&gt;
&lt;br /&gt;
[http://www.physicsbook.gatech.edu/VPython_Loops VPython Loops] - The next step in VPython code knowledge after functions - using loops&lt;br /&gt;
&lt;br /&gt;
[http://www.physicsbook.gatech.edu/VPython_Common_Errors_and_Troubleshooting VPython Troubleshooting] - Having problems? Check here!&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
http://vpython.org/&lt;br /&gt;
&lt;br /&gt;
http://vpython.org/contents/docs/index.html&lt;br /&gt;
&lt;br /&gt;
http://vpython.org/contents/docs/color.html&lt;br /&gt;
&lt;br /&gt;
http://vpython.org/contents/docs/primitives.html&lt;br /&gt;
&lt;br /&gt;
http://vpython.org/contents/docs/materials.html&lt;br /&gt;
&lt;br /&gt;
http://guigui.developpez.com/cours/python/vpython/en/?page=object&lt;/div&gt;</summary>
		<author><name>Mmorris83</name></author>
	</entry>
	<entry>
		<id>http://www.physicsbook.gatech.edu/index.php?title=VPython_Loops&amp;diff=38028</id>
		<title>VPython Loops</title>
		<link rel="alternate" type="text/html" href="http://www.physicsbook.gatech.edu/index.php?title=VPython_Loops&amp;diff=38028"/>
		<updated>2019-10-22T06:52:29Z</updated>

		<summary type="html">&lt;p&gt;Mmorris83: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;An introduction to creating and using loops in VPython.&lt;br /&gt;
&lt;br /&gt;
==The Main Idea==&lt;br /&gt;
The most commonly used loop structures in VPython are the &#039;for&#039; loop and the &#039;while&#039; loop. In Physics modeling, the &#039;for&#039; loop is useful when one wants to check a condition before running the code in the &#039;for&#039; loop. For example, the code following the statement -- &#039;for i in range(0,3):&#039; -- will only run when i is within the specified range. The &#039;while&#039; loop is useful when one wants to run a code for a specified interval or while a condition is true. For example, the code following the statement -- &#039;while t &amp;lt; 100:&#039; -- will run until t is greater than or equal to 100 (1,2,3).&lt;br /&gt;
&lt;br /&gt;
===A Mathematical Model===&lt;br /&gt;
When computing iterations for physics problems, using the iterative method with small delta t increments can produce near accurate results. To have truly small delta t increments, however, computational modeling is necessary for computation. &lt;br /&gt;
&lt;br /&gt;
In a problem that requires use of the momentum principle and a specific number of time steps for iteration, we update momentum for each time step using the following equation:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
delta P = Fnet * deltat&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
With this equation, the final momentum is updated after each time step (deltat) up to a time (t). We can only manually do this with a small number of increments, however, and as a result, with less accuracy than if our delta t increments were smaller. This is where computational modeling and VPython loops come in. &lt;br /&gt;
&lt;br /&gt;
===A Computational Model===&lt;br /&gt;
With computational modeling using VPython, we can reduce the size of delta t and increase the number of time steps in the approximation of an iteration. Instead of two or three time steps, VPython loops make it possible to test infinitely small time steps, making the final result more accurate. For example, to calculate an approximation from t = 0 to t = 2 using two time steps, one could write the following time update:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
deltat = 1&lt;br /&gt;
t = 0&lt;br /&gt;
while t &amp;lt; 2:&lt;br /&gt;
    t += deltat&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
However, loops can be used to test much smaller time steps than deltat = 1; the smaller the time step, the more accurate the iteration. &lt;br /&gt;
&lt;br /&gt;
==Examples==&lt;br /&gt;
The following examples cover a range of loops that can be created in VPython from the simplest &#039;for&#039; loops to more complicated &#039;for&#039; and &#039;while&#039; loops.&lt;br /&gt;
&lt;br /&gt;
===Simple===&lt;br /&gt;
The simplest example is a basic &#039;for&#039; loop. The following code will print each integer in a range:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
for i in range(0,10):&lt;br /&gt;
    print i&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The same thing can be accomplished with a &#039;while&#039; loop as well. See the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
i = 0&lt;br /&gt;
while i &amp;lt; 10:&lt;br /&gt;
    print i&lt;br /&gt;
    i += 1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
When modeling momentum updates, using a &#039;while&#039; loop allows the code to run until Tfinal has been reached by adding deltat to t each time the loop runs.&lt;br /&gt;
&lt;br /&gt;
===Middling===&lt;br /&gt;
To solve more complex problems, we need to create values and objects before the loop that will then be updated within the loop until a certain time, t. In the following example, the final position and final velocity of object ball is updated until t = 10 using a time step of deltat = 1.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
t = 0&lt;br /&gt;
deltat = 1&lt;br /&gt;
&lt;br /&gt;
while t &amp;lt; 10:&lt;br /&gt;
    Fgrav = vector(0,-ball.m*g,0)&lt;br /&gt;
    Fdrag=(.5)*dragCoeff*airDensity*areaBall*mag(ball.p/ball.m)**2*norm(ball.p)&lt;br /&gt;
    Fnet = Fgrav - Fdrag&lt;br /&gt;
&lt;br /&gt;
    ball.p = ball.p + Fnet*deltat&lt;br /&gt;
    ball.pos = ball.pos + (ball.p/ball.m)*deltat  &lt;br /&gt;
&lt;br /&gt;
    t += deltat&lt;br /&gt;
&lt;br /&gt;
print(ball.pos)    #prints final ball position&lt;br /&gt;
print(ball.p/mball)    #prints final ball velocity&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Difficult===&lt;br /&gt;
The following code calculates the final position and velocity of a ball attached to a string mounted to a ceiling. After code is written listing the constants, creating the objects, and setting an initial value of t = 0, the following statements update the position and velocity values until t = 10 seconds.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;pre&amp;gt;&lt;br /&gt;
t = 0&lt;br /&gt;
deltat = 1&lt;br /&gt;
&lt;br /&gt;
while t &amp;lt; 10:   &lt;br /&gt;
    L = ball.pos - ceiling.pos&lt;br /&gt;
    s=mag(L) - L0&lt;br /&gt;
    Lhat = L/mag(L)&lt;br /&gt;
    Fs = -(ks)*s*Lhat&lt;br /&gt;
    Fg = vector(0,-g*mball,0)&lt;br /&gt;
    Fdrag = (-1)*b*(ball.p/mball)&lt;br /&gt;
    Fnet = Fg + Fs + Fdrag&lt;br /&gt;
    ball.p = ball.p + Fnet*deltat&lt;br /&gt;
    ball.pos = ball.pos + (ball.p/(mball))*deltat&lt;br /&gt;
    spring.axis = ball.pos - ceiling.pos &lt;br /&gt;
    &lt;br /&gt;
    t += deltat&lt;br /&gt;
&lt;br /&gt;
print(ball.pos)    #prints final ball position&lt;br /&gt;
print(ball.p/mball)    #prints final ball velocity&lt;br /&gt;
 &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Connectedness==&lt;br /&gt;
Understanding the basics of VPython creates a framework for more easily learning to write in coding languages other than Python. Additionally, understanding the basics of the &#039;for&#039; loop and the &#039;while&#039; loop enables one to write more complex code using both &#039;for&#039; and &#039;while&#039; loops, even nesting both types of loops in creating complex conditionals. In more advanced Physics modeling, being able to write more complex conditional statements enables these more complex equations and relationships to be solved via computational modeling. &lt;br /&gt;
&lt;br /&gt;
Even for non-computing majors, coding experience is a highly valuable trait employers are increasingly looking for in candidates. In 2016, analytics firm Burning Glass reported that programming jobs were growing 12% faster than the market average. Additionally, half of the projected job openings looking for programming experience are in non-technology fields such as &#039;finance, manufacturing, and healthcare&#039; (4). In 2017, Forbes ranked Python as the top-ranked in-demand coding language among the top five: &#039;Python, Java, JavaScript, C#, and PHP&#039; (5). &lt;br /&gt;
&lt;br /&gt;
==History==&lt;br /&gt;
Python is an interpreted language that originated in the 1980s and was released from development in the 1990s. Because it is interpreted, compiling is not required to convert lines of code into machine-understandable instructions (6). In 1998, David Scherer saw a need for a better 2D and 3D graphics programming environment and created the idea for Visual (a.k.a. VPython), a Python module (7). &lt;br /&gt;
&lt;br /&gt;
==See Also==&lt;br /&gt;
&lt;br /&gt;
===Further Reading===&lt;br /&gt;
&#039;Why Coding Is Still The Most Important Job Skill Of The Future&#039; (Dishman, 2016)&lt;br /&gt;
&#039;The Five Most In-Demand Coding Languages&#039; (Kauflin, 2017)&lt;br /&gt;
&lt;br /&gt;
===External Links===&lt;br /&gt;
http://vpython.org/contents/docs/VisualIntro.html&lt;br /&gt;
http://vpython.org/contents/docs/&lt;br /&gt;
https://faculty.math.illinois.edu/~gfrancis/illimath/windows/aszgard_mini/pylibs/visual/docs/visual/VisualIntro.html&lt;br /&gt;
https://www.fastcompany.com/3060883/why-coding-is-the-job-skill-of-the-future-for-everyone&lt;br /&gt;
https://www.forbes.com/sites/jeffkauflin/2017/05/12/the-five-most-in-demand-coding-languages/#6b86011fb3f5&lt;br /&gt;
https://en.wikipedia.org/wiki/Python_(programming_language)&lt;br /&gt;
https://en.wikipedia.org/wiki/VPython#History&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
1. http://vpython.org/contents/docs/VisualIntro.html&lt;br /&gt;
2. http://vpython.org/contents/docs/&lt;br /&gt;
3. https://faculty.math.illinois.edu/~gfrancis/illimath/windows/aszgard_mini/pylibs/visual/docs/visual/VisualIntro.html&lt;br /&gt;
4. https://www.fastcompany.com/3060883/why-coding-is-the-job-skill-of-the-future-for-everyone&lt;br /&gt;
5. https://www.forbes.com/sites/jeffkauflin/2017/05/12/the-five-most-in-demand-coding-languages/#6b86011fb3f5&lt;br /&gt;
6. https://en.wikipedia.org/wiki/Python_(programming_language)&lt;br /&gt;
7. https://en.wikipedia.org/wiki/VPython#History&lt;/div&gt;</summary>
		<author><name>Mmorris83</name></author>
	</entry>
	<entry>
		<id>http://www.physicsbook.gatech.edu/index.php?title=VPython_Functions&amp;diff=38026</id>
		<title>VPython Functions</title>
		<link rel="alternate" type="text/html" href="http://www.physicsbook.gatech.edu/index.php?title=VPython_Functions&amp;diff=38026"/>
		<updated>2019-10-22T06:52:06Z</updated>

		<summary type="html">&lt;p&gt;Mmorris83: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Introduction to functions in Python and applying them to write shorter and more understandable code.&lt;br /&gt;
Assumes that VPython is [http://www.physicsbook.gatech.edu/VPython installed] and you understand the [http://www.physicsbook.gatech.edu/VPython_basics basics] of programming in Python.&lt;br /&gt;
&lt;br /&gt;
==Summary==&lt;br /&gt;
&lt;br /&gt;
Functions at a high level are used to perform a certain task. Functions can accept a number of inputs (also &amp;quot;arguments&amp;quot; or &amp;quot;parameters&amp;quot;) and can give back 0 or 1 output values. Furthermore, they make code much easier to understand by encapsulating a task in a single line of code instead of being repeated over and over again.&lt;br /&gt;
&lt;br /&gt;
Functions always start with def, which is short for define, used to define a word with a piece of code, not data.&lt;br /&gt;
	• Function is like a box of commands&lt;br /&gt;
	• Functions can take inputs&lt;br /&gt;
	• The way we pass those inputs is by putting them in parenthesis&lt;br /&gt;
Functions can return objects (outputs)&lt;br /&gt;
&lt;br /&gt;
 def sayHello():&lt;br /&gt;
   print &amp;quot;Hello, world&amp;quot;&lt;br /&gt;
&lt;br /&gt;
This is a simple function that defines the variable &amp;quot;sayHello&amp;quot; to return the phrase &amp;quot;Hello, world&amp;quot; (note that the parenthesis will not be printed. Only the &#039;&#039;Hello, world&#039;&#039; portion will be printed).&lt;br /&gt;
&lt;br /&gt;
	• Note that python uses indent to consider what is under a command. If  print &amp;quot;Hello, world&amp;quot; is not indented, then it will not be a part of the function sayHello().&lt;br /&gt;
&lt;br /&gt;
===Automating problems with VPython===&lt;br /&gt;
&lt;br /&gt;
 1.When you are trying to simulate multi-particle systems that require hundreds of calculations&lt;br /&gt;
 2.Sometimes when you are having trouble understanding homework problems solving it with python can help you understand hard to grasp concepts.&lt;br /&gt;
&lt;br /&gt;
==Basic of Functions==&lt;br /&gt;
&lt;br /&gt;
===Basic Python function syntax===&lt;br /&gt;
Functions can be defined with the keyword &amp;quot;def&amp;quot; followed by the function name and a colon and a parenthesis.&lt;br /&gt;
The variable that should be processed by the function goes Inside the parenthesis.&lt;br /&gt;
&lt;br /&gt;
 def madlib(name, noun1, noun2, verb):&lt;br /&gt;
   result = name + &amp;quot; was looking at his &amp;quot; + noun1 + &amp;quot; when a &amp;quot; + noun2 + &amp;quot; &amp;quot; + verb + &amp;quot; nearby.&amp;quot;&lt;br /&gt;
   print result&lt;br /&gt;
&lt;br /&gt;
This is a simple function that creates a madlib with the 4 variables that are given as inputs.&lt;br /&gt;
&lt;br /&gt;
For example, if Sally was inputed as the name, lunch as noun1, pterodactyl as noun2, and flew as the verb, the the function will return the phrase &#039;&#039;Sally was looking at his lunch when a pterodactyl flew nearby&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; madlib(&amp;quot;Sally&amp;quot;, &amp;quot;lunch&amp;quot;, &amp;quot;pterodactyl&amp;quot;, &amp;quot;flew&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
Sally was looking at his lunch when a pterodactyl flew nearby.&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Returning the output given by a function===&lt;br /&gt;
&lt;br /&gt;
When a function takes an input and gives an output such as &amp;lt;code&amp;gt;print&amp;lt;/code&amp;gt; in the madlib example, you cannot refer back to the output phrase &amp;lt;code&amp;gt;Sally was looking at his lunch when a pterodactyl flew nearby.&amp;lt;/code&amp;gt;&lt;br /&gt;
If you would like to use this phrase again, then a function called &amp;lt;code&amp;gt;return&amp;lt;/code&amp;gt; is needed.&lt;br /&gt;
When &amp;lt;code&amp;gt;return&amp;lt;/code&amp;gt; is added at the end of a function, the output is passed back to the caller, which means that you can refer to the output now.&lt;br /&gt;
&lt;br /&gt;
 def madlib(name, noun1, noun2, verb):&lt;br /&gt;
   result = name + &amp;quot; was looking at his &amp;quot; + noun1 + &amp;quot; when a &amp;quot; + noun2 + &amp;quot; &amp;quot; + verb + &amp;quot; nearby.&amp;quot;&lt;br /&gt;
   print result&lt;br /&gt;
   return result&lt;br /&gt;
&lt;br /&gt;
With this new code, if you need to refer to the sentence &amp;lt;code&amp;gt;Sally was looking at his lunch when a pterodactyl flew nearby.&amp;lt;/code&amp;gt;, you can do so by by typing in &amp;lt;code&amp;gt;result&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
===Example function===&lt;br /&gt;
&lt;br /&gt;
 # This function adds three numbers together and gives back the result using the return keyword&lt;br /&gt;
 def addNumbers(a, b, c):&lt;br /&gt;
     return a + b + c&lt;br /&gt;
&lt;br /&gt;
===Conditional Statement===&lt;br /&gt;
Lets say you have the following code:&lt;br /&gt;
&lt;br /&gt;
 # This function prints every letter in the input&lt;br /&gt;
 def printLetters(string):&lt;br /&gt;
  for letter in string:&lt;br /&gt;
   print letter&lt;br /&gt;
&lt;br /&gt;
What if your &#039;&#039;evil&#039;&#039; TA asks you to only print the vowel letters given in the input?&lt;br /&gt;
This means that you need to add a condition to your function where the &amp;lt;code&amp;gt;print&amp;lt;/code&amp;gt; function only works if the letter is a vowel.&lt;br /&gt;
This can be done by using &#039;&#039;&#039;conditional statement&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
Condtional statement starts with &amp;lt;code&amp;gt;if&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
 def justvowels(string):&lt;br /&gt;
  for letter in string:&lt;br /&gt;
    if letter in &amp;quot;aeiou&amp;quot;:&lt;br /&gt;
      print letter&lt;br /&gt;
&lt;br /&gt;
Instead of printing every letter in the string, this code will only print &#039;&#039;&#039;if&#039;&#039;&#039; the letter in question can be found in the list &amp;quot;a,e,i,o,u&amp;quot;&lt;br /&gt;
&lt;br /&gt;
==Writing your own Functions==&lt;br /&gt;
Writing a function for a task instead of copy and pasting code makes your program much easier to understand and debug. &lt;br /&gt;
&lt;br /&gt;
===When to write a function===&lt;br /&gt;
 1. You have a multi particle system&lt;br /&gt;
 2. You are calculating multiple forces on multiple particles over each time step&lt;br /&gt;
 3. You try not to use functions but keep running into errors or you see behaviors that don&#039;t look right. &lt;br /&gt;
&lt;br /&gt;
===When NOT to write a function===&lt;br /&gt;
 1. You have a simple system consisting of one particle and less than 3 or so forces&lt;br /&gt;
 2. You only need to find 4 or 5 values pertaining to the kinematics of the object&lt;br /&gt;
 3. You would be creating more trouble if you were writing function. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For example, to write a function that calculates the electric field created by a point charge, we first find the formula.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\overrightarrow{E}=\frac{1}{4πε_0}  \frac{q}{|\overrightarrow{r}|^2} \hat r&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then, we ask ourselves what we need in order to calculate the electric field?&lt;br /&gt;
* &amp;lt;math&amp;gt;q&amp;lt;/math&amp;gt; - the charge of the source&lt;br /&gt;
* &amp;lt;math&amp;gt;\overrightarrow{r}&amp;lt;/math&amp;gt; - the distance from the source to the electric field&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;q&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;\overrightarrow{r}&amp;lt;/math&amp;gt; will be the two arguments to our function which will look like this:&lt;br /&gt;
 &lt;br /&gt;
We start by creating a sphere for a point charge&lt;br /&gt;
 p = sphere(pos=(-5e-11,0,0), radius=1e-11, color=color.red)&lt;br /&gt;
 &lt;br /&gt;
We also need to define the observation point where we calculate the electric field created by the point charge&lt;br /&gt;
 obslocation = vector(1, 1, 1)&lt;br /&gt;
&lt;br /&gt;
r, the distance between the obslocation and p&lt;br /&gt;
 r = obslocation - p.pos&lt;br /&gt;
&lt;br /&gt;
 # We can now write a function that calculates the electric field at a point away from the charge&lt;br /&gt;
 def electricField(q, r):&lt;br /&gt;
     electricConstant = 9e9&lt;br /&gt;
     rmag = sqrt((ap.x)**2+(ap.y)**2+(ap.z)**2)&lt;br /&gt;
     rhat = r / rmag&lt;br /&gt;
     E = (electricConstant * q / rmag**2)*rhat&lt;br /&gt;
     return E&lt;br /&gt;
&lt;br /&gt;
The final code will look like this:&lt;br /&gt;
&lt;br /&gt;
 from __future__ import division&lt;br /&gt;
 from visual import * &lt;br /&gt;
 p = sphere(pos=(-5e-11,0,0), radius=1e-11, color=color.red)&lt;br /&gt;
 obslocation = vector(1, 1, 1)&lt;br /&gt;
 r = obslocation - p.pos&lt;br /&gt;
 def electricField(q, r):&lt;br /&gt;
     electricConstant = 9e9&lt;br /&gt;
     rmag = sqrt((ap.x)**2+(ap.y)**2+(ap.z)**2)&lt;br /&gt;
     rhat = r / rmag&lt;br /&gt;
     E = (electricConstant * q / rmag**2)*rhat&lt;br /&gt;
     return E&lt;br /&gt;
&lt;br /&gt;
===Using the function===&lt;br /&gt;
&lt;br /&gt;
We can apply functions to make our code shorter and easier to understand. Here is some example code that we will shorten with functions.&lt;br /&gt;
&lt;br /&gt;
 # Calculate the eletric field in two different places&lt;br /&gt;
 charge = 1.6e-19&lt;br /&gt;
 origin = vector(0,0,0)&lt;br /&gt;
 &lt;br /&gt;
 point1 = vector(-10, 5, 15)&lt;br /&gt;
 point2 = vector(20, -5, 12)&lt;br /&gt;
 &lt;br /&gt;
 field1 = 9e9 * charge * point1.norm() / point1.mag2&lt;br /&gt;
 field2 = 9e9 * charge * point2.norm() / point2.mag2&lt;br /&gt;
&lt;br /&gt;
We can use a function in the last 2 lines to reduce the duplicated code to the following&lt;br /&gt;
&lt;br /&gt;
 field1 = electricField(charge, point1)&lt;br /&gt;
 field2 = electricField(charge, point2)&lt;br /&gt;
&lt;br /&gt;
==Frequently Used Functions==&lt;br /&gt;
&lt;br /&gt;
VPython already has a few predefined functions for your ease. The following functions are available for working with vectors.&lt;br /&gt;
To better illustrate these functions, let&#039;s say we have a vector called exVector.&lt;br /&gt;
&lt;br /&gt;
 exVector = vector(-10, 2 ,5)&lt;br /&gt;
&lt;br /&gt;
===mag()===&lt;br /&gt;
 # Calculates the magnitude of a vector&lt;br /&gt;
 magExVector = mag(exVector)&lt;br /&gt;
 print magExVector    # will print 11.357&lt;br /&gt;
&lt;br /&gt;
===mag2(A)===&lt;br /&gt;
 # Calculates the magnitude squared of a vector&lt;br /&gt;
 mag2ExVector = mag2(exVector)&lt;br /&gt;
 print magExVector     # will print 129&lt;br /&gt;
&lt;br /&gt;
===norm(A)===&lt;br /&gt;
 # Calculates the unit vector of a vector&lt;br /&gt;
 unitExVector = norm(exVector)&lt;br /&gt;
 print unitExVector    # will print &amp;lt;-0.88, 0.17, 0.44&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===dot(A, B)===&lt;br /&gt;
 # Calculates the scalar dot product between the two vectors&lt;br /&gt;
 # exVector2 = vector(4, -2 ,8)&lt;br /&gt;
 dotExVector = dot(exVector, exVector2)&lt;br /&gt;
 print dotExVector     # will print 4&lt;br /&gt;
&lt;br /&gt;
===cross(A, B)===&lt;br /&gt;
 # Calculates the vector cross product between two vectors&lt;br /&gt;
 # exVector2 = vector(4, -2 ,8)&lt;br /&gt;
 crossExVector = cross(exVector, exVector2)&lt;br /&gt;
 print crossExVector   # will print &amp;lt;26, 100, 12&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Example of using these common functions==&lt;br /&gt;
&lt;br /&gt;
Remember this code from the &#039;&#039;&#039;Writing your own Functions&#039;&#039;&#039; section?&lt;br /&gt;
 &lt;br /&gt;
 def electricField(q, r):&lt;br /&gt;
     electricConstant = 9e9&lt;br /&gt;
     rmag = sqrt((ap.x)**2+(ap.y)**2+(ap.z)**2)&lt;br /&gt;
     rhat = r / rmag&lt;br /&gt;
     E = (electricConstant * q / rmag**2)*rhat&lt;br /&gt;
     return E&lt;br /&gt;
&lt;br /&gt;
We can now simplify this code using some of the common functions listed in &#039;&#039;&#039;Frequently Used Functions&#039;&#039;&#039; section.&lt;br /&gt;
&lt;br /&gt;
 def electricField(q, r):&lt;br /&gt;
     electricConstant = 9e9&lt;br /&gt;
     E = electricConstant * q * r.norm() / r.mag2&lt;br /&gt;
     return E&lt;br /&gt;
&lt;br /&gt;
It is also possible to skip defining the &amp;lt;code&amp;gt;electricConstant * q * r.norm() / r.mag2&amp;lt;/code&amp;gt; function and just return it.&lt;br /&gt;
&lt;br /&gt;
 def electricField(q, r):&lt;br /&gt;
     electricConstant = 9e9&lt;br /&gt;
     return electricConstant * q * r.norm() / r.mag2&lt;br /&gt;
&lt;br /&gt;
==Examples (Continued)==&lt;br /&gt;
&lt;br /&gt;
With Vpython it is possible to make graphs with ease by simply referencing a x axis and providing values that correspond with the x axis and have a value that can be plotted on the y axis. &lt;br /&gt;
&lt;br /&gt;
To start you must import the necessary library:&lt;br /&gt;
&lt;br /&gt;
 from visual.graph import *&lt;br /&gt;
&lt;br /&gt;
Then make a variable and declare what your x axis will be as well as color properties:&lt;br /&gt;
 &lt;br /&gt;
 f1 = gcurve(color=color.cyan)&lt;br /&gt;
&lt;br /&gt;
Every time you iterate through a loop use your index (most likely time elapsed) and a output value to add a point to your plot:&lt;br /&gt;
&lt;br /&gt;
  f1.plot(pos=(x,outputValue)) &lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
 &lt;br /&gt;
[[File:Graph1Ahennessy.png|500px]]&lt;br /&gt;
&lt;br /&gt;
==Connectedness==&lt;br /&gt;
Functions are used everywhere in coding.&lt;br /&gt;
For example, in computational media, coding is used to modify pictures, sounds, and movies.&lt;br /&gt;
Of course, we now mostly rely on editing programs, but underneath that program, when you press a button to trace the edges of a picture, the program finds the function that it runs and returns the output.&lt;br /&gt;
Such a code made look like this:&lt;br /&gt;
&lt;br /&gt;
 def luminance(pixel):&lt;br /&gt;
   r = getRed(pixel)&lt;br /&gt;
   g = getGreen(pixel)&lt;br /&gt;
   b = getBlue(pixel)&lt;br /&gt;
   return (r+g+b)/3&lt;br /&gt;
&lt;br /&gt;
 def edgeDetect(picture):&lt;br /&gt;
   for p in getPixels(picture):&lt;br /&gt;
     x = getX(p)	&lt;br /&gt;
     y = getY(p)&lt;br /&gt;
     if y &amp;lt; getHeight(picture) - 1 and x &amp;lt; getWidth(picture) - 1:&lt;br /&gt;
       botrt = getPixel(picture, x+1, y+1)&lt;br /&gt;
       thislum = luminance(p)&lt;br /&gt;
       brlum = luminance(botrt)&lt;br /&gt;
       if abs(brlum - thislum) &amp;gt; 8:&lt;br /&gt;
         setColor(p, blue)&lt;br /&gt;
       if abs(brlum - thislum) &amp;lt;= 8:&lt;br /&gt;
         setColor(p, white)&lt;br /&gt;
&lt;br /&gt;
When this program is run with the picture on the left, the output is the picture on the right.&lt;br /&gt;
&lt;br /&gt;
[[File:HW 2 Picture Original.png]] [[File:eiffel2.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Connectedness(Taking Vpython core functions and creating a simulation)==&lt;br /&gt;
Many Vpython assignments require the creation of functions that can calculate Momentum,impulse,velocity Position&lt;br /&gt;
Below are some frequently used equations that can be adapted to certain problem sets:&lt;br /&gt;
&lt;br /&gt;
===Momentum===&lt;br /&gt;
&lt;br /&gt;
 def returnMomentum(vparticle,mparticle):&lt;br /&gt;
    momentum = vector(0,0,0)&lt;br /&gt;
    return vparticle*mparticle + momentum&lt;br /&gt;
 momentum = returnMomentum(vparticle,mparticle)&lt;br /&gt;
&lt;br /&gt;
===impulse===&lt;br /&gt;
&lt;br /&gt;
 # deltat = timestep in simulation. &lt;br /&gt;
 def returnImpulse(momentum,deltat):&lt;br /&gt;
    impulse = vector(0,0,0)&lt;br /&gt;
    return momentum*deltat&lt;br /&gt;
 impulse = returnImpulse(momentum,deltat)&lt;br /&gt;
&lt;br /&gt;
===velocity===&lt;br /&gt;
&lt;br /&gt;
 def returnVelocity(impulse,mparticle,velocity):&lt;br /&gt;
    velocity = vector(0,0,0)&lt;br /&gt;
    velocity = (impulse/mparticle)+velocity&lt;br /&gt;
    return velocity&lt;br /&gt;
 velocity = returnVelocity(impulse,mparticle,velocity)&lt;br /&gt;
&lt;br /&gt;
===position===&lt;br /&gt;
&lt;br /&gt;
 def returnPosition(position, velocity, deltat):&lt;br /&gt;
    position = vector(0,0,0)&lt;br /&gt;
    position = position + velocity*deltat&lt;br /&gt;
    return position&lt;br /&gt;
 position = returnPosition(position, velocity , deltat)&lt;br /&gt;
&lt;br /&gt;
===Drag force===&lt;br /&gt;
 def returnDragforce(dragcoef,velocity,density,area):&lt;br /&gt;
    dragForce = dragcoef*((density*(velocity**2))/2)*area&lt;br /&gt;
    dragForce = dragForce * -1 * norm(velocity)&lt;br /&gt;
    return dragForce&lt;br /&gt;
 dragForce = returnDragforce(dragcoef,velocity,density,area)&lt;br /&gt;
&lt;br /&gt;
===Bringing Everything Together===&lt;br /&gt;
&lt;br /&gt;
[[File:Ezgif-5-93f2b472a8.gif]]&lt;br /&gt;
&lt;br /&gt;
== See also ==&lt;br /&gt;
&lt;br /&gt;
===Prerequisites===&lt;br /&gt;
[http://www.physicsbook.gatech.edu/VPython VPython]&lt;br /&gt;
&lt;br /&gt;
[http://www.physicsbook.gatech.edu/VPython_basics VPython Basics]&lt;br /&gt;
&lt;br /&gt;
===Further reading===&lt;br /&gt;
&lt;br /&gt;
[http://www.physicsbook.gatech.edu/VPython_Common_Errors_and_Troubleshooting VPython Common Errors and Troubleshooting]&lt;br /&gt;
&lt;br /&gt;
[http://www.physicsbook.gatech.edu/VPython_Lists VPython Lists]&lt;br /&gt;
&lt;br /&gt;
[https://docs.python.org/2/library/functions.html Python standard function library].&lt;br /&gt;
&lt;br /&gt;
[https://www.tutorialspoint.com/python/python_functions.htm Python Functions Tutorial]&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category: Modeling with VPython]]&lt;/div&gt;</summary>
		<author><name>Mmorris83</name></author>
	</entry>
	<entry>
		<id>http://www.physicsbook.gatech.edu/index.php?title=VPython_Common_Errors_and_Troubleshooting&amp;diff=38025</id>
		<title>VPython Common Errors and Troubleshooting</title>
		<link rel="alternate" type="text/html" href="http://www.physicsbook.gatech.edu/index.php?title=VPython_Common_Errors_and_Troubleshooting&amp;diff=38025"/>
		<updated>2019-10-22T06:51:47Z</updated>

		<summary type="html">&lt;p&gt;Mmorris83: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Programming languages can often generate obscure and confusing error messages, and VPython is no exception.  This reference lists out the most common types of errors students encounter, with a brief explanation of why they happen and how to fix them.&lt;br /&gt;
&lt;br /&gt;
==System/Environment Errors==&lt;br /&gt;
&lt;br /&gt;
If your system is not set up correctly, or the environment you are running VPython code is incorrect, a number of mysterious errors can result.  &lt;br /&gt;
&lt;br /&gt;
=== VPython does not start or immediately freezes ===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Make sure you are running your code in VIDLE (not the identical-looking IDLE).&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
[[File:use_vidle.jpg|300px|thumb|left|Use VIDLE instead of IDLE to avoid errors and crashes.]]&lt;br /&gt;
&lt;br /&gt;
With the most current releases of VPython, code compiles and launches fine in IDLE, but the graphics window comes up grey and hangs.  This is because of a bug in the way regular IDLE executes code, it has difficulty with programs that keep running in a loop, as VPython does so you can drag and zoom the display.&lt;br /&gt;
&lt;br /&gt;
Note that &#039;&#039;&#039;if you double-click a .py file in Windows Explorer or Finder, it may open up in the regular IDLE instead of VIDLE&#039;&#039;&#039;.  To check if your code is open in VIDLE, click the &amp;quot;Help&amp;quot; menu and look for the &amp;quot;VPython&amp;quot; menu item.  Regular IDLE does not have a &amp;quot;VPython&amp;quot; item in the Help menu.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;clear: both&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== ImportError: No module named * ===&lt;br /&gt;
&lt;br /&gt;
 Traceback (most recent call last):&lt;br /&gt;
   File &amp;quot;/my/documents/folder/vectors.py&amp;quot;, line 1&lt;br /&gt;
     from future import division&lt;br /&gt;
 ImportError: No module named future&lt;br /&gt;
&lt;br /&gt;
Python has only a small number of [https://docs.python.org/2/library/functions.html built-in functions].  The rest are stored in &amp;quot;modules&amp;quot; that you can load when you need them.  The &amp;lt;code&amp;gt;from (blank) import (blank)&amp;lt;/code&amp;gt; lines tell Python to import the named functions from a specific module.  When you import a module, Python searches various folders on your computer to find the requested module.  If it cannot find a module with that name, you get an ImportError.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Cause #1:&#039;&#039;&#039; You made a typo in the module name.&lt;br /&gt;
&lt;br /&gt;
The basic boilerplate for VPython programs written in this class:&lt;br /&gt;
&lt;br /&gt;
 from __future__ import division&lt;br /&gt;
 from visual import *&lt;br /&gt;
&lt;br /&gt;
Often missed are the &#039;&#039;&#039;two underscores&#039;&#039;&#039; (&amp;lt;code&amp;gt; _ _ &amp;lt;/code&amp;gt;) not separated by a space before and after &amp;lt;code&amp;gt;future&amp;lt;/code&amp;gt;.  Check that this is correct, or copy-and-paste from above.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Cause #2:&#039;&#039;&#039; VPython is not installed correctly.&lt;br /&gt;
&lt;br /&gt;
It is possible the module actually does not exist on your system.  The VPython installer should install all the needed modules into the module folder for Python 2.7.  If you have a different version of Python installed, it will not be able to find the modules.  Make sure to follow the instructions on the VPython website, and install Python 2.7 from python.org as suggested.&lt;br /&gt;
&lt;br /&gt;
=== NameError: name &#039;gdisplay&#039; is not defined ===&lt;br /&gt;
&lt;br /&gt;
This is often indicative of a missing import statement.  Make sure your code begins with the boilerplate code above.&lt;br /&gt;
&lt;br /&gt;
If you are using the graph functions, you will also need:&lt;br /&gt;
&lt;br /&gt;
 from visual.graph import *&lt;br /&gt;
&lt;br /&gt;
===&amp;quot;The function ‘CGContextErase’ is obsolete&amp;quot;===&lt;br /&gt;
&lt;br /&gt;
Users on Mac OS X may see this message printed whenever they run a VPython program:&lt;br /&gt;
&lt;br /&gt;
 The function ‘CGContextErase’ is obsolete and will be removed in an upcoming update.&lt;br /&gt;
 Unfortunately, this application, or a library it uses, is using this obsolete function, &lt;br /&gt;
 and is thereby contributing to an overall degradation of system performance.&lt;br /&gt;
&lt;br /&gt;
This message can be ignored and will have no impact on the running of your program.&lt;br /&gt;
&lt;br /&gt;
== Syntax Errors ==&lt;br /&gt;
&lt;br /&gt;
A syntax error means Python cannot figure out what your program is asking it to do because you did not follow its grammar. VIDLE will highlight where the error occurred, but sometimes this highlight is misleading.&lt;br /&gt;
&lt;br /&gt;
===Make sure parenthesis match up ===&lt;br /&gt;
&lt;br /&gt;
Consider the following code (asterisks were placed around the part that where IDLE reported the syntax error):&lt;br /&gt;
&lt;br /&gt;
 ## objects&lt;br /&gt;
 particle = sphere(pos=vector(1e-10,0,0), radius=2e-11, color=color.red&lt;br /&gt;
 &lt;br /&gt;
 ## initial values&lt;br /&gt;
 ***obslocation*** = vector(3.1e-10, -2.1e-10, 0)  &amp;lt;- Error at word &amp;quot;obslocation&amp;quot;&lt;br /&gt;
&lt;br /&gt;
You can look at that line all you want, but there is no error there.  Instead, look at the end of the &amp;lt;code&amp;gt;particle = sphere(...&amp;lt;/code&amp;gt; line.  Notice there is no closing parenthesis.&lt;br /&gt;
&lt;br /&gt;
 ## objects&lt;br /&gt;
 particle = sphere(pos=vector(1e-10,0,0), radius=2e-11, color=color.red  &amp;lt;- Actual problem is HERE&lt;br /&gt;
 &lt;br /&gt;
 ## initial values&lt;br /&gt;
 ***obslocation*** = vector(3.1e-10, -2.1e-10, 0)  &amp;lt;- Python reports error at word &amp;quot;obslocation&amp;quot;&lt;br /&gt;
&lt;br /&gt;
To fix this error, change the line to:&lt;br /&gt;
&lt;br /&gt;
 particle = sphere(pos=vector(1e-10,0,0), radius=2e-11, color=color.red)    &amp;lt;- closing parenthesis added&lt;br /&gt;
&lt;br /&gt;
===Rules for variable names===&lt;br /&gt;
&lt;br /&gt;
When Python is reading your code, it has to be able to identify when you are referring to a variable, as opposed to some other language construct, such as a literal number.  Here are a few rules to keep in mind:&lt;br /&gt;
&lt;br /&gt;
* Variable names cannot contain spaces&lt;br /&gt;
* Variable names cannot start with a number&lt;br /&gt;
* Variable names cannot contain dashes (-), but underscores (_) are allowed&lt;br /&gt;
* Variable must not have the same name as built-in functions, statements, etc.&lt;br /&gt;
&lt;br /&gt;
===While Loop Indentation===&lt;br /&gt;
&lt;br /&gt;
In Python, while loops and if statements rely on indentation to define where they start and end.  When you&#039;re working with a while loop, &#039;&#039;&#039;every line of code inside the loop should have the same number of spaces in front of it&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
 while t &amp;lt;= 3.0:&lt;br /&gt;
     rate(3500)       ## slow down motion to make animation look nicer&lt;br /&gt;
 &lt;br /&gt;
     # Calculate Fgrav btwn. craft and the Earth&lt;br /&gt;
    rCraftEarth = Craft.pos - Earth.pos     &amp;lt;- Error: incorrect indentation&lt;br /&gt;
     fMagG1 = (G * mCraft * mEarth)/(mag(rCraftEarth) * mag(rCraftEarth))&lt;br /&gt;
&lt;br /&gt;
If you fail to indent a line in the middle of a loop, Python is quite good about reporting it.  If you fail to indent a line at the end of a loop, Python assumes you meant for it to be outside of the loop, which does not generate any error but can cause your code to work incorrectly.&lt;br /&gt;
&lt;br /&gt;
 while t &amp;lt;= 3.0:&lt;br /&gt;
     rate(3500)       ## slow down motion to make animation look nicer&lt;br /&gt;
 &lt;br /&gt;
     (...)&lt;br /&gt;
 &lt;br /&gt;
 t = t + deltat    &amp;lt;- This line should be in the loop, but it is not.&lt;br /&gt;
&lt;br /&gt;
What belongs in the loop?  The hard and fast answer is &#039;&#039;&#039;anything that need to happen over and over again&#039;&#039;&#039;.  That&#039;s what the loop does: it runs the same code over and over again until its condition tells it to stop.  If you&#039;re animating an object that is experiencing a gravitational force, obviously we need to calculate the force over and over again.  We also need to update the particle&#039;s position and update the arrow each time as well.&lt;br /&gt;
&lt;br /&gt;
Anything outside of the loop is executed only once.  In the example above, we left updating the time out of the loop.  Obviously, we meant for the time to increase with each run of the loop, but by leaving it out, this doesn&#039;t happen (n this particular example, because the loop depends on the time to know when to stop, the program would loop infinitely and our particle would never stop moving).&lt;br /&gt;
&lt;br /&gt;
== Runtime Errors ==&lt;br /&gt;
&lt;br /&gt;
Even if Python understands the syntax of your program, it can still contain errors that pop up when it tries to run.&lt;br /&gt;
&lt;br /&gt;
=== TypeError: unsupported operand type(s) for * ===&lt;br /&gt;
&lt;br /&gt;
Consider this error and the line of code that produced it:&lt;br /&gt;
&lt;br /&gt;
 Traceback (most recent call last):&lt;br /&gt;
   File &amp;quot;/my/documents/folder/lab2.py&amp;quot;, line 32&lt;br /&gt;
     E = oofpez * (qproton / (r**2)) * rhat&lt;br /&gt;
 TypeError: unsupported operand type(s) for ** or pow(): &#039;vector&#039; and &#039;int&#039;&lt;br /&gt;
&lt;br /&gt;
The error indicates that &amp;lt;code&amp;gt;pow()&amp;lt;/code&amp;gt;, i.e. the exponent function, cannot operate on a &amp;lt;code&amp;gt;vector&amp;lt;/code&amp;gt; and an &amp;lt;code&amp;gt;int&amp;lt;/code&amp;gt; (an int is short for integer, a.k.a. a number/scalar).&lt;br /&gt;
&lt;br /&gt;
 r = vector(5, 4, 3) - particle.pos&lt;br /&gt;
 rmag = sqrt(r.x**2 + r.y**2 + r.z**2)&lt;br /&gt;
 rhat = r / rmag&lt;br /&gt;
 E = oofpez * (qproton / (r**2)) * rhat  &amp;lt;-- ERROR&lt;br /&gt;
&lt;br /&gt;
Looking at the code, we see that we typed &amp;lt;code&amp;gt;r ** 2&amp;lt;/code&amp;gt;, i.e. squaring the vector r, or as we&#039;d write it out on paper:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\vec{r}^2 = \vec{r} * \vec{r} = &amp;lt;5, 4, 3&amp;gt; * &amp;lt;5, 4, 3&amp;gt;&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you&#039;ve taken linear algebra before, you&#039;re probably aware that multiplying vectors or matrices is very different from simply multiplying out scalars, and in fact, in this case, is undefined.  The correct code here might have been:&lt;br /&gt;
&lt;br /&gt;
 E = oofpez * (qproton / (rmag**2)) * that&lt;br /&gt;
&lt;br /&gt;
Some other operations to look out for:&lt;br /&gt;
&lt;br /&gt;
* Adding or subtracting a scalar from a vector or vice-versa&lt;br /&gt;
* Divining a scalar by a vector&lt;br /&gt;
* Multiplying or dividing two vectors&lt;br /&gt;
&lt;br /&gt;
In VPython, there&#039;s no syntax to indicate that a variable is a vector. The easiest way to tell is look at where it was defined.  For example, if we created the variable &amp;lt;code&amp;gt;position&amp;lt;/code&amp;gt; with any of these lines of code, it would hold a vector:&lt;br /&gt;
&lt;br /&gt;
 position = vector(5, 4, 3)&lt;br /&gt;
 position = (5, 4, 3)&lt;br /&gt;
 position = arrow.pos     // arrow.pos is a vector property of the arrow object&lt;br /&gt;
 position = arrow.pos * 5     // vector multiplied by a scalar is a vector&lt;br /&gt;
&lt;br /&gt;
When tracing these errors, always look and make sure your variables hold the type of data you expect.  When all else fails, you can use &amp;lt;code&amp;gt;print(variable name)&amp;lt;/code&amp;gt; to examine the value.&lt;br /&gt;
&lt;br /&gt;
=== ArgumentError: Python argument types in *** did not match C++ signature ===&lt;br /&gt;
&lt;br /&gt;
If you pass the wrong type of data to a function, VPython prints all kinds of nasty jargon out.&lt;br /&gt;
&lt;br /&gt;
 ArgumentError: Python argument types in&lt;br /&gt;
     None.None(arrow, int)&lt;br /&gt;
 did not match C++ signature:&lt;br /&gt;
     None(cvisual::primitive {lvalue}, cvisual::vector)&lt;br /&gt;
&lt;br /&gt;
What the heck is a &amp;lt;code&amp;gt;cvisual::primitive {lvalue}&amp;lt;/code&amp;gt;?  Who knows? (it&#039;s some internal data type in the C++ code for VPython, and it&#039;s an error in VPython that we see this message instead of a nicer, more explanatory one).  Our code that caused this error:&lt;br /&gt;
&lt;br /&gt;
 r = sqrt(5 ** 2 + 4 ** 2 + 3**2)&lt;br /&gt;
 ea = arrow(pos=r, axis=E*scale, color=color.orange)&lt;br /&gt;
&lt;br /&gt;
r was likely assumed to be a vector, but it actually appears to hold the magnitude of a vector someone calculated.&lt;br /&gt;
&lt;br /&gt;
Consider another example:&lt;br /&gt;
&lt;br /&gt;
 Traceback (most recent call last):&lt;br /&gt;
   File &amp;quot;/my/documents/folder/lab2.py&amp;quot;, line 33&lt;br /&gt;
     r = vector(x, 5, 2)&lt;br /&gt;
 ArgumentError: Python argument types in&lt;br /&gt;
     vector.__init__(vector, vector, int, int)&lt;br /&gt;
 did not match C++ signature:&lt;br /&gt;
     __init__(_object*, cvisual::vector)&lt;br /&gt;
     __init__(_object*)&lt;br /&gt;
     __init__(_object*, double)&lt;br /&gt;
     __init__(_object*, double, double)&lt;br /&gt;
     __init__(_object*, double, double, double)&lt;br /&gt;
&lt;br /&gt;
The error points at this line:&lt;br /&gt;
&lt;br /&gt;
 r = vector(x, 5, 2)&lt;br /&gt;
&lt;br /&gt;
Huh.  That looks OK.  Let&#039;s see how x is defined:&lt;br /&gt;
&lt;br /&gt;
 x = particle.pos&lt;br /&gt;
 print(x)     // prints out &amp;lt;5, 4, 3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Apparently x is a vector.  So the line that threw the error looks like this to the computer:&lt;br /&gt;
&lt;br /&gt;
 r = vector(vector(5, 4, 3), 5, 2)     // This clearly doesn&#039;t make any sense&lt;br /&gt;
&lt;br /&gt;
Hence, when you see these kind of errors, always inspect the arguments you pass to the function, and if any of them are a variable, &#039;&#039;&#039;look back at how the variable was defined&#039;&#039;&#039;.  If all else fails, try placing each argument into a &amp;lt;code&amp;gt;print()&amp;lt;/code&amp;gt; statement separately and make sure what prints out is the type you expect.&lt;br /&gt;
&lt;br /&gt;
=== TypeError: &#039;*&#039; object is not callable ===&lt;br /&gt;
&lt;br /&gt;
In Python, function names are variables too, and are not protected in any way.  Because of this, it is totally legal to write:&lt;br /&gt;
&lt;br /&gt;
 vector = vector(5, 4, 3)&lt;br /&gt;
&lt;br /&gt;
Here, we just replaced the vector function with, well, an actual vector.  When we try to create another vector later, we&#039;re actually attempting to call our vector variable as if it were a function.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Make sure you do not name a variable the same name as a function&#039;&#039;&#039;!&lt;br /&gt;
&lt;br /&gt;
Also resist the temptation to create a sphere named sphere:&lt;br /&gt;
&lt;br /&gt;
 sphere = sphere(pos=(1,0,0), radius=2e-11, color=color.red)  // Our &amp;quot;sphere&amp;quot; just replaced the &amp;quot;sphere&amp;quot; function&lt;br /&gt;
&lt;br /&gt;
If you do this, the error will not show up until you try to use the &amp;lt;code&amp;gt;sphere()&amp;lt;/code&amp;gt; function later, which may be several lines after the actual mistake.  Instead, simply name you &amp;lt;code&amp;gt;sphere&amp;lt;/code&amp;gt; something like &amp;lt;code&amp;gt;mySphere&amp;lt;/code&amp;gt; or even better, use a precise name such as &amp;lt;code&amp;gt;sphereA&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;electron&amp;lt;/code&amp;gt; (assuming the sphere represents an electron).  Remember, the name of variables is just a name—&#039;&#039;&#039;you can name your variables whatever you want (provided it is valid syntax), &#039;&#039;just don&#039;t name it after an existing function&#039;&#039;&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
[[Category:VPython]]&lt;/div&gt;</summary>
		<author><name>Mmorris83</name></author>
	</entry>
	<entry>
		<id>http://www.physicsbook.gatech.edu/index.php?title=VPython_basics&amp;diff=38024</id>
		<title>VPython basics</title>
		<link rel="alternate" type="text/html" href="http://www.physicsbook.gatech.edu/index.php?title=VPython_basics&amp;diff=38024"/>
		<updated>2019-10-22T06:51:33Z</updated>

		<summary type="html">&lt;p&gt;Mmorris83: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This is a beginning overview to vPython with some basic syntax and functions. &lt;br /&gt;
&lt;br /&gt;
==Installation or Online Use==&lt;br /&gt;
&lt;br /&gt;
Python can be rather difficult to install. However, you can use an online version in order to do all code online. &lt;br /&gt;
===Online/ Glowscript===&lt;br /&gt;
1. Go to [http://www.glowscript.org/]&lt;br /&gt;
&lt;br /&gt;
2. Log into a Google account.&lt;br /&gt;
&lt;br /&gt;
3. Click here in &amp;quot;You are signed in as [account name you select]  and your programs are here.&amp;quot;&lt;br /&gt;
&lt;br /&gt;
4. Click the blue Create New Program.&lt;br /&gt;
&lt;br /&gt;
===Computer Installation===&lt;br /&gt;
&lt;br /&gt;
To install VPython simply follow the instructions in the links given below. After the installation is completed just open the VIDLE for Python (usually there is a shortcut created on your desktop) and start typing your code.&lt;br /&gt;
&lt;br /&gt;
===Windows===&lt;br /&gt;
Install VPython [http://vpython.org/contents/download_windows.html here]&lt;br /&gt;
&lt;br /&gt;
===OSX===&lt;br /&gt;
&lt;br /&gt;
Install VPython [http://vpython.org/contents/download_mac.html here]&lt;br /&gt;
&lt;br /&gt;
===Linux===&lt;br /&gt;
&lt;br /&gt;
Install VPython [http://vpython.org/contents/download_linux.html here]&lt;br /&gt;
&lt;br /&gt;
==Getting started with Python==&lt;br /&gt;
Introduction to basic Python use&lt;br /&gt;
&lt;br /&gt;
The first two lines of your program should be:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
::from __future__ import division&lt;br /&gt;
::from visual import *&amp;lt;/code&amp;gt;&lt;br /&gt;
The first line enables float division, so 3 / 2 = 1.5 (not 1) and the second line enables graphics module to plot your 3D simulation. &lt;br /&gt;
&lt;br /&gt;
When you reach the point where graphing is needed, you will need this line of code below the ones above:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
::from visual.graph import *&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Variables===&lt;br /&gt;
A variable is the name given to a chosen value. Variables can be manipulated, changed, or renamed within vPython. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Assigning Variables&#039;&#039;&#039;&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;&lt;br /&gt;
x = 5 &amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This assigns the variable x the number 5. &lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note:&#039;&#039;&#039;&#039;&#039; The equal sign does not mean equal. Think of it more as an assignment.&lt;br /&gt;
&lt;br /&gt;
Python allows allows you to redefine variables&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;&lt;br /&gt;
y = 0&lt;br /&gt;
&lt;br /&gt;
x = y &amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In this case, we have taken the original x and assigned it the value from the variable y making the value of x equal to 0. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Increasing a Variable&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Let&#039;s say you want x to increase by one after a certain line of code, to keep variables to a minimum. Python allows you do to so. &lt;br /&gt;
 &amp;lt;nowiki&amp;gt;&lt;br /&gt;
x = 2&lt;br /&gt;
&lt;br /&gt;
x = x + 1 &lt;br /&gt;
&lt;br /&gt;
x += 1&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In this case, we have taken the original value of x and added one to it. If you call x again, its value will now be 3. The third method performs the exact same action as the second method. It just contains different syntax. This will be helpful in loops.&lt;br /&gt;
&lt;br /&gt;
===Creating VPython Objects===&lt;br /&gt;
In VPython you can create an object with certain attributes (e.g. radius, position). You can store the information about that object in a variable. This way you can access a certain object using a variable it is stored in.&lt;br /&gt;
&#039;&#039;&#039;Here are examples of some objects you can create and how to define them&#039;&#039;&#039;&lt;br /&gt;
*[http://vpython.org/contents/docs/sphere.html Sphere]&lt;br /&gt;
[[File:Sphere.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; variableName = ball( pos=vector(x_coordinate, y_coordinate, z_coordinate), radius = radius_measure, color = color.blue) &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
&#039;&#039;&lt;br /&gt;
&#039;&#039;&#039;Note:&#039;&#039;&#039;&#039;&#039; There are different colors you can assign some of which are red, blue, magenta, cyan, yellow, and more. &lt;br /&gt;
[[File:Arrow1.jpg]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;myArrow = arrow(pos=vector(x_coordinate,y_coordinate,z_coordinate), axis=vector(x1_coordinate,y1_coordinate,z1_coordinate), color = color.color_of_the_arrow)&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The axis refers to the more so thickness of the arrow. When coding, you can multiply this vector by a scalar value. &lt;br /&gt;
&lt;br /&gt;
*[http://vpython.org/contents/docs/vector.html Vector]&lt;br /&gt;
&amp;lt;code&amp;gt;myVector = vector(x_coordinate,y_coordinate,z_coordinate)&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Outside of objects, you can just create a vector numbers to be used later, such as making the force or velocity vector. &lt;br /&gt;
*[http://vpython.org/contents/docs/trail.html Trail]&lt;br /&gt;
[[File:Trail1.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
You can leave a path behind a moving object simply by specifying &amp;lt;code&amp;gt;make_trail=True&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;ball.make_trail = True&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Each time you change (object).pos, this new position is added to a curve, thereby leaving a trail behind the moving sphere. This works with arrow, box, cone, cylinder, ellipsoid, pyramid, ring, and sphere.&lt;br /&gt;
&lt;br /&gt;
===Manipulating VPython values===&lt;br /&gt;
*Accessing attributes of the variable&lt;br /&gt;
To access the attribute of a given variable just use the syntax &amp;lt;code&amp;gt;object.attribute&amp;lt;/code&amp;gt; (e.g. to access the position of the ball variable, you should do &amp;lt;code&amp;gt;ball.pos&amp;lt;/code&amp;gt;)&lt;br /&gt;
*Updating variable&lt;br /&gt;
To update a variable (such as time, speed, force or the position of the object) you should do &amp;lt;code&amp;gt;variable = variable + updateIncrement&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Running VPython code===&lt;br /&gt;
To run VPython code simply press F5. While running your code you will see the visual module and a shell (a place where all print out information is displayed) &lt;br /&gt;
===Loops===&lt;br /&gt;
There are two types of loops that can be used in Python: [https://wiki.python.org/moin/ForLoop for loop] and [https://wiki.python.org/moin/WhileLoop while loop]. Loops repeat the actions within them until a certain pre-determined point is reached. &lt;br /&gt;
&lt;br /&gt;
In this course, only while loops are used, so you will not need to worry about for loops.&lt;br /&gt;
&lt;br /&gt;
*While loops &lt;br /&gt;
The body of a while loop is executed, while a certain condition is true. &#039;&#039;&#039;All the statements within the while loop are indented.&#039;&#039;&#039; While loop is equivalent to integration, because it manually breaks down the physical process into small parts and adds them up (see [[Iterative_Prediction | Iterative Prediction]] as a good example of the physical application of a while loop). While loop has the following structure:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
:while (condition):&lt;br /&gt;
::the body of the while loop&lt;br /&gt;
::updating the loop&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Make sure that the while loop is followed by a colon: (:), or else your program will issue an error.&lt;br /&gt;
&lt;br /&gt;
For example:&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;&lt;br /&gt;
while t &amp;lt; 60:&lt;br /&gt;
  distance = distance + velocity * deltat&lt;br /&gt;
  t = t + deltat&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note:&#039;&#039;&#039;To animate, put &#039;&#039;&#039;rate(integerNumber)&#039;&#039;&#039;. The higher the rate, the faster the animation. A good number to pick is &#039;&#039;&#039;rate(200)&#039;&#039;&#039;.&lt;br /&gt;
&#039;&#039;&#039;Note:&#039;&#039;&#039; &#039;&#039;All variables called within the while loop should be created first outside the original loop as it makes it a little easier to troubleshoot at times.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
===Comments===&lt;br /&gt;
Comments in the code have no impact on the code execution, because they are just ignored by the computer. Comments in VPython start with a pound sign (#) and end when a line ends. It is a good practice to place some useful information (like an explanation to a certain step) in the comments, so other people will find it easier to understand your code. For example:&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;&lt;br /&gt;
x = x + 1 # incrementing x variable&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Useful built-in functions===&lt;br /&gt;
====Printing out information====&lt;br /&gt;
*&amp;lt;code&amp;gt;print(value, variable)&amp;lt;/code&amp;gt;&lt;br /&gt;
Prints out the given value in the programming shell. An example is as follows&lt;br /&gt;
&amp;lt;nowiki&amp;gt;print(&amp;quot;x =&amp;quot;, x)&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The program will print x = and then the value of x from the code you have in the form of: (assuming x equals 5)&lt;br /&gt;
x = 5&lt;br /&gt;
Or&lt;br /&gt;
&amp;lt;nowiki&amp;gt;print(&amp;quot;200&amp;quot;)&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will just print the number 200.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;The print function is useful in checking your math while coding!!&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
====Math====&lt;br /&gt;
Raises x to the y-th power.&lt;br /&gt;
*&amp;lt;code&amp;gt;x ** y&amp;lt;/code&amp;gt;&lt;br /&gt;
Computes normal addition&lt;br /&gt;
*&amp;lt;code&amp;gt;x + y&amp;lt;/code&amp;gt;&lt;br /&gt;
Computes normal subtraction&lt;br /&gt;
*&amp;lt;code&amp;gt;x - y&amp;lt;/code&amp;gt;&lt;br /&gt;
Computes multiplications&lt;br /&gt;
*&amp;lt;code&amp;gt;x * y&amp;lt;/code&amp;gt;&lt;br /&gt;
Computes divisions&lt;br /&gt;
*&amp;lt;code&amp;gt;x / y&amp;lt;/code&amp;gt;&lt;br /&gt;
Computes the remainder between two values&lt;br /&gt;
*&amp;lt;code&amp;gt;x % y&amp;lt;/code&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note: You cannot multiply two vectors!! You can, however, multiply a vector by a scalar. &lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
===Vectors===&lt;br /&gt;
Calculates the cross product of two vectors&lt;br /&gt;
*&amp;lt;code&amp;gt;cross(vectorA, vectorB)&amp;lt;/code&amp;gt;&lt;br /&gt;
Calculates the magnitude of the vector&lt;br /&gt;
*&amp;lt;code&amp;gt;mag(vector)&amp;lt;/code&amp;gt;&lt;br /&gt;
Calculates the unit vector of the vector&lt;br /&gt;
*&amp;lt;code&amp;gt;norm(vector)&amp;lt;/code&amp;gt;&lt;br /&gt;
Calculates the dot product of two vectors&lt;br /&gt;
*&amp;lt;code&amp;gt;dot(vector_1, vector_2)&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==The structure of VPython program==&lt;br /&gt;
VPython reads linearly meaning that it reads down the lines as you type. Therefore, the following give you a good idea of how to begin your coding in terms for this class and physics in general. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;1. Copy the&#039;&#039;&#039; from__future import division     /    from visual import*&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;2. Create and declare all variables.&#039;&#039;&#039; This includes any constants and any initial conditions. It&#039;s important to create your initial conditions before any loops. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;3. Create objects.&#039;&#039;&#039; In VPython, you are creating 3D objects that will most likely move. Characteristics of the objects are most likely going to be updated; therefore, they need to be initialized. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;4. Initialize a while loop.&#039;&#039;&#039; Once you have all your variables, write the condition of your while loop (condition being what you are working towards). &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;5. Begin updating the necessary variables and characteristics of objects.&#039;&#039;&#039; This will include things such as velocity, force, momentum, object positions, and etc. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;6. Print any necessary pieces of data after the while loop or during, if needed.&lt;br /&gt;
&lt;br /&gt;
This program uses a simple algorithm that produces an approximate motion of Earth around the Sun. &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;
r=5.0&lt;br /&gt;
theta=0.0&lt;br /&gt;
dtheta=0.01&lt;br /&gt;
sun=sphere(color=color.yellow)&lt;br /&gt;
earth=sphere(pos=(r,0,0),color=color.blue)&lt;br /&gt;
t = 0&lt;br /&gt;
while t &amp;lt; 60:&lt;br /&gt;
    rate(20)&lt;br /&gt;
    theta=theta+dtheta&lt;br /&gt;
    x=r*cos(theta)&lt;br /&gt;
    y=r*sin(theta)&lt;br /&gt;
    earth.pos=(x,y,0)&lt;br /&gt;
    t = t + 0.1&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
[[File:Earth_Sun.jpg]]&lt;br /&gt;
&lt;br /&gt;
https://trinket.io/embed/glowscript/c8bd5fcfea&lt;br /&gt;
&lt;br /&gt;
Here is a longer, animated example if you follow the link above. It&#039;s a Glowscript trinket of a 3D spring. &lt;br /&gt;
&lt;br /&gt;
===Debugging techniques===&lt;br /&gt;
Unfortunately, sometimes programs do not work in a way we intended them to work. Here are some tips to fixing your code. &lt;br /&gt;
#If you get an error try to see what the error is. The most common errors are with syntax and include forgetting a parentheses, using the wrong punctuation in coding lines, &lt;br /&gt;
#Make sure you are updating the variable on which your while loop is based upon. This could cause an infinite while loop if you never approach a terminating condition. &lt;br /&gt;
#Double check math. Check for imaginary number or dividing by zero. &lt;br /&gt;
#Make sure you have correct indentation everywhere. Remember that the code in the while loop needs to be indented. Python is space-dependent. If an indentation is off, then your whole code will be off.&lt;br /&gt;
#Put plenty of &amp;lt;code&amp;gt;print()&amp;lt;/code&amp;gt; statements, so you can know what is going on throughout the code. Usually, put these after you are changing the values of variables. &lt;br /&gt;
#Check your mathematical expressions for the order of precedence (e.g. &amp;lt;code&amp;gt;x / (y * z)&amp;lt;/code&amp;gt; is &#039;&#039;&#039;not&#039;&#039;&#039; equivalent to &amp;lt;code&amp;gt;x / y * z&amp;lt;/code&amp;gt;). Try to fix by adding parenthesis on what needs to be done first. &lt;br /&gt;
#It&#039;s always a good idea to perhaps do coding in parts and check through the parts as you write the code to ensure not too many errors when approaching the end of coding. &lt;br /&gt;
# Always feel free to ask your TA for help! &lt;br /&gt;
For further information on debugging see [[VPython_Common_Errors_and_Troubleshooting | VPython Common Errors and Troubleshooting]].&lt;br /&gt;
&lt;br /&gt;
==Studying for Exams==&lt;br /&gt;
Most exam questions will be based on coding similar to labs or coding having to deal with concepts that you&#039;ve already covered in physics. One good way to prepare is to solve the problems with a set number of variables, then looking back and writing down the variables that change. Finally, create the objects and write the needed characteristics of these objects. &lt;br /&gt;
The exam questions will not be perfectly similar to a lab or any previous question; however, if you practice coding outside of the lab, create other simulations, and understand how the basic syntax of VPython, things should turn out well. &lt;br /&gt;
&lt;br /&gt;
==Connectedness==&lt;br /&gt;
&lt;br /&gt;
How is this topic connected to something that you are interested in?&lt;br /&gt;
&lt;br /&gt;
I enjoy coding and believe coding to be helpful in trying to visualize physics and the mathematics behind it, especially through vPython. &lt;br /&gt;
&lt;br /&gt;
How is it connected to your major?&lt;br /&gt;
&lt;br /&gt;
I&#039;m a Computer Science major and am currently learning Python in another class. It&#039;s very rewarding to see your code be applied in a way that allows you or others to visualize data.&lt;br /&gt;
 &lt;br /&gt;
Is there an interesting industrial application?&lt;br /&gt;
&lt;br /&gt;
VPython could be used to simulate different scenarios that can occur virtually.&lt;br /&gt;
&lt;br /&gt;
==History of Python==&lt;br /&gt;
&lt;br /&gt;
VPython was created by a man named Guido van Rossum. He graduated in 1982 with a master&#039;s degree in mathematics and computer science from the University of Amsterdam. &lt;br /&gt;
Originally, the program was released in 1989The first open source version was released in 1991 and van Rossum had the following goals in mind: 1. It should be easy and intuitive, 2. It should be open sourced, which means anyone can contribute to its development on the language, 3. It should be easily understood like a language and suitable to be used for multiple purposes. &lt;br /&gt;
He has been recognized by ACM in 2006 as a Distinguished Engineer. Sources:  [4] [http://www.computerhistory.org/fellowawards/hall/guido-van-rossum/]&lt;br /&gt;
&lt;br /&gt;
== See also ==&lt;br /&gt;
===General Overview of VPython===&lt;br /&gt;
[[VPython]]&lt;br /&gt;
&lt;br /&gt;
===External links===&lt;br /&gt;
[http://vpython.org/ The official VPython website with the links to YouTube tutorials]&lt;br /&gt;
&lt;br /&gt;
[http://vpython.org/contents/doc.html Documentation]&lt;br /&gt;
&lt;br /&gt;
[https://groups.google.com/forum/?fromgroups&amp;amp;hl=en#!forum/vpython-users VPython User forum]&lt;br /&gt;
&lt;br /&gt;
[https://www.computer.org/csdl/mags/co/2015/03/mco2015030008.pdf]&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;
1. [http://openbookproject.net/thinkcs/python/english3e/index.html Python tutorial]&lt;br /&gt;
&lt;br /&gt;
2. [http://vpython.wikidot.com/ VPython Wiki Site]&lt;br /&gt;
&lt;br /&gt;
3. [http://www.glowscript.org/ GlowScript]&lt;br /&gt;
&lt;br /&gt;
4. Information on van Rossum [http://www.computerhistory.org/fellowawards/hall/guido-van-rossum/] &lt;br /&gt;
&lt;br /&gt;
5. More information of python development [https://www.computer.org/csdl/mags/co/2015/03/mco2015030008.pdf]&lt;br /&gt;
&lt;br /&gt;
[[Category:VPython]]&lt;/div&gt;</summary>
		<author><name>Mmorris83</name></author>
	</entry>
	<entry>
		<id>http://www.physicsbook.gatech.edu/index.php?title=VPython&amp;diff=38023</id>
		<title>VPython</title>
		<link rel="alternate" type="text/html" href="http://www.physicsbook.gatech.edu/index.php?title=VPython&amp;diff=38023"/>
		<updated>2019-10-22T06:50:59Z</updated>

		<summary type="html">&lt;p&gt;Mmorris83: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&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;
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;
===Glowscript===&lt;br /&gt;
&lt;br /&gt;
Another useful method of using Vpython can be found at http://www.glowscript.org/. At this website, a user can make an account and have a script up and running within minutes on a web browser without having to deal with downloading any software or worrying about compatibility. Only downside is that it can be tricky to save the code for submitting to Webassign.&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;Helix&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;spring = helix(pos=(0,0,0), axis=(10,0,0), radius=0.75, color=color.cyan)&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Creates a helix of color cyan at the origin and goes to &amp;lt;10,0,0&amp;gt; with a radius of 0.75.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Pyramid&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;shape = pyramid(pos=(8,4,0), size=(20,4,10), color=color.red)&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Creates a pyramid of size &amp;lt;20,4,10&amp;gt; starting at &amp;lt;8,4,0&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Object Positioning&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
It is very important to note that the position values for arrow, cylinder, helix, and pyramid corresponds to one end of the object, however for a box, sphere, or ring it corresponds to the center of the object.&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;
&#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;
&#039;&#039;&#039;Square Root&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;sqrt(value)&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Absolute Value&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;abs(value)&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==VPython Operators==&lt;br /&gt;
&lt;br /&gt;
===Mathematical Operators===&lt;br /&gt;
1) #  comment out a line&lt;br /&gt;
&lt;br /&gt;
2) + - * /   addition, subtraction, multiplication, division&lt;br /&gt;
&lt;br /&gt;
3) ** exponential&lt;br /&gt;
&lt;br /&gt;
4) % modulus or remainder&lt;br /&gt;
&lt;br /&gt;
===Logical Operators===&lt;br /&gt;
1) ==  outputs true if the compared values are the same&lt;br /&gt;
&lt;br /&gt;
2) != outputs true if the compared values are not the same&lt;br /&gt;
&lt;br /&gt;
3) &amp;gt; or &amp;lt; outputs true if the compared values are greater or less than the other&lt;br /&gt;
&lt;br /&gt;
4) &amp;gt;= or &amp;lt;= Same as above but outputs true if greater or less than or equal to the compared value&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>Mmorris83</name></author>
	</entry>
	<entry>
		<id>http://www.physicsbook.gatech.edu/index.php?title=GlowScript&amp;diff=38022</id>
		<title>GlowScript</title>
		<link rel="alternate" type="text/html" href="http://www.physicsbook.gatech.edu/index.php?title=GlowScript&amp;diff=38022"/>
		<updated>2019-10-22T06:49:12Z</updated>

		<summary type="html">&lt;p&gt;Mmorris83: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&#039;&#039;&#039;Claimed by Miriam Morris for Fall 2019&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
GlowScript IDE is an environment where people can create 3D animations and share them on web.&amp;lt;br&amp;gt;&lt;br /&gt;
Scripts can be written in VPython.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Commands ==&lt;br /&gt;
&lt;br /&gt;
=== Header ===&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;b&amp;gt;GlowScript 2.7 VPython&amp;lt;/b&amp;gt; is required in header to run Vpython.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;GlowScript 2.7 JavaScript&amp;lt;/b&amp;gt; is required in header to run javascript.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Initialize new Variables ===&lt;br /&gt;
----&lt;br /&gt;
Use &amp;lt;b&amp;gt;var&amp;lt;/b&amp;gt; and assign values.&amp;lt;br&amp;gt;&lt;br /&gt;
 var x, y&lt;br /&gt;
 x = 2&lt;br /&gt;
 y = 3&lt;br /&gt;
&lt;br /&gt;
There is no need to put semi-colon in the end of a line.&lt;br /&gt;
&lt;br /&gt;
=== 3D Objects ===&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;b&amp;gt;Arrow&amp;lt;/b&amp;gt;&lt;br /&gt;
 newArrow = arrow(pos=vec(x0, y0, z0), shaftwidth=1, axis_and_length=vec(x1, y1, z1))&lt;br /&gt;
This creates arrow that starts at point &amp;lt;x0, y0, z0&amp;gt; that points &amp;lt;x1, y1, z1&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Box&amp;lt;/b&amp;gt;&lt;br /&gt;
 newBox = box(pos=vec(x0, y0, z0), size=vec(L, H, W))&lt;br /&gt;
This creates a box with a center &amp;lt;x0, y0, z0&amp;gt; and with size &amp;lt;L, H, W&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Sphere&amp;lt;/b&amp;gt;&lt;br /&gt;
 newSphere = sphere(pos=vec(x0, y0, z0), size=vec(x1, y1, z1) )&lt;br /&gt;
This creates a box with a center &amp;lt;x0, y0, z0&amp;gt; and with size &amp;lt;x1, y1, z1&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can learn more by clicking this. [https://www.glowscript.org/docs/GlowScriptDocs/index.html]&lt;br /&gt;
&lt;br /&gt;
=== Customizing Objects ===&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;b&amp;gt;Color&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
There are 10 default colors that can be used.&lt;br /&gt;
 color.red, color.yellow, color.green, color.orange&lt;br /&gt;
 color.blue, color.cyan, color.magenta, color.purple&lt;br /&gt;
 color.black, color.white&lt;br /&gt;
Colors can be customized by user by using following code.&lt;br /&gt;
 vec(1, 0.5, 0.3)&lt;br /&gt;
In this case, R is 1, G = 0.7, and B = 0.2, which has color of pastel orange.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Animation Speed&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
 rate(50)&lt;br /&gt;
This line will halt each computations to have interval of 1.0/50.0 second.&lt;br /&gt;
&lt;br /&gt;
== Supported Environments ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Browsers&amp;lt;/b&amp;gt;: Chrome, Firefox, Safari, Internet Explorer, and Edge.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;Devices&amp;lt;/b&amp;gt;: Most smart devices running Android or iOS.&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Mmorris83</name></author>
	</entry>
	<entry>
		<id>http://www.physicsbook.gatech.edu/index.php?title=Python_Syntax&amp;diff=38021</id>
		<title>Python Syntax</title>
		<link rel="alternate" type="text/html" href="http://www.physicsbook.gatech.edu/index.php?title=Python_Syntax&amp;diff=38021"/>
		<updated>2019-10-22T06:47:07Z</updated>

		<summary type="html">&lt;p&gt;Mmorris83: /* Math Operations */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&#039;&#039;&#039;Claimed by Miriam Morris for Fall 2019&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==The Main Idea==&lt;br /&gt;
VPython is an extension of the Python programming language that contains a 3D graphics module called Visual, which allows users to create simple simulations of physics problems. Its primary use is for educational purposes, although it has been used in research before in the past. Although it is slightly different from the actual Python program, it is similar enough for the purpose of this class. Most of the labs done this year will be done using the vPython program.&lt;br /&gt;
&lt;br /&gt;
==Downloading vPython==&lt;br /&gt;
In all cases you will need to have Python 2.7.9 installed. Future versions may also work, but be warned that it may cause VPython to behave erratically.&lt;br /&gt;
&lt;br /&gt;
[http://vpython.org/contents/download_windows.html For Windows]&lt;br /&gt;
&lt;br /&gt;
[http://vpython.org/contents/download_mac.html For Mac]&lt;br /&gt;
&lt;br /&gt;
[http://vpython.org/contents/download_linux.html For Linux]&lt;br /&gt;
&lt;br /&gt;
Note for Linux: You can only install Classic VPython, which is no longer supported and may be missing some features and bug fixes that are present in the current version of VPython.&lt;br /&gt;
&lt;br /&gt;
Alternatively, you can use GlowScript, a virtual environment that allows you to execute VPython code in your browser. You can create an account at [http://www.glowscript.org/ http://www.glowscript.org/]. Although this is useful, keep in mind that not all labs can be completed through GlowScript.&lt;br /&gt;
&lt;br /&gt;
=Python Basics=&lt;br /&gt;
&lt;br /&gt;
==Variables==&lt;br /&gt;
&lt;br /&gt;
A variable is an item within your code that has information stored in it. This information can be a number, a string of letters, or anything really. &amp;lt;br&amp;gt;&lt;br /&gt;
Variables are identified by a name. The names of your variables should be simple, but logical. Avoid names that include spaces or dots, because Python does not like this syntax. Rather, it is best to separate two words in a variable name by capitalizing the second word, such as “myVariable”, or an underscore, such as “my_variable”. &amp;lt;br&amp;gt;&lt;br /&gt;
Storing items as a variable allows for easy access when they are needed later in your program. &amp;lt;br&amp;gt;&lt;br /&gt;
One last thing that is important to note is that you can reassign variables. For example, the code below is completely valid.&amp;lt;br&amp;gt;&lt;br /&gt;
 x = 5&lt;br /&gt;
 x = x + 2&lt;br /&gt;
When this code is finished running, x will equal 7. Although this is counterintuitive at first, it’s easy to get used to.&lt;br /&gt;
&lt;br /&gt;
==Comments==&lt;br /&gt;
&lt;br /&gt;
Comments are useful when you want to include a note or a quick explanation in your code that will make it easier to understand later. Comments are sections of code that the computer will skip in execution, so it will not actually be executed when your program runs. There are two types of comments that Python uses, single line comments and multi-line comments.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Single Line Comments&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
To create a single line comment (the most common comments in Python) type a hash character (#) at the beginning of anything you would like to comment out. Note, when &amp;quot;#&amp;quot; is in a line of code, the rest of the code following the # will be ignored by the computer when your code runs.&lt;br /&gt;
&lt;br /&gt;
 # This is a comment.&lt;br /&gt;
 &lt;br /&gt;
 a = 4 # and so is this&lt;br /&gt;
 &lt;br /&gt;
 # b = 4 # and so is this entire line, be careful!&lt;br /&gt;
&lt;br /&gt;
Here is an example of comment use that you might see in a lab:&lt;br /&gt;
&lt;br /&gt;
 myTemp = 4 #This is the temperature in Celsius.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Multi-line Comments&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
To create a multi-line comment (usually reserved for longer explanations or instructions that cannot fit on one line) type three opening and closing quotation marks, like so:&lt;br /&gt;
&lt;br /&gt;
 &amp;quot;&amp;quot;&amp;quot; this &lt;br /&gt;
     is&lt;br /&gt;
     a&lt;br /&gt;
     multi-line&lt;br /&gt;
     comment &lt;br /&gt;
     example &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
 &amp;quot;&amp;quot;&amp;quot; this is also an example, but on only one line&amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Be careful! Unlike the single line comments, multi-line comments require a start and a stop (if you forget to close your comment or forget the third quotation mark then that will cause an error in your code).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Main Uses&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
- Longer variable explanation (units, where the data comes from, etc)&lt;br /&gt;
&lt;br /&gt;
- Comment out code (to save for later, instead of deleting it)&lt;br /&gt;
&lt;br /&gt;
- Instructions&lt;br /&gt;
&lt;br /&gt;
- Notes to self&lt;br /&gt;
&lt;br /&gt;
==Math Operations==&lt;br /&gt;
&lt;br /&gt;
Math operations are simple in Python. The simple operations, as you might expect, are as follows:&lt;br /&gt;
 #Addition: &lt;br /&gt;
 1+2 #This will equal 3.&lt;br /&gt;
 &lt;br /&gt;
 #Subtraction: &lt;br /&gt;
 2-1 #This will equal 1.&lt;br /&gt;
 &lt;br /&gt;
 #Multiplication: &lt;br /&gt;
 2*1 #This will equal 2.&lt;br /&gt;
 &lt;br /&gt;
 #Division: &lt;br /&gt;
 2/1 #This will equal 2.&lt;br /&gt;
&lt;br /&gt;
There are other operations, that you may want to pay closer attention to.&lt;br /&gt;
 &lt;br /&gt;
 #Exponentiation: &lt;br /&gt;
 2**2 #This will equal 4.&lt;br /&gt;
 &lt;br /&gt;
 #Square root: &lt;br /&gt;
 sqrt(4) #This will equal 2.&lt;br /&gt;
 &lt;br /&gt;
 #Remainder: &lt;br /&gt;
 5%4 #This will equal 1.&lt;br /&gt;
&lt;br /&gt;
==Print Function==&lt;br /&gt;
&lt;br /&gt;
In order to see any of the information we’ve listed above, you have to actually print it. For example, the code below will run but will not provide you with an output.&lt;br /&gt;
 x = 1 + 1&lt;br /&gt;
Instead, you have to print this information in order to see the answer when the code is finished running. You can do this in two ways. First, you can directly imbed the code in your print statement.&lt;br /&gt;
 print(1 + 1)&lt;br /&gt;
Or, you can create the variable and then print the variable.&lt;br /&gt;
 x = 1 + 1&lt;br /&gt;
 print(x)&lt;br /&gt;
Either one is valid!&lt;br /&gt;
If you would like to print something other than a variable, include quotations around it. For example, if you wanted to print the typical “Hello, world!”, you would code:&lt;br /&gt;
 print(“Hello, world!”)&lt;br /&gt;
The quotations are the important takeaway here.&lt;br /&gt;
&lt;br /&gt;
==Conditional==&lt;br /&gt;
A conditional involves an “if” statement. “If this thing is true, do this”, for example. Conditionals are useful in physics if you want to perform different things on a variable, depending on certain conditions.&lt;br /&gt;
 if x &amp;gt; 1:&lt;br /&gt;
 	print(“x is greater than 1”)&lt;br /&gt;
 elif x = 1:&lt;br /&gt;
 	print(“x is equal to 1”)&lt;br /&gt;
 else:&lt;br /&gt;
 	print(“x is less than 1”)&lt;br /&gt;
Above is the typical syntax you would see for a conditional. Notice the conditional starts with an if statement, followed by a colon. The next line is indented, and then tells that if statement what to do if the if statement is true. If it is not true, it moves on to the elif statement. Elif statements are used after if statements, but when there is still an if statement involved. There can be endless elif statements. Notice this uses the same syntax as the regular if statement. Lastly, if neither the if nor the elif statement(s) are true, there is an else statement. This will print if nothing above was true.&lt;br /&gt;
&lt;br /&gt;
==Loop==&lt;br /&gt;
A loop iterates through each item in a list or range. Loops can be useful in physics because they are vital to update equations. Loops will automatically update the information for you, rather than having to write out the long iterative process yourself. Below are examples of for loops and while loops.&lt;br /&gt;
 for i in range(1,11):&lt;br /&gt;
 	print(i)&lt;br /&gt;
The statement above will print:&lt;br /&gt;
 1&lt;br /&gt;
 2&lt;br /&gt;
 3&lt;br /&gt;
 4&lt;br /&gt;
 5&lt;br /&gt;
 6&lt;br /&gt;
 7&lt;br /&gt;
 8&lt;br /&gt;
 9&lt;br /&gt;
 10&lt;br /&gt;
Notice it does not print 11. When inputting a range in Python, the last number is not included. Notice how the for loop states “for”, and then a variable, and then a range, and then a colon. This is then followed by a statement that tells what to do for each iteration in the loop. Notice it is indented!&lt;br /&gt;
 while i &amp;gt; 1:&lt;br /&gt;
 	print(i)&lt;br /&gt;
This is an example of a while loop. While i is greater than 1, the code will print i. The syntax is similar to the for loop.&lt;br /&gt;
&lt;br /&gt;
==Equal Signs==&lt;br /&gt;
&lt;br /&gt;
“=” and “==” mean two different things in Python. When setting a variable equal to something, you use one equal sign:&lt;br /&gt;
 x = 2&lt;br /&gt;
However, when you are using it in something like an if statement, use two equal signs:&lt;br /&gt;
 if x == 2:&lt;br /&gt;
 	print(“x equals 2)&lt;br /&gt;
&lt;br /&gt;
=VPython Basics=&lt;br /&gt;
&lt;br /&gt;
In this section we will analyze some of the objects utilized by VPython. Each object is more or less self-explanatory with equally clear fields within.&lt;br /&gt;
&lt;br /&gt;
==Starting Your VPython Program==&lt;br /&gt;
To begin with, note that every VPython program must begin with these two lines of code:&lt;br /&gt;
 from__future__ import division&lt;br /&gt;
 from visual import*&lt;br /&gt;
    &lt;br /&gt;
The scene, or visual where you see your code occur, has a width and a height. You can alter them, as seen below.&lt;br /&gt;
 scene.width = 1024&lt;br /&gt;
 scene.height = 760&lt;br /&gt;
&lt;br /&gt;
==Vectors==&lt;br /&gt;
You can access each component of the vector with pos.x, pos.y, or pos.z, depending on which component you want. You access an object&#039;s field with a period following the variable name.&lt;br /&gt;
 pos = vector(1, 2, 3)&lt;br /&gt;
 xComponent = pos.x  #This value would be 1&lt;br /&gt;
 yComponent = pos.y  #This value would be 2&lt;br /&gt;
 zComponent = pos.z. #This value would be 3&lt;br /&gt;
&lt;br /&gt;
You can add two or more vectors together and you can multiply a vector by a scalar. Keep in mind you cannot add a vector and a scalar.&lt;br /&gt;
 #Adding&lt;br /&gt;
 A = vector(1, 2, 3)&lt;br /&gt;
 B = vector(4, 5, 6)&lt;br /&gt;
 C = A + B  # The value of C is now (5, 7, 9)&lt;br /&gt;
 # Multiplying&lt;br /&gt;
 D = 5 * C. # The value of D is now (25, 35, 45)&lt;br /&gt;
&lt;br /&gt;
To get the magnitude of or to normalize a vector, use the appropriate function.&lt;br /&gt;
 initialPos = vector(10, 3, 0)&lt;br /&gt;
 finalPos = vector(30, 15, 0)&lt;br /&gt;
 deltaR = finalPos - initialPos # -&amp;gt; vector(20, 12, 0)&lt;br /&gt;
 rMag = mag(finalPos)&lt;br /&gt;
 rHat = norm(finalPos)&lt;br /&gt;
 errorDemo = magR + finalPos # -&amp;gt; error; causes your program to crash&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Shapes==&lt;br /&gt;
&lt;br /&gt;
There are a number of different shapes you can create for visual reference in the vPython program. These will be used quite frequently in lab to observe things like momentum, force, etc. If you were to make, say, a ball, you would want to draw a sphere. It has a position field, a radius field, and a color field. When creating a new instance of an object, each field is comma separated. You access each field the same way as we did with the position vector.&lt;br /&gt;
 ball = sphere(pos = vector(10, 10, 10), radius = 9e2, color = color.red)&lt;br /&gt;
 ballColor = ball.color&lt;br /&gt;
 ballPos = ball.pos&lt;br /&gt;
 ballRadius = ball.radius&lt;br /&gt;
&lt;br /&gt;
You can draw arrows. These also have a color and position field, but instead of a radius, they have an axis that determines their length. These arrows can be used to represent the magnitude of the force or the momentum or anything else the lab asks you to make. &lt;br /&gt;
 velocityArrow = arrow(color = color.blue, pos = vector(-10, -10, -10), axis = velocity * vScale)&lt;br /&gt;
&lt;br /&gt;
There are also boxes. They have a position vector and a size vector.&lt;br /&gt;
 myBox = box(pos = vector(50, 50, 50), size = vector(20, 15, 12))&lt;br /&gt;
&lt;br /&gt;
You can draw helixes, which are useful for depicting springs. They have a position field, a color field, a thickness field, a radius field, and a field for the number of coils.&lt;br /&gt;
 spring = helix(pos=ceiling.pos, color=color.cyan, thickness=.003, coils=40, radius=0.015)&lt;br /&gt;
&lt;br /&gt;
==Tracing==&lt;br /&gt;
&lt;br /&gt;
If you want to trace a moving object, you can have a curve follow it by adding to it every time step. This will show the entire path the object has traveled during the simulation.&lt;br /&gt;
 posTrace = curve(color = color.yellow)&lt;br /&gt;
 trail.append(ball.pos)&lt;br /&gt;
&lt;br /&gt;
==Graphs==&lt;br /&gt;
&lt;br /&gt;
You also have the option of making graphs as your program progresses; this is particularly useful for potential vs kinetic energy.&lt;br /&gt;
 Kgraph = gcurve(color = color.cyan)&lt;br /&gt;
 Ugraph = gcurve(color = color.yellow)&lt;br /&gt;
 KplusUgraph = gcurve(color = color.red)&lt;br /&gt;
 # For each time step...&lt;br /&gt;
 Kgraph.plot(pos = (t, Kenergy))&lt;br /&gt;
 Ugraph.plot(pos = (t, Uenergy))&lt;br /&gt;
 KplusUgraph.plot(pos = (t, Kenergy + Uenergy))&lt;br /&gt;
&lt;br /&gt;
By updating the fields of whatever objects you decide to use and by using any intermediate variables necessary, you&#039;re able to draw and compute what you&#039;ll need for this course.&lt;/div&gt;</summary>
		<author><name>Mmorris83</name></author>
	</entry>
	<entry>
		<id>http://www.physicsbook.gatech.edu/index.php?title=Python_Syntax&amp;diff=38020</id>
		<title>Python Syntax</title>
		<link rel="alternate" type="text/html" href="http://www.physicsbook.gatech.edu/index.php?title=Python_Syntax&amp;diff=38020"/>
		<updated>2019-10-22T06:46:52Z</updated>

		<summary type="html">&lt;p&gt;Mmorris83: /* Math Operations */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&#039;&#039;&#039;Claimed by Miriam Morris for Fall 2019&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==The Main Idea==&lt;br /&gt;
VPython is an extension of the Python programming language that contains a 3D graphics module called Visual, which allows users to create simple simulations of physics problems. Its primary use is for educational purposes, although it has been used in research before in the past. Although it is slightly different from the actual Python program, it is similar enough for the purpose of this class. Most of the labs done this year will be done using the vPython program.&lt;br /&gt;
&lt;br /&gt;
==Downloading vPython==&lt;br /&gt;
In all cases you will need to have Python 2.7.9 installed. Future versions may also work, but be warned that it may cause VPython to behave erratically.&lt;br /&gt;
&lt;br /&gt;
[http://vpython.org/contents/download_windows.html For Windows]&lt;br /&gt;
&lt;br /&gt;
[http://vpython.org/contents/download_mac.html For Mac]&lt;br /&gt;
&lt;br /&gt;
[http://vpython.org/contents/download_linux.html For Linux]&lt;br /&gt;
&lt;br /&gt;
Note for Linux: You can only install Classic VPython, which is no longer supported and may be missing some features and bug fixes that are present in the current version of VPython.&lt;br /&gt;
&lt;br /&gt;
Alternatively, you can use GlowScript, a virtual environment that allows you to execute VPython code in your browser. You can create an account at [http://www.glowscript.org/ http://www.glowscript.org/]. Although this is useful, keep in mind that not all labs can be completed through GlowScript.&lt;br /&gt;
&lt;br /&gt;
=Python Basics=&lt;br /&gt;
&lt;br /&gt;
==Variables==&lt;br /&gt;
&lt;br /&gt;
A variable is an item within your code that has information stored in it. This information can be a number, a string of letters, or anything really. &amp;lt;br&amp;gt;&lt;br /&gt;
Variables are identified by a name. The names of your variables should be simple, but logical. Avoid names that include spaces or dots, because Python does not like this syntax. Rather, it is best to separate two words in a variable name by capitalizing the second word, such as “myVariable”, or an underscore, such as “my_variable”. &amp;lt;br&amp;gt;&lt;br /&gt;
Storing items as a variable allows for easy access when they are needed later in your program. &amp;lt;br&amp;gt;&lt;br /&gt;
One last thing that is important to note is that you can reassign variables. For example, the code below is completely valid.&amp;lt;br&amp;gt;&lt;br /&gt;
 x = 5&lt;br /&gt;
 x = x + 2&lt;br /&gt;
When this code is finished running, x will equal 7. Although this is counterintuitive at first, it’s easy to get used to.&lt;br /&gt;
&lt;br /&gt;
==Comments==&lt;br /&gt;
&lt;br /&gt;
Comments are useful when you want to include a note or a quick explanation in your code that will make it easier to understand later. Comments are sections of code that the computer will skip in execution, so it will not actually be executed when your program runs. There are two types of comments that Python uses, single line comments and multi-line comments.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Single Line Comments&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
To create a single line comment (the most common comments in Python) type a hash character (#) at the beginning of anything you would like to comment out. Note, when &amp;quot;#&amp;quot; is in a line of code, the rest of the code following the # will be ignored by the computer when your code runs.&lt;br /&gt;
&lt;br /&gt;
 # This is a comment.&lt;br /&gt;
 &lt;br /&gt;
 a = 4 # and so is this&lt;br /&gt;
 &lt;br /&gt;
 # b = 4 # and so is this entire line, be careful!&lt;br /&gt;
&lt;br /&gt;
Here is an example of comment use that you might see in a lab:&lt;br /&gt;
&lt;br /&gt;
 myTemp = 4 #This is the temperature in Celsius.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Multi-line Comments&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
To create a multi-line comment (usually reserved for longer explanations or instructions that cannot fit on one line) type three opening and closing quotation marks, like so:&lt;br /&gt;
&lt;br /&gt;
 &amp;quot;&amp;quot;&amp;quot; this &lt;br /&gt;
     is&lt;br /&gt;
     a&lt;br /&gt;
     multi-line&lt;br /&gt;
     comment &lt;br /&gt;
     example &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
 &amp;quot;&amp;quot;&amp;quot; this is also an example, but on only one line&amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Be careful! Unlike the single line comments, multi-line comments require a start and a stop (if you forget to close your comment or forget the third quotation mark then that will cause an error in your code).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Main Uses&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
- Longer variable explanation (units, where the data comes from, etc)&lt;br /&gt;
&lt;br /&gt;
- Comment out code (to save for later, instead of deleting it)&lt;br /&gt;
&lt;br /&gt;
- Instructions&lt;br /&gt;
&lt;br /&gt;
- Notes to self&lt;br /&gt;
&lt;br /&gt;
==Math Operations==&lt;br /&gt;
&lt;br /&gt;
Math operations are simple in Python. The simple operations, as you might expect, are as follows:&lt;br /&gt;
 #Addition: &lt;br /&gt;
 1+2 #This will equal 3.&lt;br /&gt;
 &lt;br /&gt;
 #Subtraction: &lt;br /&gt;
 2-1 #This will equal 1.&lt;br /&gt;
 &lt;br /&gt;
 #Multiplication: &lt;br /&gt;
 2*1 #This will equal 2.&lt;br /&gt;
 &lt;br /&gt;
 #Division: &lt;br /&gt;
 2/1 #This will equal 2.&lt;br /&gt;
 &lt;br /&gt;
There are other operations, that you may want to pay closer attention to.&lt;br /&gt;
 &lt;br /&gt;
 #Exponentiation: &lt;br /&gt;
 2**2 #This will equal 4.&lt;br /&gt;
 &lt;br /&gt;
 #Square root: &lt;br /&gt;
 sqrt(4) #This will equal 2.&lt;br /&gt;
 &lt;br /&gt;
 #Remainder: &lt;br /&gt;
 5%4 #This will equal 1.&lt;br /&gt;
&lt;br /&gt;
==Print Function==&lt;br /&gt;
&lt;br /&gt;
In order to see any of the information we’ve listed above, you have to actually print it. For example, the code below will run but will not provide you with an output.&lt;br /&gt;
 x = 1 + 1&lt;br /&gt;
Instead, you have to print this information in order to see the answer when the code is finished running. You can do this in two ways. First, you can directly imbed the code in your print statement.&lt;br /&gt;
 print(1 + 1)&lt;br /&gt;
Or, you can create the variable and then print the variable.&lt;br /&gt;
 x = 1 + 1&lt;br /&gt;
 print(x)&lt;br /&gt;
Either one is valid!&lt;br /&gt;
If you would like to print something other than a variable, include quotations around it. For example, if you wanted to print the typical “Hello, world!”, you would code:&lt;br /&gt;
 print(“Hello, world!”)&lt;br /&gt;
The quotations are the important takeaway here.&lt;br /&gt;
&lt;br /&gt;
==Conditional==&lt;br /&gt;
A conditional involves an “if” statement. “If this thing is true, do this”, for example. Conditionals are useful in physics if you want to perform different things on a variable, depending on certain conditions.&lt;br /&gt;
 if x &amp;gt; 1:&lt;br /&gt;
 	print(“x is greater than 1”)&lt;br /&gt;
 elif x = 1:&lt;br /&gt;
 	print(“x is equal to 1”)&lt;br /&gt;
 else:&lt;br /&gt;
 	print(“x is less than 1”)&lt;br /&gt;
Above is the typical syntax you would see for a conditional. Notice the conditional starts with an if statement, followed by a colon. The next line is indented, and then tells that if statement what to do if the if statement is true. If it is not true, it moves on to the elif statement. Elif statements are used after if statements, but when there is still an if statement involved. There can be endless elif statements. Notice this uses the same syntax as the regular if statement. Lastly, if neither the if nor the elif statement(s) are true, there is an else statement. This will print if nothing above was true.&lt;br /&gt;
&lt;br /&gt;
==Loop==&lt;br /&gt;
A loop iterates through each item in a list or range. Loops can be useful in physics because they are vital to update equations. Loops will automatically update the information for you, rather than having to write out the long iterative process yourself. Below are examples of for loops and while loops.&lt;br /&gt;
 for i in range(1,11):&lt;br /&gt;
 	print(i)&lt;br /&gt;
The statement above will print:&lt;br /&gt;
 1&lt;br /&gt;
 2&lt;br /&gt;
 3&lt;br /&gt;
 4&lt;br /&gt;
 5&lt;br /&gt;
 6&lt;br /&gt;
 7&lt;br /&gt;
 8&lt;br /&gt;
 9&lt;br /&gt;
 10&lt;br /&gt;
Notice it does not print 11. When inputting a range in Python, the last number is not included. Notice how the for loop states “for”, and then a variable, and then a range, and then a colon. This is then followed by a statement that tells what to do for each iteration in the loop. Notice it is indented!&lt;br /&gt;
 while i &amp;gt; 1:&lt;br /&gt;
 	print(i)&lt;br /&gt;
This is an example of a while loop. While i is greater than 1, the code will print i. The syntax is similar to the for loop.&lt;br /&gt;
&lt;br /&gt;
==Equal Signs==&lt;br /&gt;
&lt;br /&gt;
“=” and “==” mean two different things in Python. When setting a variable equal to something, you use one equal sign:&lt;br /&gt;
 x = 2&lt;br /&gt;
However, when you are using it in something like an if statement, use two equal signs:&lt;br /&gt;
 if x == 2:&lt;br /&gt;
 	print(“x equals 2)&lt;br /&gt;
&lt;br /&gt;
=VPython Basics=&lt;br /&gt;
&lt;br /&gt;
In this section we will analyze some of the objects utilized by VPython. Each object is more or less self-explanatory with equally clear fields within.&lt;br /&gt;
&lt;br /&gt;
==Starting Your VPython Program==&lt;br /&gt;
To begin with, note that every VPython program must begin with these two lines of code:&lt;br /&gt;
 from__future__ import division&lt;br /&gt;
 from visual import*&lt;br /&gt;
    &lt;br /&gt;
The scene, or visual where you see your code occur, has a width and a height. You can alter them, as seen below.&lt;br /&gt;
 scene.width = 1024&lt;br /&gt;
 scene.height = 760&lt;br /&gt;
&lt;br /&gt;
==Vectors==&lt;br /&gt;
You can access each component of the vector with pos.x, pos.y, or pos.z, depending on which component you want. You access an object&#039;s field with a period following the variable name.&lt;br /&gt;
 pos = vector(1, 2, 3)&lt;br /&gt;
 xComponent = pos.x  #This value would be 1&lt;br /&gt;
 yComponent = pos.y  #This value would be 2&lt;br /&gt;
 zComponent = pos.z. #This value would be 3&lt;br /&gt;
&lt;br /&gt;
You can add two or more vectors together and you can multiply a vector by a scalar. Keep in mind you cannot add a vector and a scalar.&lt;br /&gt;
 #Adding&lt;br /&gt;
 A = vector(1, 2, 3)&lt;br /&gt;
 B = vector(4, 5, 6)&lt;br /&gt;
 C = A + B  # The value of C is now (5, 7, 9)&lt;br /&gt;
 # Multiplying&lt;br /&gt;
 D = 5 * C. # The value of D is now (25, 35, 45)&lt;br /&gt;
&lt;br /&gt;
To get the magnitude of or to normalize a vector, use the appropriate function.&lt;br /&gt;
 initialPos = vector(10, 3, 0)&lt;br /&gt;
 finalPos = vector(30, 15, 0)&lt;br /&gt;
 deltaR = finalPos - initialPos # -&amp;gt; vector(20, 12, 0)&lt;br /&gt;
 rMag = mag(finalPos)&lt;br /&gt;
 rHat = norm(finalPos)&lt;br /&gt;
 errorDemo = magR + finalPos # -&amp;gt; error; causes your program to crash&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Shapes==&lt;br /&gt;
&lt;br /&gt;
There are a number of different shapes you can create for visual reference in the vPython program. These will be used quite frequently in lab to observe things like momentum, force, etc. If you were to make, say, a ball, you would want to draw a sphere. It has a position field, a radius field, and a color field. When creating a new instance of an object, each field is comma separated. You access each field the same way as we did with the position vector.&lt;br /&gt;
 ball = sphere(pos = vector(10, 10, 10), radius = 9e2, color = color.red)&lt;br /&gt;
 ballColor = ball.color&lt;br /&gt;
 ballPos = ball.pos&lt;br /&gt;
 ballRadius = ball.radius&lt;br /&gt;
&lt;br /&gt;
You can draw arrows. These also have a color and position field, but instead of a radius, they have an axis that determines their length. These arrows can be used to represent the magnitude of the force or the momentum or anything else the lab asks you to make. &lt;br /&gt;
 velocityArrow = arrow(color = color.blue, pos = vector(-10, -10, -10), axis = velocity * vScale)&lt;br /&gt;
&lt;br /&gt;
There are also boxes. They have a position vector and a size vector.&lt;br /&gt;
 myBox = box(pos = vector(50, 50, 50), size = vector(20, 15, 12))&lt;br /&gt;
&lt;br /&gt;
You can draw helixes, which are useful for depicting springs. They have a position field, a color field, a thickness field, a radius field, and a field for the number of coils.&lt;br /&gt;
 spring = helix(pos=ceiling.pos, color=color.cyan, thickness=.003, coils=40, radius=0.015)&lt;br /&gt;
&lt;br /&gt;
==Tracing==&lt;br /&gt;
&lt;br /&gt;
If you want to trace a moving object, you can have a curve follow it by adding to it every time step. This will show the entire path the object has traveled during the simulation.&lt;br /&gt;
 posTrace = curve(color = color.yellow)&lt;br /&gt;
 trail.append(ball.pos)&lt;br /&gt;
&lt;br /&gt;
==Graphs==&lt;br /&gt;
&lt;br /&gt;
You also have the option of making graphs as your program progresses; this is particularly useful for potential vs kinetic energy.&lt;br /&gt;
 Kgraph = gcurve(color = color.cyan)&lt;br /&gt;
 Ugraph = gcurve(color = color.yellow)&lt;br /&gt;
 KplusUgraph = gcurve(color = color.red)&lt;br /&gt;
 # For each time step...&lt;br /&gt;
 Kgraph.plot(pos = (t, Kenergy))&lt;br /&gt;
 Ugraph.plot(pos = (t, Uenergy))&lt;br /&gt;
 KplusUgraph.plot(pos = (t, Kenergy + Uenergy))&lt;br /&gt;
&lt;br /&gt;
By updating the fields of whatever objects you decide to use and by using any intermediate variables necessary, you&#039;re able to draw and compute what you&#039;ll need for this course.&lt;/div&gt;</summary>
		<author><name>Mmorris83</name></author>
	</entry>
	<entry>
		<id>http://www.physicsbook.gatech.edu/index.php?title=Python_Syntax&amp;diff=38019</id>
		<title>Python Syntax</title>
		<link rel="alternate" type="text/html" href="http://www.physicsbook.gatech.edu/index.php?title=Python_Syntax&amp;diff=38019"/>
		<updated>2019-10-22T06:42:27Z</updated>

		<summary type="html">&lt;p&gt;Mmorris83: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&#039;&#039;&#039;Claimed by Miriam Morris for Fall 2019&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==The Main Idea==&lt;br /&gt;
VPython is an extension of the Python programming language that contains a 3D graphics module called Visual, which allows users to create simple simulations of physics problems. Its primary use is for educational purposes, although it has been used in research before in the past. Although it is slightly different from the actual Python program, it is similar enough for the purpose of this class. Most of the labs done this year will be done using the vPython program.&lt;br /&gt;
&lt;br /&gt;
==Downloading vPython==&lt;br /&gt;
In all cases you will need to have Python 2.7.9 installed. Future versions may also work, but be warned that it may cause VPython to behave erratically.&lt;br /&gt;
&lt;br /&gt;
[http://vpython.org/contents/download_windows.html For Windows]&lt;br /&gt;
&lt;br /&gt;
[http://vpython.org/contents/download_mac.html For Mac]&lt;br /&gt;
&lt;br /&gt;
[http://vpython.org/contents/download_linux.html For Linux]&lt;br /&gt;
&lt;br /&gt;
Note for Linux: You can only install Classic VPython, which is no longer supported and may be missing some features and bug fixes that are present in the current version of VPython.&lt;br /&gt;
&lt;br /&gt;
Alternatively, you can use GlowScript, a virtual environment that allows you to execute VPython code in your browser. You can create an account at [http://www.glowscript.org/ http://www.glowscript.org/]. Although this is useful, keep in mind that not all labs can be completed through GlowScript.&lt;br /&gt;
&lt;br /&gt;
=Python Basics=&lt;br /&gt;
&lt;br /&gt;
==Variables==&lt;br /&gt;
&lt;br /&gt;
A variable is an item within your code that has information stored in it. This information can be a number, a string of letters, or anything really. &amp;lt;br&amp;gt;&lt;br /&gt;
Variables are identified by a name. The names of your variables should be simple, but logical. Avoid names that include spaces or dots, because Python does not like this syntax. Rather, it is best to separate two words in a variable name by capitalizing the second word, such as “myVariable”, or an underscore, such as “my_variable”. &amp;lt;br&amp;gt;&lt;br /&gt;
Storing items as a variable allows for easy access when they are needed later in your program. &amp;lt;br&amp;gt;&lt;br /&gt;
One last thing that is important to note is that you can reassign variables. For example, the code below is completely valid.&amp;lt;br&amp;gt;&lt;br /&gt;
 x = 5&lt;br /&gt;
 x = x + 2&lt;br /&gt;
When this code is finished running, x will equal 7. Although this is counterintuitive at first, it’s easy to get used to.&lt;br /&gt;
&lt;br /&gt;
==Comments==&lt;br /&gt;
&lt;br /&gt;
Comments are useful when you want to include a note or a quick explanation in your code that will make it easier to understand later. Comments are sections of code that the computer will skip in execution, so it will not actually be executed when your program runs. There are two types of comments that Python uses, single line comments and multi-line comments.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Single Line Comments&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
To create a single line comment (the most common comments in Python) type a hash character (#) at the beginning of anything you would like to comment out. Note, when &amp;quot;#&amp;quot; is in a line of code, the rest of the code following the # will be ignored by the computer when your code runs.&lt;br /&gt;
&lt;br /&gt;
 # This is a comment.&lt;br /&gt;
 &lt;br /&gt;
 a = 4 # and so is this&lt;br /&gt;
 &lt;br /&gt;
 # b = 4 # and so is this entire line, be careful!&lt;br /&gt;
&lt;br /&gt;
Here is an example of comment use that you might see in a lab:&lt;br /&gt;
&lt;br /&gt;
 myTemp = 4 #This is the temperature in Celsius.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Multi-line Comments&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
To create a multi-line comment (usually reserved for longer explanations or instructions that cannot fit on one line) type three opening and closing quotation marks, like so:&lt;br /&gt;
&lt;br /&gt;
 &amp;quot;&amp;quot;&amp;quot; this &lt;br /&gt;
     is&lt;br /&gt;
     a&lt;br /&gt;
     multi-line&lt;br /&gt;
     comment &lt;br /&gt;
     example &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
 &amp;quot;&amp;quot;&amp;quot; this is also an example, but on only one line&amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Be careful! Unlike the single line comments, multi-line comments require a start and a stop (if you forget to close your comment or forget the third quotation mark then that will cause an error in your code).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Main Uses&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
- Longer variable explanation (units, where the data comes from, etc)&lt;br /&gt;
&lt;br /&gt;
- Comment out code (to save for later, instead of deleting it)&lt;br /&gt;
&lt;br /&gt;
- Instructions&lt;br /&gt;
&lt;br /&gt;
- Notes to self&lt;br /&gt;
&lt;br /&gt;
==Math Operations==&lt;br /&gt;
&lt;br /&gt;
Math operations are simple in Python. The simple operations, as you might expect, are as follows:&lt;br /&gt;
 #Addition: &lt;br /&gt;
 1+2 #This will equal 3.&lt;br /&gt;
 #Subtraction: &lt;br /&gt;
 2-1 #This will equal 1.&lt;br /&gt;
 #Multiplication: &lt;br /&gt;
 2*1 #This will equal 2.&lt;br /&gt;
 #Division: &lt;br /&gt;
 2/1 #This will equal 2.&lt;br /&gt;
There are other operations, that you may want to pay closer attention to.&lt;br /&gt;
 #Exponentiation: &lt;br /&gt;
 2**2 #This will equal 4.&lt;br /&gt;
 #Square root: &lt;br /&gt;
 sqrt(4) #This will equal 2.&lt;br /&gt;
 #Remainder: &lt;br /&gt;
 5%4 #This will equal 1.&lt;br /&gt;
&lt;br /&gt;
==Print Function==&lt;br /&gt;
&lt;br /&gt;
In order to see any of the information we’ve listed above, you have to actually print it. For example, the code below will run but will not provide you with an output.&lt;br /&gt;
 x = 1 + 1&lt;br /&gt;
Instead, you have to print this information in order to see the answer when the code is finished running. You can do this in two ways. First, you can directly imbed the code in your print statement.&lt;br /&gt;
 print(1 + 1)&lt;br /&gt;
Or, you can create the variable and then print the variable.&lt;br /&gt;
 x = 1 + 1&lt;br /&gt;
 print(x)&lt;br /&gt;
Either one is valid!&lt;br /&gt;
If you would like to print something other than a variable, include quotations around it. For example, if you wanted to print the typical “Hello, world!”, you would code:&lt;br /&gt;
 print(“Hello, world!”)&lt;br /&gt;
The quotations are the important takeaway here.&lt;br /&gt;
&lt;br /&gt;
==Conditional==&lt;br /&gt;
A conditional involves an “if” statement. “If this thing is true, do this”, for example. Conditionals are useful in physics if you want to perform different things on a variable, depending on certain conditions.&lt;br /&gt;
 if x &amp;gt; 1:&lt;br /&gt;
 	print(“x is greater than 1”)&lt;br /&gt;
 elif x = 1:&lt;br /&gt;
 	print(“x is equal to 1”)&lt;br /&gt;
 else:&lt;br /&gt;
 	print(“x is less than 1”)&lt;br /&gt;
Above is the typical syntax you would see for a conditional. Notice the conditional starts with an if statement, followed by a colon. The next line is indented, and then tells that if statement what to do if the if statement is true. If it is not true, it moves on to the elif statement. Elif statements are used after if statements, but when there is still an if statement involved. There can be endless elif statements. Notice this uses the same syntax as the regular if statement. Lastly, if neither the if nor the elif statement(s) are true, there is an else statement. This will print if nothing above was true.&lt;br /&gt;
&lt;br /&gt;
==Loop==&lt;br /&gt;
A loop iterates through each item in a list or range. Loops can be useful in physics because they are vital to update equations. Loops will automatically update the information for you, rather than having to write out the long iterative process yourself. Below are examples of for loops and while loops.&lt;br /&gt;
 for i in range(1,11):&lt;br /&gt;
 	print(i)&lt;br /&gt;
The statement above will print:&lt;br /&gt;
 1&lt;br /&gt;
 2&lt;br /&gt;
 3&lt;br /&gt;
 4&lt;br /&gt;
 5&lt;br /&gt;
 6&lt;br /&gt;
 7&lt;br /&gt;
 8&lt;br /&gt;
 9&lt;br /&gt;
 10&lt;br /&gt;
Notice it does not print 11. When inputting a range in Python, the last number is not included. Notice how the for loop states “for”, and then a variable, and then a range, and then a colon. This is then followed by a statement that tells what to do for each iteration in the loop. Notice it is indented!&lt;br /&gt;
 while i &amp;gt; 1:&lt;br /&gt;
 	print(i)&lt;br /&gt;
This is an example of a while loop. While i is greater than 1, the code will print i. The syntax is similar to the for loop.&lt;br /&gt;
&lt;br /&gt;
==Equal Signs==&lt;br /&gt;
&lt;br /&gt;
“=” and “==” mean two different things in Python. When setting a variable equal to something, you use one equal sign:&lt;br /&gt;
 x = 2&lt;br /&gt;
However, when you are using it in something like an if statement, use two equal signs:&lt;br /&gt;
 if x == 2:&lt;br /&gt;
 	print(“x equals 2)&lt;br /&gt;
&lt;br /&gt;
=VPython Basics=&lt;br /&gt;
&lt;br /&gt;
In this section we will analyze some of the objects utilized by VPython. Each object is more or less self-explanatory with equally clear fields within.&lt;br /&gt;
&lt;br /&gt;
==Starting Your VPython Program==&lt;br /&gt;
To begin with, note that every VPython program must begin with these two lines of code:&lt;br /&gt;
 from__future__ import division&lt;br /&gt;
 from visual import*&lt;br /&gt;
    &lt;br /&gt;
The scene, or visual where you see your code occur, has a width and a height. You can alter them, as seen below.&lt;br /&gt;
 scene.width = 1024&lt;br /&gt;
 scene.height = 760&lt;br /&gt;
&lt;br /&gt;
==Vectors==&lt;br /&gt;
You can access each component of the vector with pos.x, pos.y, or pos.z, depending on which component you want. You access an object&#039;s field with a period following the variable name.&lt;br /&gt;
 pos = vector(1, 2, 3)&lt;br /&gt;
 xComponent = pos.x  #This value would be 1&lt;br /&gt;
 yComponent = pos.y  #This value would be 2&lt;br /&gt;
 zComponent = pos.z. #This value would be 3&lt;br /&gt;
&lt;br /&gt;
You can add two or more vectors together and you can multiply a vector by a scalar. Keep in mind you cannot add a vector and a scalar.&lt;br /&gt;
 #Adding&lt;br /&gt;
 A = vector(1, 2, 3)&lt;br /&gt;
 B = vector(4, 5, 6)&lt;br /&gt;
 C = A + B  # The value of C is now (5, 7, 9)&lt;br /&gt;
 # Multiplying&lt;br /&gt;
 D = 5 * C. # The value of D is now (25, 35, 45)&lt;br /&gt;
&lt;br /&gt;
To get the magnitude of or to normalize a vector, use the appropriate function.&lt;br /&gt;
 initialPos = vector(10, 3, 0)&lt;br /&gt;
 finalPos = vector(30, 15, 0)&lt;br /&gt;
 deltaR = finalPos - initialPos # -&amp;gt; vector(20, 12, 0)&lt;br /&gt;
 rMag = mag(finalPos)&lt;br /&gt;
 rHat = norm(finalPos)&lt;br /&gt;
 errorDemo = magR + finalPos # -&amp;gt; error; causes your program to crash&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Shapes==&lt;br /&gt;
&lt;br /&gt;
There are a number of different shapes you can create for visual reference in the vPython program. These will be used quite frequently in lab to observe things like momentum, force, etc. If you were to make, say, a ball, you would want to draw a sphere. It has a position field, a radius field, and a color field. When creating a new instance of an object, each field is comma separated. You access each field the same way as we did with the position vector.&lt;br /&gt;
 ball = sphere(pos = vector(10, 10, 10), radius = 9e2, color = color.red)&lt;br /&gt;
 ballColor = ball.color&lt;br /&gt;
 ballPos = ball.pos&lt;br /&gt;
 ballRadius = ball.radius&lt;br /&gt;
&lt;br /&gt;
You can draw arrows. These also have a color and position field, but instead of a radius, they have an axis that determines their length. These arrows can be used to represent the magnitude of the force or the momentum or anything else the lab asks you to make. &lt;br /&gt;
 velocityArrow = arrow(color = color.blue, pos = vector(-10, -10, -10), axis = velocity * vScale)&lt;br /&gt;
&lt;br /&gt;
There are also boxes. They have a position vector and a size vector.&lt;br /&gt;
 myBox = box(pos = vector(50, 50, 50), size = vector(20, 15, 12))&lt;br /&gt;
&lt;br /&gt;
You can draw helixes, which are useful for depicting springs. They have a position field, a color field, a thickness field, a radius field, and a field for the number of coils.&lt;br /&gt;
 spring = helix(pos=ceiling.pos, color=color.cyan, thickness=.003, coils=40, radius=0.015)&lt;br /&gt;
&lt;br /&gt;
==Tracing==&lt;br /&gt;
&lt;br /&gt;
If you want to trace a moving object, you can have a curve follow it by adding to it every time step. This will show the entire path the object has traveled during the simulation.&lt;br /&gt;
 posTrace = curve(color = color.yellow)&lt;br /&gt;
 trail.append(ball.pos)&lt;br /&gt;
&lt;br /&gt;
==Graphs==&lt;br /&gt;
&lt;br /&gt;
You also have the option of making graphs as your program progresses; this is particularly useful for potential vs kinetic energy.&lt;br /&gt;
 Kgraph = gcurve(color = color.cyan)&lt;br /&gt;
 Ugraph = gcurve(color = color.yellow)&lt;br /&gt;
 KplusUgraph = gcurve(color = color.red)&lt;br /&gt;
 # For each time step...&lt;br /&gt;
 Kgraph.plot(pos = (t, Kenergy))&lt;br /&gt;
 Ugraph.plot(pos = (t, Uenergy))&lt;br /&gt;
 KplusUgraph.plot(pos = (t, Kenergy + Uenergy))&lt;br /&gt;
&lt;br /&gt;
By updating the fields of whatever objects you decide to use and by using any intermediate variables necessary, you&#039;re able to draw and compute what you&#039;ll need for this course.&lt;/div&gt;</summary>
		<author><name>Mmorris83</name></author>
	</entry>
	<entry>
		<id>http://www.physicsbook.gatech.edu/index.php?title=Python_Syntax&amp;diff=38018</id>
		<title>Python Syntax</title>
		<link rel="alternate" type="text/html" href="http://www.physicsbook.gatech.edu/index.php?title=Python_Syntax&amp;diff=38018"/>
		<updated>2019-10-22T06:41:51Z</updated>

		<summary type="html">&lt;p&gt;Mmorris83: /* Comments */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&#039;&#039;&#039;Claimed by Morgan Powers for Fall 2018&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==The Main Idea==&lt;br /&gt;
VPython is an extension of the Python programming language that contains a 3D graphics module called Visual, which allows users to create simple simulations of physics problems. Its primary use is for educational purposes, although it has been used in research before in the past. Although it is slightly different from the actual Python program, it is similar enough for the purpose of this class. Most of the labs done this year will be done using the vPython program.&lt;br /&gt;
&lt;br /&gt;
==Downloading vPython==&lt;br /&gt;
In all cases you will need to have Python 2.7.9 installed. Future versions may also work, but be warned that it may cause VPython to behave erratically.&lt;br /&gt;
&lt;br /&gt;
[http://vpython.org/contents/download_windows.html For Windows]&lt;br /&gt;
&lt;br /&gt;
[http://vpython.org/contents/download_mac.html For Mac]&lt;br /&gt;
&lt;br /&gt;
[http://vpython.org/contents/download_linux.html For Linux]&lt;br /&gt;
&lt;br /&gt;
Note for Linux: You can only install Classic VPython, which is no longer supported and may be missing some features and bug fixes that are present in the current version of VPython.&lt;br /&gt;
&lt;br /&gt;
Alternatively, you can use GlowScript, a virtual environment that allows you to execute VPython code in your browser. You can create an account at [http://www.glowscript.org/ http://www.glowscript.org/]. Although this is useful, keep in mind that not all labs can be completed through GlowScript.&lt;br /&gt;
&lt;br /&gt;
=Python Basics=&lt;br /&gt;
&lt;br /&gt;
==Variables==&lt;br /&gt;
&lt;br /&gt;
A variable is an item within your code that has information stored in it. This information can be a number, a string of letters, or anything really. &amp;lt;br&amp;gt;&lt;br /&gt;
Variables are identified by a name. The names of your variables should be simple, but logical. Avoid names that include spaces or dots, because Python does not like this syntax. Rather, it is best to separate two words in a variable name by capitalizing the second word, such as “myVariable”, or an underscore, such as “my_variable”. &amp;lt;br&amp;gt;&lt;br /&gt;
Storing items as a variable allows for easy access when they are needed later in your program. &amp;lt;br&amp;gt;&lt;br /&gt;
One last thing that is important to note is that you can reassign variables. For example, the code below is completely valid.&amp;lt;br&amp;gt;&lt;br /&gt;
 x = 5&lt;br /&gt;
 x = x + 2&lt;br /&gt;
When this code is finished running, x will equal 7. Although this is counterintuitive at first, it’s easy to get used to.&lt;br /&gt;
&lt;br /&gt;
==Comments==&lt;br /&gt;
&lt;br /&gt;
Comments are useful when you want to include a note or a quick explanation in your code that will make it easier to understand later. Comments are sections of code that the computer will skip in execution, so it will not actually be executed when your program runs. There are two types of comments that Python uses, single line comments and multi-line comments.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Single Line Comments&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
To create a single line comment (the most common comments in Python) type a hash character (#) at the beginning of anything you would like to comment out. Note, when &amp;quot;#&amp;quot; is in a line of code, the rest of the code following the # will be ignored by the computer when your code runs.&lt;br /&gt;
&lt;br /&gt;
 # This is a comment.&lt;br /&gt;
 &lt;br /&gt;
 a = 4 # and so is this&lt;br /&gt;
 &lt;br /&gt;
 # b = 4 # and so is this entire line, be careful!&lt;br /&gt;
&lt;br /&gt;
Here is an example of comment use that you might see in a lab:&lt;br /&gt;
&lt;br /&gt;
 myTemp = 4 #This is the temperature in Celsius.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Multi-line Comments&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
To create a multi-line comment (usually reserved for longer explanations or instructions that cannot fit on one line) type three opening and closing quotation marks, like so:&lt;br /&gt;
&lt;br /&gt;
 &amp;quot;&amp;quot;&amp;quot; this &lt;br /&gt;
     is&lt;br /&gt;
     a&lt;br /&gt;
     multi-line&lt;br /&gt;
     comment &lt;br /&gt;
     example &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
 &amp;quot;&amp;quot;&amp;quot; this is also an example, but on only one line&amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Be careful! Unlike the single line comments, multi-line comments require a start and a stop (if you forget to close your comment or forget the third quotation mark then that will cause an error in your code).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Main Uses&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
- Longer variable explanation (units, where the data comes from, etc)&lt;br /&gt;
&lt;br /&gt;
- Comment out code (to save for later, instead of deleting it)&lt;br /&gt;
&lt;br /&gt;
- Instructions&lt;br /&gt;
&lt;br /&gt;
- Notes to self&lt;br /&gt;
&lt;br /&gt;
==Math Operations==&lt;br /&gt;
&lt;br /&gt;
Math operations are simple in Python. The simple operations, as you might expect, are as follows:&lt;br /&gt;
 #Addition: &lt;br /&gt;
 1+2 #This will equal 3.&lt;br /&gt;
 #Subtraction: &lt;br /&gt;
 2-1 #This will equal 1.&lt;br /&gt;
 #Multiplication: &lt;br /&gt;
 2*1 #This will equal 2.&lt;br /&gt;
 #Division: &lt;br /&gt;
 2/1 #This will equal 2.&lt;br /&gt;
There are other operations, that you may want to pay closer attention to.&lt;br /&gt;
 #Exponentiation: &lt;br /&gt;
 2**2 #This will equal 4.&lt;br /&gt;
 #Square root: &lt;br /&gt;
 sqrt(4) #This will equal 2.&lt;br /&gt;
 #Remainder: &lt;br /&gt;
 5%4 #This will equal 1.&lt;br /&gt;
&lt;br /&gt;
==Print Function==&lt;br /&gt;
&lt;br /&gt;
In order to see any of the information we’ve listed above, you have to actually print it. For example, the code below will run but will not provide you with an output.&lt;br /&gt;
 x = 1 + 1&lt;br /&gt;
Instead, you have to print this information in order to see the answer when the code is finished running. You can do this in two ways. First, you can directly imbed the code in your print statement.&lt;br /&gt;
 print(1 + 1)&lt;br /&gt;
Or, you can create the variable and then print the variable.&lt;br /&gt;
 x = 1 + 1&lt;br /&gt;
 print(x)&lt;br /&gt;
Either one is valid!&lt;br /&gt;
If you would like to print something other than a variable, include quotations around it. For example, if you wanted to print the typical “Hello, world!”, you would code:&lt;br /&gt;
 print(“Hello, world!”)&lt;br /&gt;
The quotations are the important takeaway here.&lt;br /&gt;
&lt;br /&gt;
==Conditional==&lt;br /&gt;
A conditional involves an “if” statement. “If this thing is true, do this”, for example. Conditionals are useful in physics if you want to perform different things on a variable, depending on certain conditions.&lt;br /&gt;
 if x &amp;gt; 1:&lt;br /&gt;
 	print(“x is greater than 1”)&lt;br /&gt;
 elif x = 1:&lt;br /&gt;
 	print(“x is equal to 1”)&lt;br /&gt;
 else:&lt;br /&gt;
 	print(“x is less than 1”)&lt;br /&gt;
Above is the typical syntax you would see for a conditional. Notice the conditional starts with an if statement, followed by a colon. The next line is indented, and then tells that if statement what to do if the if statement is true. If it is not true, it moves on to the elif statement. Elif statements are used after if statements, but when there is still an if statement involved. There can be endless elif statements. Notice this uses the same syntax as the regular if statement. Lastly, if neither the if nor the elif statement(s) are true, there is an else statement. This will print if nothing above was true.&lt;br /&gt;
&lt;br /&gt;
==Loop==&lt;br /&gt;
A loop iterates through each item in a list or range. Loops can be useful in physics because they are vital to update equations. Loops will automatically update the information for you, rather than having to write out the long iterative process yourself. Below are examples of for loops and while loops.&lt;br /&gt;
 for i in range(1,11):&lt;br /&gt;
 	print(i)&lt;br /&gt;
The statement above will print:&lt;br /&gt;
 1&lt;br /&gt;
 2&lt;br /&gt;
 3&lt;br /&gt;
 4&lt;br /&gt;
 5&lt;br /&gt;
 6&lt;br /&gt;
 7&lt;br /&gt;
 8&lt;br /&gt;
 9&lt;br /&gt;
 10&lt;br /&gt;
Notice it does not print 11. When inputting a range in Python, the last number is not included. Notice how the for loop states “for”, and then a variable, and then a range, and then a colon. This is then followed by a statement that tells what to do for each iteration in the loop. Notice it is indented!&lt;br /&gt;
 while i &amp;gt; 1:&lt;br /&gt;
 	print(i)&lt;br /&gt;
This is an example of a while loop. While i is greater than 1, the code will print i. The syntax is similar to the for loop.&lt;br /&gt;
&lt;br /&gt;
==Equal Signs==&lt;br /&gt;
&lt;br /&gt;
“=” and “==” mean two different things in Python. When setting a variable equal to something, you use one equal sign:&lt;br /&gt;
 x = 2&lt;br /&gt;
However, when you are using it in something like an if statement, use two equal signs:&lt;br /&gt;
 if x == 2:&lt;br /&gt;
 	print(“x equals 2)&lt;br /&gt;
&lt;br /&gt;
=VPython Basics=&lt;br /&gt;
&lt;br /&gt;
In this section we will analyze some of the objects utilized by VPython. Each object is more or less self-explanatory with equally clear fields within.&lt;br /&gt;
&lt;br /&gt;
==Starting Your VPython Program==&lt;br /&gt;
To begin with, note that every VPython program must begin with these two lines of code:&lt;br /&gt;
 from__future__ import division&lt;br /&gt;
 from visual import*&lt;br /&gt;
    &lt;br /&gt;
The scene, or visual where you see your code occur, has a width and a height. You can alter them, as seen below.&lt;br /&gt;
 scene.width = 1024&lt;br /&gt;
 scene.height = 760&lt;br /&gt;
&lt;br /&gt;
==Vectors==&lt;br /&gt;
You can access each component of the vector with pos.x, pos.y, or pos.z, depending on which component you want. You access an object&#039;s field with a period following the variable name.&lt;br /&gt;
 pos = vector(1, 2, 3)&lt;br /&gt;
 xComponent = pos.x  #This value would be 1&lt;br /&gt;
 yComponent = pos.y  #This value would be 2&lt;br /&gt;
 zComponent = pos.z. #This value would be 3&lt;br /&gt;
&lt;br /&gt;
You can add two or more vectors together and you can multiply a vector by a scalar. Keep in mind you cannot add a vector and a scalar.&lt;br /&gt;
 #Adding&lt;br /&gt;
 A = vector(1, 2, 3)&lt;br /&gt;
 B = vector(4, 5, 6)&lt;br /&gt;
 C = A + B  # The value of C is now (5, 7, 9)&lt;br /&gt;
 # Multiplying&lt;br /&gt;
 D = 5 * C. # The value of D is now (25, 35, 45)&lt;br /&gt;
&lt;br /&gt;
To get the magnitude of or to normalize a vector, use the appropriate function.&lt;br /&gt;
 initialPos = vector(10, 3, 0)&lt;br /&gt;
 finalPos = vector(30, 15, 0)&lt;br /&gt;
 deltaR = finalPos - initialPos # -&amp;gt; vector(20, 12, 0)&lt;br /&gt;
 rMag = mag(finalPos)&lt;br /&gt;
 rHat = norm(finalPos)&lt;br /&gt;
 errorDemo = magR + finalPos # -&amp;gt; error; causes your program to crash&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Shapes==&lt;br /&gt;
&lt;br /&gt;
There are a number of different shapes you can create for visual reference in the vPython program. These will be used quite frequently in lab to observe things like momentum, force, etc. If you were to make, say, a ball, you would want to draw a sphere. It has a position field, a radius field, and a color field. When creating a new instance of an object, each field is comma separated. You access each field the same way as we did with the position vector.&lt;br /&gt;
 ball = sphere(pos = vector(10, 10, 10), radius = 9e2, color = color.red)&lt;br /&gt;
 ballColor = ball.color&lt;br /&gt;
 ballPos = ball.pos&lt;br /&gt;
 ballRadius = ball.radius&lt;br /&gt;
&lt;br /&gt;
You can draw arrows. These also have a color and position field, but instead of a radius, they have an axis that determines their length. These arrows can be used to represent the magnitude of the force or the momentum or anything else the lab asks you to make. &lt;br /&gt;
 velocityArrow = arrow(color = color.blue, pos = vector(-10, -10, -10), axis = velocity * vScale)&lt;br /&gt;
&lt;br /&gt;
There are also boxes. They have a position vector and a size vector.&lt;br /&gt;
 myBox = box(pos = vector(50, 50, 50), size = vector(20, 15, 12))&lt;br /&gt;
&lt;br /&gt;
You can draw helixes, which are useful for depicting springs. They have a position field, a color field, a thickness field, a radius field, and a field for the number of coils.&lt;br /&gt;
 spring = helix(pos=ceiling.pos, color=color.cyan, thickness=.003, coils=40, radius=0.015)&lt;br /&gt;
&lt;br /&gt;
==Tracing==&lt;br /&gt;
&lt;br /&gt;
If you want to trace a moving object, you can have a curve follow it by adding to it every time step. This will show the entire path the object has traveled during the simulation.&lt;br /&gt;
 posTrace = curve(color = color.yellow)&lt;br /&gt;
 trail.append(ball.pos)&lt;br /&gt;
&lt;br /&gt;
==Graphs==&lt;br /&gt;
&lt;br /&gt;
You also have the option of making graphs as your program progresses; this is particularly useful for potential vs kinetic energy.&lt;br /&gt;
 Kgraph = gcurve(color = color.cyan)&lt;br /&gt;
 Ugraph = gcurve(color = color.yellow)&lt;br /&gt;
 KplusUgraph = gcurve(color = color.red)&lt;br /&gt;
 # For each time step...&lt;br /&gt;
 Kgraph.plot(pos = (t, Kenergy))&lt;br /&gt;
 Ugraph.plot(pos = (t, Uenergy))&lt;br /&gt;
 KplusUgraph.plot(pos = (t, Kenergy + Uenergy))&lt;br /&gt;
&lt;br /&gt;
By updating the fields of whatever objects you decide to use and by using any intermediate variables necessary, you&#039;re able to draw and compute what you&#039;ll need for this course.&lt;/div&gt;</summary>
		<author><name>Mmorris83</name></author>
	</entry>
</feed>