Skip to content
PrestonCranford edited this page Apr 6, 2018 · 44 revisions

box

#

For a box that isn't aligned with the coordinate axes, additional issues come into play. The orientation of the length of the box is given by the axis:box

The axis attribute gives a direction for the length of the box, and the length, height, and width of the box are given as before.

You can rotate the box around its own axis by changing which way is "up" for the box, by specifying an up attribute for the box that is different from the up vector of the coordinate system:

Here is a full list of attributes for a box. All 3D objects have all of these attributes, other than arrow and curve:

pos (Position): the center of the box; default = vec(0,0,0). Takes a vector as an argument.

axis:The axis points in the direction of the length of the box, default = vec(1,0,0). Only the direction of the axis is meaningful, not its magnitude. The length of the box is size.x, not the magnitude of the axis. An object's axis and up attributes are always perpendicular to each other. Changing the direction of axis also changes the direction of up so that the two directions always remain at right angles to each other. Takes a vector as an argument.

size: The length, width, and height of the box; default = vec(1,1,1). Takes a vector as an arguement.

up: Which side of the box is "up". An object's axis and up attributes are always perpendicular to each other. Changing the direction of up also changes the direction of axis so that the two directions always remain at right angles to each other. Takes a vector as an argument.

color: Color of object. Takes a color as an argument.

texture: You can specify a texture to apply to the object's surface. Takes a Takes a texture as an argument.

opacity: Opacity of object, default = 1 (fully opaque); 0 is completely transparent. Takes a 1 or 0 as an arguement.

make trail: Creates a dissipating path following the object. There are 4 components.

make trail: Trail visibility. takes true or false as an argument. type determines the shape of the trail, takes "curve" or "points" as an argument.

type: Trail shape. Default is "curve", but can be "points".

retain: Ff retain=50, only the 50 most recently added points will be retained, takes a constant as an argument.

interval: If interval=10, a point is added to the trail only every 10th move of the object. If interval is 0, no trail is shown. If trail_type is "points", the default interval = 1; interval must have a nonzero value because the points need to be accurately spaced in order to look right. If trail_type is "curve" (the default), and no interval is specified, updates to the trail are made every time a new image is rendered, typically about 30 to 60 times a second. This usually looks fine. Takes a constant as an argument.

velocity: Determines velocity of object (first derivative of motion). Takes a vector as an argument.

acc (Acceleration): Determines acceleration of object (second derivative of motion). Takes a vector as an argument.

mass: Determines mass of object. Takes a constant as an argument.

charge: Determines charge of object. Takes a constant as an argument.

sphere

This produces a sphere centered at location (1,2,1) with diameter = 3. If you specify unequal values for the components of size, you get an ellipsoid.

Here is a full list of attributes for a sphere. All 3D objects have all of these attributes, other than arrow and curve:

Here is a full list of attributes for a box. All 3D objects have all of these attributes, other than arrow and curve:

pos (Position): the center of the box; default = vec(0,0,0). Takes a vector as an argument.

axis:The axis points in the direction of the length of the box, default = vec(1,0,0). Only the direction of the axis is meaningful, not its magnitude. The length of the box is size.x, not the magnitude of the axis. An object's axis and up attributes are always perpendicular to each other. Changing the direction of axis also changes the direction of up so that the two directions always remain at right angles to each other. Takes a vector as an argument.

size: The length, width, and height of the box; default = vec(1,1,1). Takes a vector as an arguement.

up: Which side of the box is "up". An object's axis and up attributes are always perpendicular to each other. Changing the direction of up also changes the direction of axis so that the two directions always remain at right angles to each other. Takes a vector as an argument.

color: Color of object. Takes a color as an argument.

texture: You can specify a texture to apply to the object's surface. Takes a Takes a texture as an argument.

opacity: Opacity of object, default = 1 (fully opaque); 0 is completely transparent. Takes a 1 or 0 as an arguement.

make trail: Creates a dissipating path following the object. There are 4 components.

make trail: Trail visibility. takes true or false as an argument. type determines the shape of the trail, takes "curve" or "points" as an argument.

type: Trail shape. Default is "curve", but can be "points".

retain: Ff retain=50, only the 50 most recently added points will be retained, takes a constant as an argument.

interval: If interval=10, a point is added to the trail only every 10th move of the object. If interval is 0, no trail is shown. If trail_type is "points", the default interval = 1; interval must have a nonzero value because the points need to be accurately spaced in order to look right. If trail_type is "curve" (the default), and no interval is specified, updates to the trail are made every time a new image is rendered, typically about 30 to 60 times a second. This usually looks fine. Takes a constant as an argument.

velocity: Determines velocity of object (first derivative of motion). Takes a vector as an argument.

acc (Acceleration): Determines acceleration of object (second derivative of motion). Takes a vector as an argument.

mass: Determines mass of object. Takes a constant as an argument.

charge: Determines charge of object. Takes a constant as an argument.

arrow

The arrow object has the following attributes and default values, similar to those for cylinder: pos vec(0,0,0), axis_and_length vec(1,0,0), color vec(1,1,1) which is color.white, opacity (1), shininess (0.6), emissive (False), up vec(0,1,0), and visible (True). As with box, the up attribute is significant for arrow because the shaft and head have square cross sections, and setting the up attribute rotates the arrow about its axis.

axis_and_length: Due to its typical uses for quantitative displays of vector quantities, the arrow object differs from the other 3D objects. There is no size attribute; the lateral dimensions are determined by shaftwidth. The attribute axis_and_length is used to specify simultaneously the direction and the length of the arrow object. For example, pointer.axis_and_length = vec(3,4,0) yields an arrow pointing in the direction of vec(3,4,0) with a length that is 5, the magnitude of this vector.

Additional arrow attributes:

shaftwidth By default, shaftwidth = 0.1*(length of arrow)

headwidth By default, headwidth = 2*shaftwidth

headlength By default, headlength = 3*shaftwidth

Assigning shaftwidth = 0 makes it be the default (0.1 times the length of the arrow). If you don't explicitly set headwidth or headlength, its length is based as shown above on shaftwidth (either the default or whatever value you specify for shaftwidth). If headlength becomes larger than half the length of the arrow, or the shaft becomes thinner than 1/50 the length, the entire arrow is scaled accordingly.

If you specifically specify shaftwidth yourself, the only adjustment that is made is that headlength is adjusted so that it never gets longer than half the total length, so that the total length of the arrow is correct. This means that very short, thick arrows look similar to a thumbtack, with a nearly flat head.

No texture: Currently it is not possible to apply a texture to an arrow.

Here is a full list of attributes for a box. All 3D objects have all of these attributes, other than arrow and curve:

pos (Position): the center of the box; default = vec(0,0,0). Takes a vector as an argument.

axis:The axis points in the direction of the length of the box, default = vec(1,0,0). Only the direction of the axis is meaningful, not its magnitude. The length of the box is size.x, not the magnitude of the axis. An object's axis and up attributes are always perpendicular to each other. Changing the direction of axis also changes the direction of up so that the two directions always remain at right angles to each other. Takes a vector as an argument.

size: The length, width, and height of the box; default = vec(1,1,1). Takes a vector as an arguement.

up: Which side of the box is "up". An object's axis and up attributes are always perpendicular to each other. Changing the direction of up also changes the direction of axis so that the two directions always remain at right angles to each other. Takes a vector as an argument.

color: Color of object. Takes a color as an argument.

texture: You can specify a texture to apply to the object's surface. Takes a Takes a texture as an argument.

opacity: Opacity of object, default = 1 (fully opaque); 0 is completely transparent. Takes a 1 or 0 as an arguement.

make trail: Creates a dissipating path following the object. There are 4 components.

make trail: Trail visibility. takes true or false as an argument. type determines the shape of the trail, takes "curve" or "points" as an argument.

type: Trail shape. Default is "curve", but can be "points".

retain: Ff retain=50, only the 50 most recently added points will be retained, takes a constant as an argument.

interval: If interval=10, a point is added to the trail only every 10th move of the object. If interval is 0, no trail is shown. If trail_type is "points", the default interval = 1; interval must have a nonzero value because the points need to be accurately spaced in order to look right. If trail_type is "curve" (the default), and no interval is specified, updates to the trail are made every time a new image is rendered, typically about 30 to 60 times a second. This usually looks fine. Takes a constant as an argument.

velocity: Determines velocity of object (first derivative of motion). Takes a vector as an argument.

acc (Acceleration): Determines acceleration of object (second derivative of motion). Takes a vector as an argument.

mass: Determines mass of object. Takes a constant as an argument.

charge: Determines charge of object. Takes a constant as an argument.

End vs center: The pos attribute for arrow, cone, cylinder, helix, and pyramid corresponds to one end of the object, whereas for a box, ring, or sphere it corresponds to the center of the object.

cylinder

cylinder cylinder Studying this description of the cylinder object provides an overview of important aspects common to all of the GlowScript 3D objects, box, sphere, pyramid, etc. Additional details about how to orient an object using "axis" and "up" are found in the description of the box object.

Here is an example of how to make a cylinder, naming it "rod" for future reference:

rod = cylinder() rod.pos = vec(0,1,2) rod.axis = vec(1,0,0) rod.size = vec(5,1,1)

Attributes: The properties pos (position), axis, and size are called "attributes" of the object. The function "vec" creates a vector with (x,y,z) components.

cylinder Alternatively, you can specify the initial values of the attributes when creating the cylinder::

rod = cylinder( pos=vec(0,2,1), axis=vec(1,0,0), size=vec(5,1,1) )

The center of one end of this cylinder (pos) is at x=0, y=2, and z=1. Its axis lies along the x axis, vec(1,0,0), which points to the right (y points up, z points out of the screen toward you). The size or bounding box is 5 in the direction of the axis, so that the other end of the cylinder is at (5,2,1). The lateral size of the cylinder, the diameter, is 1. If you specify the size to be vec(3,1,2), the cylinder will have an elliptical cross section.

Modifying attributes

You can modify the position attribute of the cylinder after it has been created, which has the effect of moving it immediately to the new position:

rod.pos=vec(15,11,9) # change (x,y,z) rod.pos.x=15 # change the x component

If you create an object such as a cylinder without giving it a name such as rod, you can't refer to it later. This doesn't matter if you never intend to modify the object.

The bounding box: All of the 3D objects (except for arrow) can be thought of as being contained in a box whose size is specified by the size attribute. Changing the size corresponds to stretching or squeezing the box that contains the object. Setting size to vec(3,1,2) means that if the axis is in the x direction, vec(1,0,0), the bounding box will be 3 have a length of 3 in the x direction, a height of 1 in they y direction, and a depth of 2 in the z direction.

If you change the axis (rod.axis) to point in some direction other than in the x direction, you still specify the size attribute as though the axis were pointing to the right. In other words, when specifying the size, imagine that the object is aligned along the x axis even if you specify a different direction by setting the axis attribute. This is true for all the 3D objects (other than arrow).

Specifying the color: Since we didn't specify a color for rod, the cylinder will be the default color, which is white (shown on a black background). After creating the cylinder, you can change its color. The following will change the color to blue:

rod.color = vec(0,0,1) # same as color.blue

This uses the so-called RGB system for specifying colors in terms of fractions of red, green, and blue. (For details on choosing colors, see Specifying Colors.) You can set individual amounts of red, green, and blue, as colors are treated as though they were vectors, with x, y, and z components:

rod.color.x = 0.4 rod.color.y = 0.7 rod.color.z = 0.8

Here is a full list of attributes for a cylinder. All 3D objects have all of these attributes, other than arrow and curve:

pos Position: the center of one end of the cylinder; default = vec(0,0,0).

size The length, width, and height of the cylinder; default = vec(1,1,1).

axis The axis points in the direction of the length of the cylinder, default = vec(1,0,0). Only the direction of the axis is meaningful, not its magnitude. The length of the cylinder is size.x, not the magnitude of the axis. Changing axis may change up, to ensure that axis and up are always perpendicular to each other.

up Which side of the cylinder is "up"; this has only a subtle effect on the 3D appearance of a cylinder unless the cross section is not circular or a texture is applied; default = vec(0,1,0). Changing up may change axis, to ensure that axis and up are always perpendicular to each other.

color Color of object, as a red-green-blue (RGB) triple: vec(1,0,0) is the same as color.red, default = vec(1,1,1), which is color.white.

opacity Opacity of object, default = 1 (fully opaque); 0 is completely transparent.

shininess 0 to 1, default 0.6; governs the amount of specular reflections.

emissive If True, local and distant lights are ignored, and the brightness is governed by the object's own color. An example of its use is to put an emissive sphere at the location of a local_light, which looks like a glowing lamp. The default for emissive is False. (For JavaScript, specify true or false instead of True or False.)

visible If false, object is not displayed; e.g. rod.visible = False Use rod.visible = True to make the object visible again. (For JavaScript, specify true or false instead of True or False.)

texture You can specify a texture to apply to the object's surface. See the Textures documentation.

End vs center: The pos attribute for arrow, cone, cylinder, helix, and pyramid corresponds to one end of the object, whereas for a box, ring, or sphere it corresponds to the center of the object.

ring

The following statement creates a ring centered at location vec(3,0,1), with its axis pointing in the vec(0,1,0) direction, and with a thickness in that direction of 0.2 and a diameter of 1:

ring( pos=vec(3,0,1), axis=vec(0,1,0), size=vec(0.2,1,1) )

Here is a full list of attributes for a ring. All 3D objects have all of these attributes, other than arrow (which has axis_and_length instead of axis):

pos Position: the center of one end of the ring; default = vec(0,0,0).

size The length, width, and height of the ring; default = vec(0.1,1,1), where size.x is the thickness of the ring.

axis The axis points in the direction of the length of the ring, default = vec(1,0,0). Only the direction of the axis is meaningful, not its magnitude. The length of the ring is size.x, not the magnitude of the axis.

color Color of object, as a red-green-blue (RGB) triple: vec(1,0,0) is the same as color.red, default = vec(1,1,1), which is color.white.

up Which side of the ring is "up".

visible If False, object is not displayed; e.g. myring.visible = False Use myring.visible = True to make the object visible again.

End vs center: The pos attribute for arrow, cone, cylinder, helix, and pyramid corresponds to one end of the object, whereas for a box, ring, or sphere it corresponds to the center of the object.

To display a trail or an arrow along the path of a moving object, see Attach a trail or arrow.

No texture or opacity: Currently rings, like curve, cannot be transparent, it is not possible to apply a texture, and it cannot be part of a compound object.

helix

The following statement will display a helix that is parallel to the x axis (the default axis direction), with length 5 and diameter 1:

var spring = helix( pos=vec(0,2,1), size=vec(5,1,1) )

The attribute thickness is the diameter of the cross section of the curve used to draw the helix; default is diameter/10.

There is also a coils attribute, which is the number of coils; the default is 5.

Here is the rest of the attributes for a helix. All 3D objects have all of these attributes, other than arrow (which has axis_and_length instead of axis):

pos Position: the center of one end of the helix; default = vec(0,0,0).

size The length, width, and height of the helix; default = vec(1,1,1). Changing the size does not change the thickness.

axis The axis points in the direction of the length of the helix, default = vec(1,0,0). Only the direction of the axis is meaningful, not its magnitude. The length of the helix is size.x, not the magnitude of the axis.

color Color of object, as a red-green-blue (RGB) triple: vec(1,0,0) is the same as color.red, default = vec(1,1,1), which is color.white.

up Which side of the helix is "up"; default = vec(0,1,0).

visible If False, object is not displayed; e.g. spring.visible = False Use spring.visible = True to make the object visible again.

End vs center: The pos attribute for arrow, cone, cylinder, helix, and pyramid corresponds to one end of the object, whereas for a box, ring, or sphere it corresponds to the center of the object.

No texture or opacity: Currently helixes, like curves, cannot be transparent, it is not possible to apply a texture, and it cannot be part of a compound object.



Clone this wiki locally