OpticalRayTracer 9.4 Help Page

A virtual lens/mirror design workshop.

Copyright © 2014, Paul LutusMessage Page

OpticalRayTracer is released under the GPL.

Visit the OpticalRayTracer Home Page for more information and to be sure you have the latest version.

For formatting reasons, users may want to temporarily make the OpticalRayTracer program frame larger to properly read these instructions.

Users may prefer to search this document using the search feature at the bottom of this frame.

Introduction | First Steps | The Basics of Lenses
Supported Optical Elements | Mirrors | Absorbers
Tutorial | Lens Control Panel | Dispersion Experiment
Using the Mouse and Keyboard | Importing and Exporting Data | System Considerations
Algorithm Description | Snell's Law | Dispersion Computation
Design Options | Configuration Options | Command-line Interface
Common Problems | Conclusion | User support


OpticalRayTracer is a very portable Java program meant to analyze and model systems of lenses. It accurately models the physics of lenses, including the effect known as dispersion. But perhaps the most remarkable thing about OpticalRayTracer is that it updates and displays complex ray tracing paths in real time, as the user moves virtual lenses around on a virtual optical bench. This allows the user to very quickly learn the behavior of a system of lenses, compare, experiment, and just play.

OpticalRayTracer places its configuration file in a directory it creates, so your settings and choices are preserved. This directory is located at (user directory) on your machine, and it contains a configuration file named "OpticalRayTracer.ini" containing quite a lot of detailed information unique to your use of the program.

I mention this because:

This file contains a very detailed snapshot of your last session with OpticalRayTracer, with lens specifications and positions, suitable for exporting into other environments (the same information can be gotten from the copy-configuration button on the Design toolbar). To create this file and its picture of your optical setup, simply exit OpticalRayTracer, navigate to (user directory) and read the file.

First Steps

Since you are reading this, you have successfully installed OpticalRayTracer, and are ready to try some experiments.

When it is first run, the program will automatically create two common lenses for you, a double-convex lens and a double-concave lens. Click the "Design" tab and you will most likely see these two default lenses. If you do not see any lenses, click the "Erase & Reset" button.

Navigation within the ray trace display is as intuitive as I could make it:

The default setup shows four light beams passing from left to right, through two example lenses. The mathematical methods used in this program are efficient enough that (with a moderately fast computer) you can move the lenses around and see how this changes the beam paths — in real time. Try it — move the lenses around (hold the Shift or Ctrl key down, click a lens and drag it) and observe the changing beam paths.

Notice that, when you click a lens, the lens changes color and the design control panel below the display becomes active. This panel allows you to change the characteristics of your lenses — focal length, size, curvature, and many other things. Feel free to experiment with this panel's settings — see how they change the appearance of the lenses and light beams.

It will help to know a little about optics to understand what you are seeing. If you already know the basics, you can safely skip the next few lines.

The Basics of Lenses

Very basically, a lens is a simple way to bend light beams. Imagine a row of soldiers marching, side by side. To change the direction they're marching, it is necessary to make some of the soldiers slow down temporarily. Now let this picture of marching soldiers help you imagine a light wave, traveling through space. Just as with the soldiers, to make the wave change direction, you have to think of a way to make part of the wave slow down. That is what a lens does — it selectively slows parts of a light wave.

A convex lens is thicker in the middle than at the edges, and, as it turns out, light takes longer to pass through glass than through air. What this means is that the light that passes through the middle, thickest part of the lens, is slowed down compared to the light that passes through the thinner parts near the edges of the lens. This has the effect of shaping the wavefront that emerges from the lens — the middle of the emerging wavefront is delayed, and the wave's overall shape is concave, with a depression in the middle. The wavefront has been reshaped to converge on a point some distance away from the lens, and that is exactly what it does.

Such a lens could be used to focus parts of a real-world scene onto a piece of film or an image sensor. The ability of a lens to focus accurately is a central issue in lens design and, as it turns out, the most common kind of lens, with a spherical shape, is actually not a very good design. Its only advantage is that it's easy to make — everything after that is downhill.

Supported Optical Elements

OpticalRayTracer supports a variety of optical elements:

OpticalRayTracer will let you play with various kinds of simple, spherical lenses in its virtual playground, but it also includes some mathematical methods that allow you to fashion some rather extraordinarily good lenses called "hyperboloids," famous for their accuracy ... and their difficulty of manufacture. These kinds of lenses are so expensive that it is simpler — and much less expensive — to build and test such lenses using a program like OpticalRayTracer than to try to purchase real-world examples. This is an answer to the oft-heard objection to too much gazing at glowing computer screens. We are excused, just this once, by pointing out that building an exotic lens on a computer screen, changing its characteristics, experimenting, would cost thousands of dollars if rendered in glass instead of computer code, and would require months of fabrication time as well.


Recent OpticalRayTracer versions allow the creation of mirrors — more specifically, lenses that behave like mirrors. The user creates a suitable flat or curved surface and clicks the Design tab's "Reflector" checkbox. This feature allows diverting light beams out of the normal optical path, as well as the creation of concave and convex mirrors, such as are used in astronomical telescopes.

To produce a generic mirror, click the "New mirror/absorber" toolbar button. Now you may change the mirror's characteristics, just as for a lens. Remember that, if it has a curved surface, a mirror can act as a lens. To tilt the mirror in the optical path, choose an appropriate value for the angle entry. By creating two mirrors, one concave reflector as an objective lens and a smaller diagonal mirror, it's possible to build a virtual Newtonian telescope and analyze the beam paths.

If you encouter a case where a mirror won't reflect light, try increasing the mirror's thickness. OpticalRayTracer tries to avoid drawing the same object repeatedly, and it does this by measuring very small distances, and skipping objects that it thinks it may already have drawn. If your mirror is thin enough, OpticalRayTracer may not "see" it. This is true in nature too, but for a different reason.


An absorber is a third kind of supported optical object, and is a variation on mirrors. It's used in cases where the user wants to eliminate one or more rays from the calculation. To create an absorber, just create a mirror as explained above, then select "Absorb" from the Design tab's option checklist. All rays that intersect with an absorber are terminated and play no further part in the optical calculation.


Figure 1: Lens defined by overlapping spheres

I want you to perform your own experiments, but first, here's a simple tutorial to get you started. Using the default lenses automatically created when you run OpticalRayTracer the first time, temporarily drag the concave lens (the lens at the right) out of the optical path (remember: to move a lens, press Shift or Ctrl as you drag your mouse cursor). If you drag the lens a small distance, it will jump back into place, realigning itself with the beam line (ordinarily this automatic feature is a good thing). So drag it a good distance up or down, temporarily removing it from the beam path. Now notice the double-convex lens at the left. If you click this lens, then read its characteristics in the control panel below it, you will discover that it has a "lens radius" of 2 units and a "sphere radius" of 6 units. What do these terms mean?

As it turns out, the mathematics behind lenses relies very much on this idea of overlapping spheres, hyperboloids, and some other useful shapes (as fully explained here). So if you can mentally picture two overlapping spheres as shown in Figure 1, you should be able to predict the result of entering particular numbers into OpticalRayTracer. For example, to create a lens with one side convex and one side flat, you may want to proceed as follows:

Left-Right Reversal: At this point, you may wonder why an entry defining the left-hand sphere's radius had its effect on the right hand side of our lens. The answer is that, as explained above, a lens is defined by two overlapping spheres (see Figure 1 above), and the right-hand surface of our lens is defined by a sphere centered to the left of the lens, and vice versa.

Now for something a tiny bit more advanced.

Hyperbolic-curvature lenses are an example of advanced optics and were once very difficult to manufacture. As computers come to play a greater role in optical manufacturing, these high-performance lenses should become more common.

Lens Control Panel

Play with some of the settings in the lens control panel (the panel located on the "Design" tab) to see what effect they have. Notice that you can reposition a lens exactly by entering its x and y coordinates — this is a way to get around the fact that it is difficult to position a lens precisely using the mouse.

Notice the entry marked "IOR". This means "Index of Refraction," a value representing the ratio of the speed of light through the lens in question to a vacuum (which has an IOR of 1.0). If you set this value to 1.0, the lens will no longer deflect the light beams, because the lens has in essence been redefined as empty space.

Different glasses have different indices of refraction, a property we can take advantage of in advanced lens designs. Here's an example design that displays the effect called dispersion using differently colored light beams.

"Dispersion" is a property of glass in which light beams of different wavelengths travel at different speeds. For example, a blue beam takes longer to move through a lens than a red beam. This causes the two colors (wavelengths) of light to focus at two different places, a trait regarded as a bad thing, called "chromatic aberration."

Dispersion Experiment

This is an optional digression for the curious. To set up for this experiment:

Now we'll add a dispersion calculation.

When you return to the ray trace display, you should see an array of colored beams near the lens focal point. In this mode, OpticalRayTracer creates colored beams, each of which has an associated wavelength. During the calculation of the ray paths, the lens dispersion property is taken into account and, just as in the real world, the lens cannot focus all these wavelengths onto a single point.

This, by the way, is a classic solution to the problem of chromatic aberration, using varieties of glass called "crown" and "flint," with differing properties that are exploited to make the light beams converge.

By changing the spacing between the two lenses, you will quickly see that this setting is very critical to the outcome, which is why in the real world, such pairs of lenses are often glued together or placed in a lens cell with a spacer of some durable material to maintain the required separation.

Using the Mouse and Keyboard

Graphic display

While playing with lens configurations, you may sometimes notice it is difficult to select a particular lens because the lenses are close together and their selection territories overlap. In a case like this, just click the display repeatedly — the program will cycle through the lenses that could be selected at the location of your click. You also have the option of cycling among the objects by clicking the "Cycle through" toolbar button.

The graphic display pays attention to the mouse's various buttons and wheel, plus certain keyboard keys. Here's a list of mouse-related inputs and actions:

Action Result
Click once Select an object near the mouse cursor
Click more than once Cycle through objects near mouse cursor
Double-click List properties of nearest line
Drag mouse Pan display
Drag mouse with Shift or Ctrl keys Move selected object
Mouse wheel Zoom display
Mouse wheel with Shift key Rotate selected object
Mouse wheel with Ctrl key Resize selected object
Most of the above actions with Alt key Slower change

Here is a list of keyboard-related inputs and actions:

Action Result
Tab Move forward through all program controls
Shift|Tab Move in reverse through all program controls
Alt-D Design tab
Alt-C Configure tab
Alt-T Table tab
Alt-H Help tab
F1 Concise help dialog
M or context menu key Context [M]enu
Enter (over object) Select object under cursor
Enter (outside objects) List properties of nearest line
L [L]ist properties of nearest line (even inside objects)
O Cycle through [O]bject selections
U [U]nselect all objects
Up/down/left/right Arrow keys Pan display
Ctrl|Arrow or Shift|Arrow keys Move selected object
+/- or Home/End Zoom display in/out
Ctrl|(+/-) or Ctrl|(Home/End) Resize selected object
Shift|(+/-) orShift|(Home/End) Rotate selected object
Most of the above actions with Alt key Slower change

Text Entry Fields

Virtually all OpticalRayTracer's text entry fields can be changed by placing the mouse cursor over them and spinning the mouse wheel. If the rate of change is too fast, hold down the shift key while spinning the mouse. If that rate is also too fast, hold down the shift and Alt keys together while spinning the mouse.

These actions can be gotten with some special keyboard keys also — the up and down arrow keys will change the value by +1 and -1 respectively, with smaller changes if the shift and/or Alt keys are held down, just as with the mouse wheel example above. Here is a full list of these special controls:

Action Result
Mouse wheel Value increased/decreased by 1
up/down arrow keys Value increased/decreased by 1
Page Up/Page Down keys Value increased/decreased by 10
Home/End keys Value increased/decreased by 100
Esc key Change sign (+-) of associated entry

The text-field mouse-wheel and keyboard actions listed above can be modified by these accompanying keystrokes:

Action Result
Wheel/keyboard with Shift key Amount of change divided by 10
Wheel/keyboard with Alt key Amount of change divided by 100
Wheel/keyboard with both Shift and Alt keys Amount of change divided by 1000
Importing and Exporting Data

OpticalRayTracer has a number of methods for writing and reading data to/from the world at large, primarily by way of the system clipboard.

System Considerations

Remember that OpticalRayTracer is a Java application, which means it needs a current Java runtime engine. If the behavior of your copy of OpticalRayTracer doesn't correspond with the description provided here, it probably means your installed version of Java is not up-to-date. To remedy this, visit http://java.com to update your Java installation (Java is free).

Remember also that the total number of beams traced is equal to the number of tracing beams (selected in the "Configuration" panel) multiplied by the number of dispersion beams, e. g. there is a dispersion beam for each chosen wavelength, times each tracing beam. So if the display slows down, this could easily be the reason — too many beams selected. To prevent calculation of dispersion, simply set "Dispersion Beam Count" to zero.

Algorithm Description
(For a more complete presentation of this topic, visit the OpticalRayTracer technical discussion page.)

OpticalRayTracer first calculates the location of any intersections between tracing beams and spheres or hyperboloids (our lenses). The collision detection mathematics is rather involved and won't be described in any detail here.

Having acquired a list of all possible points of collision for a particular beam, OpticalRayTracer sorts the list of results along the current direction, then determines which intersection is closest along the beam's path.

At this point OpticalRayTracer has determined a point of collision between a tracing ray and a lens or mirror. The ray and the lens collision point each have a characteristic angle, which is used in the next computation.

Snell's Law

"Snell's Law" is a classic optical relationship that, given arguments for incidence angle between two media and indices of refraction for the two media, determines the deflection angle. Expressed in classic form, Snell's Law is:

n1 sin(a1) = n2 sin(a2)


The astute reader will notice that, in passing from a medium like air with an IOR near 1.0, to a lens with an IOR of 1.5 for example, the light beam's angle with repect to the surface normal must decrease. And conversely, a beam emerging from glass to air will show an increase in its angle of deflection. It can also be seen that an incident relative angle of zero will not be deflected — it will remain zero.

In computing refraction, OpticalRayTracer uses this restatement of the classic Snell's Law equation:

a2 = sin-1(sin(a1) n1 / n2)

Here's a practical example:

The above example (in which n1 < n2) causes the beam to deflect toward the normal line (the line perpendicular to the optical surface). In the reverse case (n1 > n2), the ray is deflected away from the normal line. In some cases this may exceed a "critical angle" such that the beam is deflected back into the refracting medium. This is called "total internal reflection", and in such a case OpticalRayTracer imitates nature by reflecting the beam back into the medium using a classic mirror equation. This design choice increases the correspondence between OpticalRayTracer's virtual world and reality.

Note: OpticalRayTracer provides very reliable Snell's Law results, as accurate as the entered lens measurements. The values listed in the OpticalRaytracer data table can be relied on for optical analysis purposes within floating-point processing accuracy limitations.

Dispersion Computation

The computation for dispersion follows along similar lines, but this task is less open to analysis from physically simple principles. My empirical dispersion equation changes the index of refraction based on the wavelength of the light beam:

ior' = ior + ((dp - w) 5x105) / (abbe dp w2)


Abbe's Number is arrived at in this way:

abbe = (nd-1)/(nf-nc)


Abbe numbers for various media are arrived at empirically in laboratory experiments. My equation reverses the relationship between the number and its effects, giving a dispersion-modified IOR with an accuracy of about 5% for many common glasses.

Note: OpticalRayTracer provides approximate dispersion results, suitable for graphic display purposes but not precise (as explained here). If very accurate results are required, a formal calculation is recommended.

Design Options

Here is a list of the Design tab options and their meanings.

Configuration Options

Here is an explanation of the controls in the Configure tab:

Remember that all the above values are reset by the Erase & Reset button. If you make settings that cause problems, simply reset the program to its default values.

Remember also that the total number of ray trace computations is equal to the number of tracing beams multiplied by the number of dispersion beams, such that choosing 8 tracing beams and 8 dispersion beams results in 64 traces, fine for a fast computer, but not so great for a slower machine. To prevent the generation of dispersion beams and their associated computation overhead, set this value to zero.

All the configuration values, along with a full description of the lenses you create, are preserved between sessions in a file located at (user directory)/OpticalRayTracer.ini on this system, and the same information can be copied onto the system clipboard with the toolbar "Copy Configuration" button.

Command-line Interface

To facilitate design automation and testing procedures, OpticalRayTracer accepts a small number of command-line arguments:

This is an advanced feature that most OpticalRayTracer users won't need. Here is an example that passes command-line arguments and streams to OpticalRayTracer from a shell session:

$ java -jar OpticalRayTracer.jar -r -t -q < test_configuration.txt > output_table.txt

The above example causes OpticalRayTracer to (-r) read a user-defined test configuration from the standard input stream, (-t) emit a tab-separated-value table to the standard output stream, and (-q) quit. The user's command-line parameters provide the content of a configuration file and saves the resulting table in another file.

An example use might be to repeatedly change one or more optical configuration parameters in a user-defined configuration file (which must be a complete configuration such as may be acquired from the OpticalRayTracer "Copy full configuration" button on the Design tab), then produce a table of results for analysis of the changes.

Unfortunately, this feature isn't particularly fast. Because OpticalRayTracer is a Java program it must load the Java virtual machine before it can run, also some commands may require the graphical user interface to be displayed, consequently each invocation of an example like the above may require two or more seconds to run, even though (for this example) the program quits immediately after generating the table.

Common Problems

The OpticalRayTracer Home Page is located at http://www.arachnoid.com/OpticalRayTracer, where additional documentation and other resources are located. Be sure to visit to make sure you have the latest version of OpticalRayTracer.

User support

Click here for a more detailed technical description of OpticalRayTracer and optical mathematics in general.

Because OpticalRayTracer is released under the GPL (but please visit Careware anyway), there is no user support. This help file plus the sort of knowledge available in optical textbooks and online should be sufficient to help the user make it productive.

If you detect a bug in OpticalRayTracer, please report it at arachnoid.com Messages.