REVISED: Sunday, March 3, 2013
In this tutorial, you will learn vPython vectors.
I. SCALAR VERSUS VECTOR
Mathematics is the language of physics. "Scalar" and "vector" are two terms in mathematics that appear frequently when discussing physics. A scalar is a "real number" that is not associated with a direction. A mathematical quantity that has both a size, called its magnitude and direction, represented by its unit vector is a vector. "Distance", "length", or "speed" is synonymous with magnitude.
II. vPYTHON VECTOR VERSUS ARROW
There are several mathematical representations of vectors. vPython uses vector(x,y,z). By adding “.x”, “.y”, or “.z” to the name of a vector you can refer to the components of a vector. Where "x" is the "x axis", "y" is the "y axis", and "z" is the "z axis".
The vPython arrow object has a straight box-shaped shaft with an arrowhead on one end. The arrow object can be used to represent vectors. Attributes of the arrow object are "axis", "pos", and "color". The location of the tail of the arrow is specified by the "pos" attribute. A vector that points from the tail to the tip of the arrow is specified by the "axis" attribute. Arrows help to visualize vector quantities like momentum, position, and force in 3D. You can set the color to red, blue, green, cyan, magenta, yellow, orange, black, or white.
III. vPYTHON EXAMPLE ARROW PROGRAM
Start the vPython interpreter shell by "double left mouse clicking" the vPython icon on your desktop. When the "vPython Shell" window opens type the following code:
from __future__ import division #For floating point numbers.
from visual import * # Enables the graphics to work.
tonto=arrow(pos=vector(0, 1, 5), axis=vector(3, 1, 4), color=color.green) #Creates an arrow object named "tonto" with the following three attributes:
# 1. pos is the position vector <0, 1, 5> of the tail of the arrow.
# 2. axis is the components of the arrow vector <3, 1, 4> measured from the tail to the tip of the arrow.
# 3. color is the arrow’s color, which is green.
from visual import * # Enables the graphics to work.
tonto=arrow(pos=vector(0, 1, 5), axis=vector(3, 1, 4), color=color.green) #Creates an arrow object named "tonto" with the following three attributes:
# 1. pos is the position vector <0, 1, 5> of the tail of the arrow.
# 2. axis is the components of the arrow vector <3, 1, 4> measured from the tail to the tip of the arrow.
# 3. color is the arrow’s color, which is green.
From the "vPython Shell" window, do a "File Save" and save the above vPython program, using the file name arrowVector.py.
From the "vPython Shell" window, do a "Run" and then a "Run Module F5" and a vPython 3-D graphics scene will open displaying the arrow.
The comments which start with a hash, #, sign explain how this vPython program works.
IV. vPYTHON 3-D GRAPHICS SCENE
vPython automatically “zooms” the camera in or out so that all objects appear in the window. The coordinate system shows the positive x direction pointing to the right, the positive y direction going up, and the positive z direction moving toward you out of the screen, when you run the program. Rotating the camera view makes these axes point in other directions. Use the following controls when viewing objects in the vPython 3-D graphics scene:
A. TO ZOOM OUT AND IN
Move the mouse down or up and hold down both mouse buttons.
B. TO REVOLVE AROUND THE SCENE
Move the mouse and hold down the right mouse button alone.
-->
-->
-->
How to Link to My Home Page
It will appear on your website as:"Link to: ELCRIC OTTO CIRCLE's Home Page"
No comments:
Post a Comment