OpticalRayTracer #version# Help Page

A virtual lens design workshop.

Copyright © 2009, Paul LutusMessage Page

OpticalRayTracer is released under the GPL: http://www.gnu.org/licenses/gpl.html

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

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

NOTE: 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 Lens Types | Tutorial | Lens Control Panel
Dispersion Experiment | Using the Mouse and Keyboard | Importing and Exporting Data
System Considerations | Algorithm Description | Snell's Law
Dispersion Computation | Configuration | Conclusion
User support

Introduction

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 #userdir# 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 #userdir# 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:

Notice that panning the display itself requires you to click outside any lenses, then drag. To move a lens, click directly on the lens you want to move and drag it.

The default setup shows six light beams passing from right to left, through the 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 (click on a lens and drag it) and observe the changing beam paths.

Notice that, when you click a lens, a selection frame appears and the blue control panel below the display becomes enabled. 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 the 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 are 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 shaped 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 quite a bad lens. Its only advantage is that it is easy to make — everything after that is downhill.

Supported Lens Types

OpticalRayTracer will happily 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.

Tutorial

I want you to perform your own experiments, but 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. If you drag it 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 and 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. So if you can mentally picture two overlapping spheres, you will be able to predict what will result from your typing particular numbers into OpticalRayTracer. For example, to create a lens with one side convex and one side flat, you might choose to enter a very, very large radius for one side. Like this:

At this point, you may wonder why an entry defining the left-hand sphere had its effect on the right hand side of our lens. The answer is that the imaginary spheres are overlapping, and the right-hand part of our lens is defined by an imaginary sphere centered to the left of the lens. I mention this now to avoid confusion later on. The circle that defines the right-hand side of the overlapped region (e.g. the lens) is centered to the left of the overlap area.

Now for something a tiny bit more advanced.

To discover how accurate this focus is, simply center the focal point in the display and zoom in on it. Eventually you will get to a point where you can see some small imperfections in the focus. (This will become visible at a zoom factor of about 15.) In any case, this class of lens design is very advanced and (no surprise) very difficult to manufacture.

Lens Control Panel

Play with some of the settings in the lens control panel (the blue panel below the graphic display) 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 window 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 (with an IOR of 1.0). If you set this value to 1.0, the lens will no longer deflect the light beams, because it has in essence been defined as empty space.

Different glasses have different indices of refraction, a property that is taken advantage of in advanced lens designs. Here's an example design that exploits this fact, and introduces the topic of dispersion.

"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

To set up for this experiment, delete any existing lenses, then create a lens with these settings (or you can copy the lens definition from this page — see below):

Click here to copy this lens definition onto the clipboard, then paste it into the experimental setup using the display context menu (use "Paste: defined position").

Now switch to the "Configuration" panel and enter 2 for "Beam Count". Now return to the ray trace display to see the effect.

If all your settings are correct, and if the lens has really been positioned at x = 0, y = 0, the two beams should converge at about x = 2.53.

Now we'll add a dispersion calculation. Go to the "Configuration" panel and enter 8 for "Dispersion beam count." 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.

Moving right along, create a second lens (or copy it from this page — see below) with these properties:

Click here to copy this lens definition onto the clipboard, then paste it into the experimental setup using the display context menu (use "Paste: defined position").

If all the settings on both lenses are correct and all the other required settings have been made correctly, you will see all the colored beams converge at about x = 11.63, with very little color dispersion.

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 a particular separation.

Using the Mouse and Keyboard

While playing with lens configurations, you may sometimes notice it is difficult to select a particular lens, because the lenses are very close together and their colored border-boxes overlap. In a case like this, just click again — the program will cycle through the lenses that could be selected at the location of your click.

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

The following actions apply to the graphic display panels:

Action
Result
Mouse wheel Zoom in/out
Mouse drag Pan image vertically or horizontally

Most of the above mouse and keyboard actions can be changed with the following modifier keystrokes:

Action
Result
Above actions accompanied by Shift key Amount of change divided by 10
Above actions accompanied by Alt key Amount of change divided by 100
Above actions accompanied by 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.

You can also make a copy of the entire experimental setup — lenses, colors, zoom levels, everything — by clicking the "Copy" button on the toolbar below the graphic display (not the context-menu copy button). This places a full description of OpticalRayTracer's present state onto the system clipboard. And this exact state can be reëstablished by pasting such a description using the toolbar "Paste" button. This means you can send a full, exact description of your experimental setup to a friend, including lenses, zoom settings, everything. Or you can save your experiments for later use by pasting them into a plain-text file.

To make a graphic copy of the workspace display, click the "Copy Workspace" button, then open a graphic image editor and choose "Paste".
System Considerations

If the behavior of your copy of OpticalRayTracer doesn't correspond in every way to 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 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 "Number of Dispersion Beams" to zero.

OpticalRayTracer uses several mathematical methods to produce its results (and you got a copy of all the source files when you downloaded the program, so you can examine the methods in detail).

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 x dimension, then determines which intersection is next (to the right) along the beam's path.

At this point OpticalRayTracer has determined a point of collision between a tracing ray and a lens. 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)

Where:

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 angle must decrease. And conversely, a beam emerging from glass to air will show an increase in its angle of deflection. Also, it can be seen that an incident angle of zero will not be deflected — it will remain zero.

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

a2 = arcsin(n1 sin(a1) / n2)

Here is a practical example:

Dispersion Computation

The computation for dispersion follows along similar lines, but with an empirical equation less grounded in physically simple principles (and original with the author). The dispersion equation changes the index of refraction based on the wavelength of the light beam:

ior2 = ior + ((dp - w) * 500000.0) / (abbe * dp * w^2)

Where:

Abbe's Number is arrived at in this way:

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

Where:

The Abbe numbers for various media are arrived at in laboratory experiments. My equation simply reverses the relationship between the number and its effects, within an accuracy of about 1%.

Configuration

Here is an explanation of the controls in the Configuration panel:

Remember 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, simply set this value to zero.

Conclusion

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.

There is a great deal of excellent, detailed information about optics on the Web, both theoretical and practical. Google for "optics," "ray tracing" and related topics.

User support

There is a more detailed technical description of OpticalRayTracer and optical mathematics in general located at http://arachnoid.com/OpticalRayTracer/documentation.html

Because OpticalRayTracer is released under the GPL (but please visit http://www.arachnoid.com/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 http://www.arachnoid.com/messages.