Thin Lens Ray Simulator

JJ Ben-Joseph headshot JJ Ben-Joseph

Introduction: 1. Real‑world motivation

From eyeglasses to telescopes, thin lenses focus light by redirecting rays according to simple geometric rules. Students often solve the lens equation on paper yet struggle to picture how rays travel through the lens and where the image forms. This calculator preserves the traditional computation but couples it to a live ray diagram. As you adjust the object distance or focal length, rays shoot across the canvas, converge, and build an image arrow while striped bars display object and image distances. The animation responds in real time, turning the abstract algebra into a visual narrative that mirrors the behavior of actual lenses.

2. Variables and assumptions

The simulation assumes a thin, ideal lens obeying the paraxial approximation. Three inputs define the optical setup: focal length f , object distance d o , and object height h o . All quantities use SI units. The lens sits at the origin with the object to the left; positive image distances indicate real images to the right. Rays are propagated in a two-dimensional plane, ignoring thickness, aberrations, and diffraction. The time step Δt controls how fast the animated rays advance; it must be between 0.001 and 0.1 s to keep the animation readable. Input validation rejects zero focal length, nonpositive object distance, nonpositive object height, and the focal-plane case where do=f because the image distance is infinite. Negative focal length is allowed for diverging lenses.

Formula: 3. Core equations

The foundation is the thin lens equation

Formula: 1 / f = 1 / d_o + 1 / d_i

1 f = 1 d o + 1 d i

Solving for the image distance yields

Formula: d_i = (f d_o) / (d_o - f)

d i = f d o d o - f

The linear magnification follows as m = - d i d o , giving an image height h i = m h o .

4. Numerical scheme

Rays propagate at constant speed and change direction instantaneously at the lens. To animate this, the simulator stores two segments for each ray: from the object to the lens and from the lens to the image. A parameter s tracks progress along the current segment. At each frame explicit Euler updates the parameter by sn+1 = sn + Δt until the segment ends, after which the next segment begins. The positions (x,y) interpolate between endpoints based on s . The algorithm is simple yet numerically stable for the small time steps used. Every frame writes time, ray positions, and image height to an array that underpins the CSV export.

5. Worked example

Suppose a 0.05 m tall object sits 0.15 m in front of a 0.10 m focal length converging lens. The lens equation gives d i =0.30 m on the opposite side. The magnification is m =- 0.30 0.15 =-2, so the image is 0.10 m tall and inverted. Entering these values and pressing Play launches rays from the object tip. One ray travels parallel to the axis and refracts through the far focal point, while another passes through the lens center undeviated. Their intersection builds the inverted image arrow at 0.30 m. The striped distance bars show d o and d i as proportional lengths, providing a visual check on the equation.

6. Comparison table

The table compares the baseline scenario above with two variations: moving the object farther away and replacing the lens with a diverging element of negative focal length. Values stem from the simulation.

Scenario f (m) dₒ (m) dᵢ (m) m
Baseline 0.10 0.15 0.30 -2.0
Object farther 0.10 0.25 0.17 -0.7
Diverging lens -0.10 0.15 -0.06 0.4

The diverging lens produces a virtual image on the same side as the object, reflected by the negative image distance and positive magnification. The animation illustrates this by keeping the image arrow on the object side and drawing rays that appear to emanate from the virtual focus.

7. How to read the animation

The canvas shows the optical axis as a horizontal line with the lens at the center. A vertical orange arrow on the left represents the object, and a blue arrow on the right denotes the image. When animation begins, two rays leave the object tip: an orange one moving parallel to the axis and a blue one passing through the lens center. Dots crawl along each ray, advancing at a rate set by Δt . When the rays meet, the image arrow fills in, and the caption announces the image distance and magnification. The striped orange and blue bars beneath the canvas encode d o and d i independently of color. Keyboard users can focus the canvas and press the space bar to play or pause.

8. Limitations

The simulator omits thick-lens effects, chromatic and spherical aberrations, and diffraction limits. It assumes paraxial rays and small angles; large off-axis objects or short focal lengths would require more advanced ray tracing. Numerical integration is straightforward because rays move linearly, but extremely large time steps could cause them to jump past the lens or miss the intersection. Finally, the distance bars scale linearly and may saturate for very large distances, so interpret them qualitatively.

9. Suggested extensions

Future work could incorporate multiple lenses, allow arbitrary ray angles, or overlay wavefronts to connect geometric and wave optics. A phase-space plot of object versus image distance would reveal the symmetry of the lens equation. Related tools include the Lens Maker’s Equation Calculator, the Thin Lens Magnification Calculator, and the Lense–Thirring Precession Calculator for a relativistic twist on rotation and light.

10. References

For deeper reading, consult E. Hecht’s Optics for derivations of the thin lens equation and its limits. The American Association of Physics Teachers publishes numerous laboratory exercises on ray tracing. Classic texts by Abbe and Rayleigh provide historical context for the evolution of lens theory.

How to use this calculator

  1. Enter f (m) using the unit or time period shown by the field.
  2. Enter dₒ (m) using the unit or time period shown by the field.
  3. Enter hₒ (m) using the unit or time period shown by the field.
  4. Run the calculation and compare the output with a second scenario before acting on it.

Arcade Mini-Game: Thin Lens Ray Simulator Calibration Run

Use this quick arcade run to practice separating useful scenario inputs from common planning mistakes before you rely on the calculator output.

Score: 0 Timer: 30s Best: 0

Start the game, then use your pointer or arrow keys to catch useful inputs and avoid bad assumptions.

Enter values and press Play.
Simulation summary will appear here.