arrow An arrow is like a cylinder, but it has square cross-section and has an arrowhead at the end. Arrows have position (pos), color, axis, and shaftwidth. The position of the arrow is the position of thetail of the arrow, and the axis is the vector from the tail to the head. The default value of shaftwidth is 0.1×(length).
box A box has color, position (pos), length (x extent), height (y extent) and width (z extent). The position of the box refers to the center of the box. The box can also have an axis, which is the vector de- scribing the box’s x axis. (by default, the box x axis matches the window’sx axis.) In addition, the box has an “up”, which is a vector describing the box’s y axis. (by default, the boy y ayis matches the window’syayis.) Between pos, axis, and up it is possible to put a box in any orientation in space. In addition to specifying length, width, and height individually, it is possible to define the size of the box via
size =(length, width, height).
cone The cone has color, pos, axis, and radius. The position refers to the center of the cone’s base, and the axis is the vector from the position to the apex of the cone. The radius is that of the cone’s base.
curve A curve is actually a set of straight line segments between points. It’s most often used to trace out the path of some object, such as a
planet or the tip of a gyroscope. Curves have radius, which is the radius of the circular cross-section of the curve. The append function (curve.append(vector(x,y,z)) adds a new point (and line segment) to the end of the curve, which is particularly useful for tracing position of objects. The last line of example B.-1.1, for example, tacks the current position of the Dot onto the curve.
Technical note: No matter how many points there are in a curve, only 1000 points are shown. The points chosen are spread evenly over the whole curve. This keeps the display from slowing down too much, but it also makes the curve turn into a bunch of obviously straight lines if you make the curve very long.
cylinder Cylinders have position (pos), color, radius, and axis. It helps to think of a cylinder as a vector: the position of the cylinder is the location of the tail of the vector, and the axis describes the length and direction of the cylinder. A short cylinder looks like a disk, of course. ellipsoid An ellipsoid is described by exactly the same parameters as a box: position (pos), color, length, height, width, and axis. (The “up” parameter does not matter, since the ellipsoid is radially symmet- ric.) The resulting ellipsoid fits exactly within the box with the same dimensions and axis. In addition to specifying length, width, and height individually, it is possible to define the size of the ellipsoid via
size =(length, width, height).
frame A frame allows one to form composite objects that can be moved and rotated as if they were one object. For example:
pendulum = frame ( ) c y l i n d e r ( frame=pendulum , pos = ( 0 , 0 , 0 ) r a d i u s =0.1 c o l o r=c o l o r . b l u e a x i s =(0 ,−1 ,0)) s p h e r e ( frame=pendulum , pos =(0 ,−1 ,0) r a d i u s =0.2 c o l o r=c o l o r . cyan ) pendulum . a x i s = ( 0 , 1 , 0 ) # c h a n g e o r i e n t a t i o n o f e n t i r e frame
pendulum . pos = ( 1 , 2 , 1 ) # c h a n g e p o s i t i o n o f e n t i r e frame
You can change the parameters of all objects in a frame with a for loop:
B.1 VPython Objects 173
f o r i t e m in pendulum . o b j e c t s :
i t e m . c o l o r=c o l o r . g r e e n
Frame parameters include pos, x, y, z, axis, and up.
helix A helix is a spiral, defined in the same way as a cylinder. It has position (pos), radius, axis, and color, all of which are defined exactly as for a cylinder. In addition, a helix has “coils”, which is the number of turns in its entire length, and “thickness” which is the radius of the “wire” that makes the helix.
points A “points” is a set of points which will be indicated by circular or square markers. This is the same as a curve, but without the straight lines between points. The shape of the points can be circu- lar (shape=”round”) or square (shape=”square”). Points also have a characteristic size, which is most often set in pixels.
pyramid A pyramid has a rectangular base and tapers to a point. The pos of the pyramid is the position of the center of the base, and the axis is the vector between base and apex. The height and width of the pyramid are they and z extent of the base, respectively, and the length can be used to define thex extent of the pyramid. In addition to specifying length, width, and height individually, it is possible to define the size of the pyramid via size =(length, width, height).
ring A ring (toroid) has color, pos, radius, thickness, and axis. The pos of the ring is the position of the center of the ring. The radius is the radius from the center of the ring to the center of the material — the spoke length, if it were a bicycle wheel. Thickness refers to the radius (not diameter) of the ring material. The axis points along the axis of the ring. The magnitude of the axis is irrelevant: only the direction is used to orient the ring in space.
sphere The sphere has position (pos), color, and radius.
vector Vectors don’t display, but they’re very useful for calculations. They allow correct math, for example: vectors can be added and subtracted with predictable mathematical results. The functions cross (A, B) and dot(A, B) return the cross and dot products of vectorsA and B. The mag(A) function returns the magnitude of A. the norm(A) function returns the vector with the same direction as A but with length 1. You can also rotate a vector around an arbitrary axis, using the rotate function described below.