Home / Science / Physics / Optics and photonics / Lens ray tracerTool #932

Lens ray tracer: trace rays through spherical lenses, spot diagram, focal length and aberrations

Type a lens system as a list of spherical surfaces and trace exact rays through it: focal length, f-number, image position, a spot diagram against the Airy disc, spherical aberration, ray fans, best focus, distortion and Petzval field curvature, drawn as a lens layout.

Keep it one tap away for everyday use.

Bookmark Lens ray tracer?

Press Ctrl + D now. Your browser opens its own bookmark box, where you choose the name and folder.

  1. Surfaces
  2. Trace
  3. Spot
  4. Aberrations
Nothing is uploadedWorks offline once open

Lens system

The aperture stop is the first surface, so the entrance pupil is there. Light travels left to right. One wavelength at a time: type the glass index for the colour you care about (a crown glass is about 1.517 for yellow light, rounded). The example lenses are made up.

Result

Exact (real) rays through spherical surfaces, one wavelength, no diffraction in the spot diagram (the circle is the Airy disc for comparison: a spot much smaller than it means the lens is diffraction-limited). For study and planning, not a substitute for professional optical design software.

Download

What it does

A lens bends each ray by Snell’s law where it enters and leaves the glass. Rays near the axis (paraxial rays) all meet at the focus that the lens formula predicts, but rays through the edge of a spherical lens, or from a star off to the side, miss it a little. Those misses are the aberrations, and they decide how sharp an image the lens can make.

This tool traces exact rays in three dimensions through any number of centred spherical or flat surfaces. A paraxial trace gives the first-order numbers (effective and back focal length, image distance, magnification, f-number); then a fan of real rays across the entrance pupil gives a spot diagram, the longitudinal spherical aberration curve, the tangential and sagittal ray fans, the best focus, and the distortion of the chief ray. A lens layout shows the rays on their way.

How to use it

  1. Pick an example or type your own surfaces, in the order light meets them. Each line is radius thickness index semi-diameter in millimetres:
    • radius positive when its centre of curvature is to the right (a convex front face), negative when to the left, inf for a flat face;
    • thickness to the next surface (the last line’s is ignored, the image plane is found for you);
    • index of the material after the surface (1 for air);
    • semi-diameter, the clear radius, optional; rays outside it are clipped (vignetting).
  2. Choose an object at infinity (a star, parallel light) or at a distance in front of the first surface.
  3. Set the entrance pupil diameter (the width of the light beam at the first surface, which is the stop) and the field angle for the off-axis spot.
  4. Choose the image plane: the paraxial focus or the best focus (smallest RMS spot), plus any extra shift.

Worked example

The default is a made-up plano-convex lens, curved side first: radius 51.7 mm, 5 mm thick, index 1.517, then flat. The page gives f = 100 mm (51.7 / 0.517) and a back focal length of 96.70 mm; with a 20 mm pupil that is f/5. On axis, rays through the rim focus 1.10 mm short of the paraxial focus (undercorrected spherical aberration) and the RMS spot is 63.8 µm, far larger than the 3.58 µm Airy disc: this lens is aberration-limited at f/5. At 5° the RMS spot is 141 µm, the image is 8.748 mm off axis, and distortion is tiny (−0.0071 %).

Turn the same lens round (flat side to the light) and the rim rays focus 4.38 mm short: four times the spherical aberration. That is why a plano-convex lens should face its curved side towards the parallel light.

Tips

  • Halving the pupil diameter cuts the spherical aberration blur by about eight times (it grows with the cube of the aperture).
  • The spot diagram is geometric. When the RMS spot is well inside the Airy circle, diffraction, not aberration, sets the sharpness.
  • Distortion is the difference between where the real chief ray lands and where the paraxial chief ray would; positive is pincushion, negative is barrel.
  • The Petzval radius is the curved surface the lens naturally images a flat object onto.

FAQ

Does it handle colour? One wavelength at a time: change the indices to the values for another colour and compare.

Can I model aspheres, mirrors or tilted elements? Not here: centred spherical and flat refracting surfaces only.

Is it good enough to design a lens? It is for study and planning, not a substitute for professional optical design software and a qualified optical designer.

Where the numbers come from

  • Paraxial y-nu ray trace, real ray tracing through spherical surfaces (the Spencer and Murty / Welford intersection and vector refraction formulas), Petzval sum: standard results, for example Welford, W. T., Aberrations of Optical Systems (1986), and Smith, W. J., Modern Optical Engineering.
  • Airy disc radius 1.22 λ N: standard diffraction result. The crown-glass index 1.517 is a rounded general value; all example lenses are made up.
  • Checked against an independent NumPy ray tracer written for the tests (sphere intersection from the centre of curvature, angle-form Snell's law) and against the thick-lens lensmaker's equation; no lens catalogue or glass data is used.

Standard scientific values, such as constants, atomic weights and melting points, are facts found in every textbook; we name where ours were checked. If you are an author or publisher and want a value, a credit or a table changed or removed, tell us and we will act quickly.

Last updated 2026-11-09.

Related tools

Gaussian beam calculator #930 Put lenses and curved mirrors on an optical rail and follow a laser beam through them with the complex beam parameter q and ABCD matrices: the size and position of every new waist, Rayleigh range, divergence, beam radius and wavefront curvature anywhere, with M² for real lasers. Diffraction pattern generator #933 See and measure the light pattern from a single slit, a double slit, a grating or a round hole on a screen at any distance: the picture, the irradiance profile, fringe spacing, the Airy disc, grating orders and resolving power, in the far field (Fraunhofer) or near field (Fresnel). Sellmeier fitter #935 Paste or open measured refractive index against wavelength and fit a Sellmeier (1 to 3 terms) or Cauchy equation: coefficients with standard errors, residuals, the index at any wavelength, Abbe number, group index and group-velocity dispersion, with every model compared. Star FWHM checker #72 Open a star image and measure every star's FWHM, half-flux radius and elongation, with a map across the field that shows focus, sensor tilt, field curvature and tracking errors. Backfocus calculator #43 Add up your camera, filter wheel, off-axis guider and adapters, allow for the filter's thickness, and get the exact spacer stack to hit your reducer's or flattener's backfocus from the spacers you own. Telescope and camera calculator #19 Enter your telescope, eyepieces and camera to see magnification, true field, exit pupil, faintest stars, image scale and whether your camera suits your seeing, with a picture of what fits in the view.