BField AddObject Method

BField allows the creation of geometric shapes as well as coils and straight wires using the add object method:

addObject(String name, String attributes)

Objects usually, but not always, have an on-screen representation.  The first argument is the name of the object to be added, and the second is a comma-delimited list of parameters.  A circle can now be added to either applet using the following JavaScript statement:

document.physletname.addObject("circle", "x=0,y=-1.0,r=10");.

The addObject method is very forgiving since not all parameters need to be specified.  Default values are overridden only if the parameter appears in the list.  Incorrect and unsupported parameters do not affect the applet and are ignored.

The table below lists the name and the associated parameters for version 4 of the BField Physlet.   Consult the online documentation for information about other Physlets.  OpticsBench, for example, supports the addObject method for lenses, mirrors, and light sources.

Name  Attributes
arrow

Arrows are often animation slaves of other objects.  They can represent almost any vector since the h and v components can be functions of the variables.

x- double position of the base in world units
y- double position of the base in world units.
h- string horizontal component
v- string vertical component
s -int size of arrowhead

box

a hollow rectangle.

 

x- double position of the base in world units
y- double position of the base in world units.
h- int height in pixels
w- int width in pixels
s- int thickness of the box

caption

Text.

x- double position of the base in world units
y- double position of the base in world units.
txt- string text

constraint

a constraint on dragged objects.

 

xmin- double minimum x
xmax- double maximum x
ymin- double minimum y
ymax- double maximum y
path- string the constraining path can either be a "rectangle" or an "ellipse."

circle

a filled circle.

x- double position of the base in world units
y- double position of the base in world units.
r- int radius in pixels

coil

a current carrying coil.

 

x- double position of the base in world units
y- double position of the base in world units.
i- double current
r- int coil radius
s- int size

compass

a compass.

x- double position of the base in world units
y- double position of the base in world units.
r- double radius

cursor

A circle with crosshairs

x- double position of the base in world units
y- double position of the base in world units.
r- int radius in pixels

field

shows the vector field.

No attributes.  A placeholder for the vector field.  Vectors will be displayed if this value exits.
Use this parameter to order the z-level of the drawing.
 

image

a gif image

x- double position of the base in world units
y- double position of the base in world units.
file- string image file relative to code base

rectangle

a filled rectangle

 

x- double position of the base in world units
y- double position of the base in world units.
h- int height in pixels
w- int width in pixels

shell

A hollow circle.

 

x- double position of the base in world units
y- double position of the base in world units.
r- int radius in pixels

text
message with an optional calculation.

 

x- double position of the base in world units
y- double position of the base in world units.
txt- string message
calc- string an analytic function that is appended to the message.

Text objects are often slaved to other objects. If a text object is slaved to an object, it takes on the properties of that object. A BField slaved text object can evaluate a function of t, x, y, bx, by, i, curl, and path. The curl of the field is evaluated at the position, (x, y). The path is the line integral evaluated along the perimeter of a shell or a box object.

Use the setFormat method described to change the decimal format used to output the calculation.

wire

A current carrying wire.

 

x- double position of the base in world units
y- double position of the base in world units.
i- double current
s- double on-screen size