OpticsApplet addObject Method

OpticsApplet supports the addObject method with the following signature

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 lens can be added using the following JavaScript statement:

id=document.physletname.addObject("lens", "x=1,f=-2");.

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.

Name

Attributes

aperture
restricts the propagation of light rays

x- double x position of the center in world units
opening- double the opening size as a fraction from 0 to 1.0.

beamstop
restricts the propagation of light rays

x- double x position of the center in world units
bottom- double position of bottom as a fraction from 0 to 1.0.
top- double position of top as a fraction from 0 to 1.0.

bench
a placeholder for the optic elements

No attributes.  Use this parameter to determine the drawing order for the optic elements relative to the geometric objects.

box

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
s-int thickness of the box

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

constraint

xmin- double The minimum x value.
xmax- double The maximum x value.
ymin- double The minimum y value.
ymax- double
The maximum y value.

A constraint, by itself, will have no effect.  It must be attached to a dragable object using the setConstriant method.

dielectric

x- double x position of the center in world units.
dn- double the change in index of refraction.
r- double radius or curvature of the index change

Models and change in index of refraction using Snell's law.  Aberrations are observed. See also refraction.

image 
a gif image

x- double x position of the center in world units
y- double y position of the center in world units.
gif- string a gif image
file- string same as gif

OpticsApplet will search for images in the code-base directory.  This is the directory containing the jar files.
You may use subdirectories relative to the code-base to organize images.
Example: addObject("image","file=optics/eye.gif");

lens

x- double x position of the center in world units.
f- double the focal length  
Example:  addObject("lens","x=1, f=-2");

matrix
transformation functions

x- double x position in world units.
height- double
the height transformation:  H(h,a)
angle- double the angle transformation: A(h,a)
Transformation functions are analytic functions of height and angle, h and a, respectively.

mirror

x- double x position of the center in world units.
f- double
the focal length
spherical  include spherical aberrations
Example: addObject("mirror","x=1, f=-2, spherical");

protractor
a protractor for measuring angles

x- double x position of the vertex in world units
y- double
y position of the vertex in world units.
s- int base size in pixel
theta- double vertex interior angle
theta0- double vertex base angle
fixedbase-
fixes the base angle
fixedsize-
fixes the length of the arm

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

refraction

x- double x position of the center in world units.
dn- double the change in index of refraction.
r- double
radius or curvature of the index change

Models and change in index of refraction using the small angle approximation. See also dielectric.

screen

x- double x position of the center in world units

shell

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

source

x- double x position of the center in world units.
y- double y position of the center in world units.

Choose either infinite or point selectors.  The three principle rays will be drawn if neither selector is specified.

 infinite  a beam of parallel light rays
   
s- int the size of the beam in pixels.
   
nrays- int the number of rays

point  a beam of parallel light rays
    slope- double the slope of the rays.  -1<angle<1
    inc- double the slope increment between rays.

Examples:
addObject("source","x=1, point, inc=0.1, slope=1.0":
addObject("source","x=1, infinite, s=30, nrays=20");

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 An analytic function to be evaluated.  The calculation is displayed to the right of the static text.

Text objects are often slaved to other objects.  If a text object is slaved to a wire, it takes on the properties of that wire and can evaluate a function of t, x, y, flux, and v. Note:  Use the setFormat method described to change the decimal format used to output the calculation.