Thin Lens Ray Simulator

JJ Ben-Joseph headshot JJ Ben-Joseph

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

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 do, and object height ho. 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 is clamped between 0.001 and 0.1 s to maintain numerical stability. Input validation prevents zero or negative focal lengths and ensures all values are finite numbers.

3. Core equations

The foundation is the thin lens equation

1f=1do+1di

Solving for the image distance yields

di=fdodo-f

The linear magnification follows as m=-dido, giving an image height hi=mho.

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 s_{n+1}=s_n+Δ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 di=0.30 m on the opposite side. The magnification is m=-0.300.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 do and di 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 do and di 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.

Embed this calculator

Copy and paste the HTML below to add the Thin Lens Equation - Interactive Ray Simulator to your website.