VPython Object

From Physics Book
Revision as of 17:59, 5 December 2015 by Ddebord3 (talk | contribs)
Jump to navigation Jump to search

Claimed by Daniel DeBord. Not Finished


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.

VPython Objects

A VPython object is intended to represent data in a way that can be easily visualized and understood by both the user and the computer as it processes information. Each individual object has a specific type type it belongs to, which determines its default characteristics as well as how the computer will choose to display it when the program is run. The particular assigned characteristics of each object are known as its attributes. Some objects have default attributes such as "pos" in almost every object, but they can also have new attributes added to them to allow them to carry additional information.

Common Attributes

Many objects in VPython carry common attributes regardless of type. Here are some of the more significant examples of this.

Pos (Position)

Pos is a common attribute held by almost every object used to describe the position of that object's center or its endpoint. It is of the vector type and has three components of its own. It can be accessed using objectName.pos. Its individual components can be accessed using objectName.pos.direction where direction is either an x, y, or z depending on the component desired.

Color

Color is an attribute that defines the object's color when it appears in the display window. This attribute is important simply for distinguishing objects from one another. Color can be assigned in one of two ways. The first way it can be assigned is through a pre-set color such as red or cyan. The syntax for creating a red color is:

color = color.red.

Another way of assigning color is through an RGB vector. The vector contains three numbers from 0 to 1. The first number represents the red saturation, the second represents green, and the third represents blue. The higher the value of the number, the more it resembles that particular color. The syntax for doing this is:

color = (1, 0.5, 0).

Common Objects

In order to display the data effectively, there are some common objects that are important to understand.

Sphere

A sphere object is a representation of a sphere with a set radius, position, and color. A magenta sphere center centered at the origin with radius one can be created through the syntax:

nameSphere = sphere(radius = 1, pos = vector(0,0,0), color=color.magenta)

Arrow

An arrow object creates an arrow with a position, an axis, and a color. The axis is a vector representing the arrow's direction and length. Position is the location of its tail, not its center. A yellow arrow centered at (0,7,2) in the direction of (3,-9,1) can be created through:

nameArrow = arrow(pos=(0,7,2), axis=(3,-9,1), color=color.yellow)

Curve

A curve is series of connections between points. This can be used to show the path of an object through the append function. This function adds an additional point to the curve allowing the curve to follow each position added. To create a red curve and add the point (4,4,4) use the syntax:

nameCurve = curve(color.color = red)

nameCurve.append(4,4,4)

References[edit] This section contains the the references you used while writing this page