A virtual lens design workshop.
Copyright © 2009, Paul Lutus — Message 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
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:
- if you want to analyze or process the results of your work with OpticalRayTracer, the file #userdir#/OpticalRayTracer.ini contains a lot of numeric information in plain-text form, and
- if you have gotten into difficulty and just want to start over, simply delete this file and run OpticalRayTracer again.
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.
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:
- To zoom in and out, use your mouse wheel.
- To pan around the display, just click the display and drag using the mouse.
- To move a lens from one place to another in the display, simply click the lens and drag 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 display has two dimensions, "x" and "y". "x" is the horizontal dimension, and positive values for x move to the right. "y" is the vertical dimension, and positive values for y move up.
- To move large distances, first zoom out, then pan, then zoom in again. This saves time compared to clicking and dragging multiple times.
- To determine the position of something in the display, for example the location fo a focal point, simply point the mouse cursor at the point of interest and read the mouse x and y positon on the status bar.
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.
- If you make a change you don't like, simply press the
"Undo" button to change back.
- To change the settings for a lens, first click the lens, then use the lens control panel to make the changes you want.
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.
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.
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.
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?
- "Lens Radius" refers to the distance from the center to the edge of the lens itself. Very simple.
- "Sphere radius" refers to imaginary spheres that our lens is composed of. Imagine two spheres of glass floating in space, overlapping to some extent, and then imagine that our lens represents the parts of the spheres that overlap. To help in visualizing this, draw two circles on a piece of paper using a coin and a pencil, and be sure to allow some overlap between the circles. The area where the circles overlap is our lens. Starting with this paper diagram, one need only use imagination to expand the picture to three dimensions and glass.
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:
- Select the double-convex lens by clicking it.
- Deselect the "symmetrical" check box, which will allow you to choose different traits for the left and right-hand sides of your lens.
- Enter "1000" into the "Left Sphere Radius" window and press Enter.
- You will see that the right-hand side of the lens has become flat, and (because we now have a lens with less overall curvature), the beams travel farther to the right before converging. The lens is said to have a longer focal length.
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.
- Select the default convex lens by clicking on it.
- Re-enter "6" for "Left Sphere Radius," press Enter, then enable "symmetrical" again by clicking its checkbox, restoring our lens to its original state — a simple, symmetrical double-convex lens.
- Drag the mouse on the display to pan over to the region between x = 5 and 6 (remember that "x" means the horizontal axis), where the beams should now be converging. Once you have centered this part of the display, use the mouse wheel to zoom in a bit for a closer look.
- While looking as the point where the beams converge, click the "Left Hyperboloid" checkbox (because you selected "symmetrical" above, this entry will affect both sides of our lens). The lens focus should improve.
- A quick reality check — what constitutes an "improvement" in a lens? Well, ideally, all the beams should converge on a single point, rather than taking slightly different paths as they are doing now.
- Now we are going to fine-tune our lens by entering a value for hyperboloid curvature. Type ".074" into the "Left Curv. Fact." window, and press Enter. If you have entered all the right values up to now, this should produce a nearly perfect focus — all the beams should converge on a single point, located at about x = 4.996.
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.
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."
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):
- Symmetrical: selected.
- Lens Radius: 2.0
- Left Sphere Radius: 4.0
- Right Sphere Radius: 4.0
- Lens Thickness: 0.0
- Index of Refraction: 1.52
- Dispersion: 59
- X position: 0.0
- Y position: 0.0
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:
- Symmetrical: deselected.
- Lens Radius: 2.0
- Left Sphere Radius: 1000
- Right Sphere radius: -4
- Lens Thickness: 0.1
- Index of Refraction: 1.72
- Dispersion: 29
- X position: 0.3834
- Y position: 0.0
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.
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 ResultMouse 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 ResultMouse 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 ResultAbove 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
OpticalRayTracer has a number of methods for writing and reading data to/from the world at large, primarily by way of the system clipboard.
- To create a copy of a lens you have designed, simply click the lens, press the right mouse button and choose
"Copy".
- To paste that lens somewhere else, move the mouse cursor to the desired destination point, press the right mosue button and select
"Paste: mouse cursor."
- You can save lens descriptions in other locations, or even paste them into an e-mail for a friend, by simply pasting the lens desciption from the system clipboard. This works because an OpticalRaytracer lens description is a plain-text line of ordinary characters like this:
0.0|0.0|2.0|6.0|6.0|0.0|1.52|0.03|0.03|59.0|false|false|trueYou 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".
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).
(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" 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:
- n1 = index of refraction of medium 1
- a1 = angle within medium 1
- n2 = index of refraction of medium 2
- a2 = angle within medium 2
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:
- Medium 1: air
- n1 = 1.0
- a1 = 20 degrees
- Medium 2: crown spectacle glass
- n2 = 1.52
- a2 = arcsin(1.0 sin(a1) / 1.52) = 13.00365 degrees
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:
- ior = original index of refraction for the medium.
- dp = dispersion pivot wavelength, set to 589.3 nm, the sodium yellow line.
- w = wavelength of the tracing beam in nm (nanometers).
- abbe = Abbe's Number, a value associated with many glasses and that describes its dispersion property. Lower Abbe's numbers result in higher dispersion.
Abbe's Number is arrived at in this way:
abbe = (nd-1)/(nf-nc)Where:
- nf = a medium's index of refraction at the 486.1 nm hydrogen blue line.
- nd = a medium's index of refraction at the 589.3 nm sodium yellow line.
- nc = a medium's index of refraction at the 656.3 nm hydrogen red line.
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%.
- To change a color in the "Configure" panel's selection list, simply click the colored button for the value you want to change. A color selection dialog will appear.
- All the configuration values, along with a full description of the lenses you create, are preserved between sessions in a file located at #userdir#/OpticalRayTracer.ini on this system, and the same information can be copied onto the system clipboard with the toolbar "Copy Configuration" button.
Here is an explanation of the controls in the Configuration panel:
- Domain Barrier Color. This is the color of the left and right-hand barriers that define the experimental domain.
- Y Baseline Color. This is the color of the reference line at y = 0 in the ray trace display. If you do not want this line to appear, set its color to the color of the display background (see "Display Background" below).
- Grid Color. This is the auto-scaling grid in the ray trace display. Again, you can turn this off by setting its color to that of the background.
- Lens Outline Color. This color is used to draw the profile of each lens.
- Tracing Beams Color. This is the beam color that is used when dispersion is not being computed. Remember that dispersion beams have an internally computed color, appropriate to their wavelength.
- Beam Intersection Color. This is the color of the dots that mark the intersections between light beams and lens surfaces.
- Lens Selected Box Color. This color might be better allowed to remain in view, since it tells you which lens has been selected and to which lens the control panel settings apply.
- Display High Background Color. This color defaults to white, but in some cases, like trying to make out the color of dispersion beams, another color might be better.
- Display Low Background Color. This color defaults to black, but the user has the option of choosing a different color.
- Intersection Dot Size. This numeric entry specifies the size of the dots that mark intersections between light beams and surfaces. A positive entry produces circles, a negative entry produces solid disks of color.
- Y Snap-to-Base Band. This numeric entry sets the threshold for the behavior that returns a lens to the Y baseline when the mouse is released. This is ordinarily a good thing, a feature, but if you prefer this not to happen, set this number to zero. In truth, the feature is always active regardless of the this setting, but if you enter zero, the feature is only active at a threshold value of zero, which ... oh well, I think you get the idea.
- Beam Width. This setting actually sets the width of all image lines. An entry of zero is ignored, the minimum beam width is 1.
- Beam Count. This is a setting with an large impact on program performance. OpticalRayTracer's algorithms are swift, but choosing a large number of tracing beams might disable one of its best features: real-time response to user inputs. Also, it is easy to become overloaded with information as the number of beams increases. It is difficult to take advantage of the information presented by more than about 8 tracing beams. Lots of beams can be entertaining, though.
- Interactions per beam. This determines the limit to interactions for a given beam, to avoid the computation of pointless internal reflections within a lens, for example. The default value is quite large, but a sufficiently complex lens system might require that it be increased.
- Source Y Start and
- Source Y End. These values determine the vertical limits for the array of tracing beams. These two numbers are typically set to fall within the chosen radius of your lenses. The default settings of -1.8 and 1.8 means all the beams fall comfortably within the default lens radius of 2 units (remember that a lens diameter is twice its radius).
- X Source Plane. This is the location in the x dimension from which the tracing beams emanate. In the ray trace display, zoom out to see the location of the beam origin, then change this number to see what happens.
- X Target Plane. This is the plane in the x dimension through which the tracing beams pass, regardless of their angle (desribed below). It is useful as a movable reference point, for example to see how a focusing effort is turning out.
- Beam Offset Angle. This setting is used to tilt the array of tracing beams, a way to test the off-axis performance of a lens without having to rotate the lens itself. By controlling the source angle you can observe the resulting path through a series of lenses, thus determining the off-axis performance for the entire system.
- Dispersion Beam Count. This setting produces a set of dispersion beams, with appropriate colors and wavelengths, for each tracing beam. These dispersion beams will be deflected by different amounts depending on specific lens settings, in particular the dispersion value. This is the key to the dispersion effect simulation.
- Diverging Beams. This checkbox causes the tracing beams to originate in and diverge from a point source located at the X source reference plane, rather than being generated in parallel.
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.
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.
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.