Efield addObject Method

EField allows the creation of point charges as well as geometric shapes using the add object method:

addObject(String name, String attributes)

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 be added to either applet using the following JavaScript statement:

id=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 the EField Physlet.  Consult the online documentation for information about other Physlets.  DataGraph, for example supports the addObject method for geometric shapes such as circles, boxes, and shells.  OpticsBench 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 x position of the base in world units
y- double
y position of the base in world units.
h- string horizontal component as a function of t, x, y, vx, vy, ax, and ay.
v- string vertical component as a function of t, x, y, vx, vy, ax, and ay.
s- int the size of the head in pixels

box
a box is a hollow rectangle.

x- double x position of the center in world units
y- double y position of the center in world units
h- int height in pixels
w- int width in pixels
m-double the mass

caption
text that is centered near the top of the screen.

x- double x position of the center in world units
y- double y position of the center in world units.
text- string
text of the caption
calc- string
A function of t to be evaluated at every time step.  The value of the function is displayed to the right of the text.

charge

x- double x position of the center in world units
y- double y position of the center in world units.
q- double object's charge.
r- int radius in pixels
m-double
the mass

circle

x- double x position of the center in world units
y- double y position of the center in world units.
r- int radius in pixels
m-double the mass

connectorline
a straight line connection two objects.

id1- int first object identifier.
id2- int
second object identifier.
See also: addConnectorSpring(int,int) in the online documentation.  This method is easier to use if the ids are stored as integers.

connectorspring
a spring connection two objects.

id1- int first object identifier.
id2- int
second object identifier.
See also: addConnectorLine(int,int) in the online documentation.  This method is easier to use if the ids are stored as integers.

cursor
a circle with cross hairs.

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

image
a gif image.  The coordinates are the coordinates of the upper left hand corner.

x- double x position of the left side in world units
y- double y position of the top in world units
file- string name of the gif file.  The image should be in located in the same directory as the jar file for the applet.
m-double the mass

line

 

 

x- double x position of the base in world units
y- double y position of the base in world units.
h- string horizontal component as a function of t, x, y, vx, vy, ax, and ay.
v- string vertical component as a function of t, x, y, vx, vy, ax, and ay.

rectangle

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

relshape
draws an arbitrary shape by connect-the-dots.  The shape is specified by passing the relative pixel positions of the dots starting at x and y.

x- double x position of the center in world units
y- double y position of the center in world units. n- int number of vertices in the polygon.
hStr- string
A comma separated list of the x postions of the relative vertices in pixel units. vStr- string A comma separated list of the y postions of the relative vertices in pixel units.
m-double the mass

shell
a circle with a hollow center

x- double x position of the center in world units
y- double y position of the center in world units
r- int
radius in pixels
m-double the mass

testcharge
a charge that is free to move under the action of fixed charges and an external potential.

x- double x position of the center in world units
y- double
y position of the center in world units
vx- double x velocity in world units
vy- double y velocity in world units
q- double object's charge
r- int radius in pixels
m-double the mass

text
a fixed text string followed by an optional calculation.

x- double x position of the left side of the text in world units
y- double
y position of the top of the text in world units
text- string static text.
calc- string A function of t, x, y, vx, vy, ax, and ay that is evaluated at every time step.  The value of the function is displayed to the right of the static text.]
Note:  Use the setFormat method to change the decimal format used to output the calculation.