Optics AddObject Method

Almost all Physlets support one or more add methods designed to create an object and add it to the applet.  The addObject method with the following signature

addObject(String name, String attributes)

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

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.

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.

lens

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

f- double the focal length 

Example:

addObject("lens","x=1, f=-2");

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");

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.

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.

slope- double the slope of the rays.  -1<angle<1.

point  a beam of parallel light rays

inc- double the slope increment between rays.

slope- double the slope of the rays.  -1<angle<1.

Examples:

addObject("source","x=1, point, inc=0.1, slope=1.0");

addObject("source","x=1, infinite, s=30, slope=0.5");

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 in 17.3.1 to change the decimal format used to output the calculation.