RayCrafter (dev) vs Zemax

One fold mirror, up: RayCrafter (dev) against Zemax

A relay with one mirror turning the light up. In Zemax the mirrors sit where RayCrafter puts them, with the same outlines, and stop the same rays; the unclipped field matches. Not all matches where the mirror clips: the MTF and the RMS wavefront of the clipped field differ a little (Partial). The RMS spot of the clipped field now matches Zemax's own rays, and its Strehl ratio is not compared: Zemax's Huygens PSF (0.077) disagrees with Zemax's own wavefront map (0.091), which RayCrafter's PSF gives (0.090).

RayCrafter dev 5ecb2efd Zemax 24.1.3 λ 0.555 µm Zemax run 2026-12-03 22:21

The design

Two Thorlabs AC254-100-A with a 4 mm beam at 555 nm, 0 and 2 degrees, and a rectangular 25 x 40 mm mirror that turns the light up.

Zemax: seen from the side (z right, y up).
Zemax: seen from the side (z right, y up).
RayCrafter's own ray diagram.
RayCrafter's own ray diagram.

What is tested

RayCrafter's ZMX export of a folded design (coordinate breaks, mirror and outline): Zemax must trace it to the same rays.

Issue: raycrafter #159.

RayCrafter against Zemax

This is RayCrafter's development branch

RayCrafter at commit 5ecb2efd of dev, not the release on PyPI. The .zmx was exported at d5d3377b.

RayCrafter opens the project itself; Zemax (OpticStudio 24.1.3) the .zmx RayCrafter exported from it. So a difference may be in the export, in a calculation, or in what a quantity means. Each row is the largest difference over every field (0°, 2°).

24matching
3partial
0failing

Not matching: partial and fail rows.

QuantityLargest difference from ZemaxMatch / partial withinResult
RMS wavefront, fields with rays stopped, against Zemax's Wavefront MapAt fields 2, where Zemax's apertures stop rays, Zemax's Wavefront Map (piston and tilt removed) of the rays that get through: its RMS operand counts the stopped rays too (evaluation #72). Both numbers are fitted the same way: the evaluation takes a least-squares plane (piston and tilt) out of Zemax's Wavefront Map and out of RayCrafter's own wavefront map over the pupil, every point that got through alike (raycrafter #243, Rob's decision of 2026-12-04). RayCrafter's reported RMS wavefront and Zemax's RMS operand, which take the tilt out in direction cosines on a focused image, are a different convention (on the focused designs of #243 a plane in pupil coordinates was 1.5 to 8 % from Zemax's operand), so they are not what is compared here. RayCrafter's map is traced with 513 rays across the part of the pupil that gets light, where its RMS has converged (its window's 65 were 1.6 % low on US005899585 at 15.12 mm). Zemax's map is 64 x 64, and on a field whose rays are stopped where the wavefront is steep its RMS depends on where its grid falls: on US005899585 at 15.12 and 21.6 mm a 64 x 64 grid moved by under a step changes the RMS by 0.9 % (one standard deviation), so differences of that size can be Zemax's sampling. RayCrafter's own reported RMS wavefront, for information (waves): 2: 0.3531 (fitted 0.3507)0.003765 waves0.001 / 0.01 waves, or 1 % of Zemax's if larger, to failPartial
MTF (one wavelength), every fieldAt RayCrafter's own frequencies.0.01010.005 / 0.02Partial
MTF (all wavelengths), every fieldAt RayCrafter's own frequencies.0.01010.005 / 0.02Partial
All 27 rows, matches included
QuantityLargest difference from ZemaxMatch / partial withinResult
Zemax reads the aperture, fields, wavelength and afocal setting that were meant0 warnings0 / 0 warningsMatch
Surfaces: thicknesses, gaps and semi-diametersThe project file against the lens data Zemax holds0 mm1e−09 / 1e−06 mmMatch
Surfaces: curvatures and conicsCurvature in 1/mm01e−12 / 1e−09Match
Refractive index of each glassN-BK7, SF501e−06 / 0.0001Match
Fold mirrors (1): distance along the light0 mm1e−09 / 1e−06 mmMatch
Fold mirrors: half widths of the outlineAgainst the apertures Zemax holds (Zemax_layouts/layouts.json)0 mm1e−09 / 1e−06 mmMatch
Rays at the image, ray by ray: positionThe rays that both programs trace and get through: 27937 at 0, 19797 at 21.07e−13 mm1e−06 / 0.001 mmMatch
Rays at the image, ray by ray: slopedx/dz and dy/dz7.27e−161e−08 / 1e−05Match
Share of the pupil's rays that get through the aperturesRayCrafter's vignetting analysis against the range that Zemax's rings of rays allow: at 0, RayCrafter 100.0 %, Zemax 100.0 to 100.0 % (27937 of 27937 rays through); at 2, RayCrafter 71.0 %, Zemax 70.7 to 71.3 % (19797 of 27937 rays through)0 % points0.5 / 2 % pointsMatch
Chief ray at the image, every field5.33e−14 mm1e−06 / 0.001 mmMatch
Rays stopped by apertures and mirrorsOf the pupil points both trace, Zemax / RayCrafter stop: 8140 / 8140 of 27937. Counted are points stopped by one program and not the other0 %0 / 1 %Match
Focal length and f-numberCompares Zemax's image-space F/# with RayCrafter's f-number, which is the focal length over the diameter of the beam that gets through; for an unclipped beam that is the same quantity, so the two agree to rounding (they differ only where a rim clips the beam, as on clipped_negative_lens, where it is recorded, not scored)4.44e−14 %0.0001 / 0.1 %Match
RMS spot radius, fields with no ray stoppedZemax by Gaussian quadrature, RayCrafter from its spot diagram0 %0.1 / 2 %Match
RMS spot radius, fields with rays stopped, against Zemax's own raysZemax's RMS operand counts the stopped rays too, so its rays that get through are used, and RayCrafter's rays are launched at the same pupil points. field 2: Zemax's rays 52.53, RayCrafter 52.53 (launched at Zemax's pupil points; 0 points through in one program only), RayCrafter's spot diagram 50.94, Zemax's operand 85.58, RayCrafter's own rays summed finely 52.54 um5.06e−12 %1 / 2 %Match
Ray fans, tangential and sagittal1.01e−13 mm1e−06 / 0.001 mmMatch
RMS spot against focus, fields with no ray stoppedWhere the two ranges overlap0.02802 % of the largest0.1 / 2 % of the largestMatch
RMS wavefront, fields with rays stopped, against Zemax's Wavefront MapAt fields 2, where Zemax's apertures stop rays, Zemax's Wavefront Map (piston and tilt removed) of the rays that get through: its RMS operand counts the stopped rays too (evaluation #72). Both numbers are fitted the same way: the evaluation takes a least-squares plane (piston and tilt) out of Zemax's Wavefront Map and out of RayCrafter's own wavefront map over the pupil, every point that got through alike (raycrafter #243, Rob's decision of 2026-12-04). RayCrafter's reported RMS wavefront and Zemax's RMS operand, which take the tilt out in direction cosines on a focused image, are a different convention (on the focused designs of #243 a plane in pupil coordinates was 1.5 to 8 % from Zemax's operand), so they are not what is compared here. RayCrafter's map is traced with 513 rays across the part of the pupil that gets light, where its RMS has converged (its window's 65 were 1.6 % low on US005899585 at 15.12 mm). Zemax's map is 64 x 64, and on a field whose rays are stopped where the wavefront is steep its RMS depends on where its grid falls: on US005899585 at 15.12 and 21.6 mm a 64 x 64 grid moved by under a step changes the RMS by 0.9 % (one standard deviation), so differences of that size can be Zemax's sampling. RayCrafter's own reported RMS wavefront, for information (waves): 2: 0.3531 (fitted 0.3507)0.003765 waves0.001 / 0.01 waves, or 1 % of Zemax's if larger, to failPartial
Strehl ratio, fields where Zemax's Huygens PSF is consistentRayCrafter's Strehl ratio on the pixel grid of Zemax's Huygens PSF, as Zemax reads its own (its largest pixel); Zemax's prints three decimals.0.0001760.005 / 0.02Match
MTF (one wavelength), every fieldAt RayCrafter's own frequencies.0.01010.005 / 0.02Partial
MTF (one wavelength), cutoff frequency, every fieldOf the fields where Zemax's table reaches beyond the cutoff. Cycles/mm, RayCrafter then Zemax: 85 and 84; 86 and 860.831 %2 / 5 %Match
MTF (all wavelengths), every fieldAt RayCrafter's own frequencies.0.01010.005 / 0.02Partial
MTF (all wavelengths), cutoff frequency, every fieldOf the fields where Zemax's table reaches beyond the cutoff. Cycles/mm, RayCrafter then Zemax: 85 and 84; 86 and 860.831 %2 / 5 %Match
Grid distortion, largestZemax 4.316 %3.12e−05 percentage points0.005 / 0.05 percentage pointsMatch
Distortion, f-tanAt the largest field: Zemax 4.316 %, RayCrafter 4.316 %5.77e−08 percentage points0.005 / 0.05 percentage pointsMatch
Distortion, f-thetaAt the largest field: Zemax 4.358 %, RayCrafter 4.358 %5.82e−08 percentage points0.005 / 0.05 percentage pointsMatch
Field curvature, change from the axisAt 0, 1, 2°, the angles RayCrafter plots0.002344 mm0.01 / 0.1 mmMatch
Field curvatureRayCrafter takes the best focus of a whole fan, Zemax that of rays near the chief ray, so they differ with spherical aberration. Where rays are stopped, RayCrafter's fan loses them; Zemax's rays near the chief ray do not see apertures0.002344 mm0.01 / 0.1 mmMatch
Not compared

RMS spot against field: Some rays are stopped, and Zemax's RMS operands count them all the same, so there is no number of Zemax's to compare with

RMS wavefront against field: Some rays are stopped, and Zemax's RMS operands count them all the same, so there is no number of Zemax's to compare with

Strehl ratio, fields where Zemax's Huygens PSF disagrees with its own wavefront map: Zemax reports a positive exit pupil position, and its Huygens PSF is reproduced by RayCrafter's summed over the reference sphere of the opposite sign to the one of Zemax's own wavefront map; the whole explanation, with the numbers, is in the section “Strehl ratio: Zemax's Huygens PSF disagrees with Zemax's own wavefront map” (https://github.com/raycrafter-optical-design/evaluation/issues/84). at 2 deg: Zemax 0.077, RayCrafter 0.088, Zemax's own wavefront map 0.091

Strehl ratio: Zemax's Huygens PSF disagrees with Zemax's own wavefront map

Not comparable at these fields

Where Zemax reports the exit pupil at a positive position, its Huygens PSF is the diffraction image of a different wavefront from the one in its own Wavefront Map, and the Strehl ratio it prints is not that of the wavefront it reports. RayCrafter's Strehl ratio is computed from the wavefront Zemax's map shows, summed over the reference sphere of the sign that map and Zemax's OPD use (it differs from Zemax's wavefront map by 0.003 at 2 deg, Zemax's FFT PSF by 0.002 at 2 deg). So the two Strehl ratios cannot be compared at these fields. This is an inconsistency inside Zemax's output; we do not claim to know that Zemax's code is wrong. Decision of the project's owner, evaluation #84: the page must say so in full, and it does here.

RayCrafter's Strehl ratio is read on the pixel grid of Zemax's Huygens PSF (its largest pixel, as Zemax reads it). The grid differences are the largest difference of relative intensity over the 128 x 128 pixels, RayCrafter's PSF against Zemax's: once with the reference sphere of the exit pupil as RayCrafter has it and as Zemax's own Wavefront Map and OPD have it, and once with the sphere's radius reversed (the one change; RayCrafter does the sum). Where the reversed sphere reproduces Zemax's grid and the right one does not, Zemax's Huygens PSF used the opposite sign.

Field (deg) Zemax exit pupil position (mm) Strehl, Zemax Huygens Strehl, RayCrafter (Zemax's grid) Strehl of Zemax's own wavefront map Peak of Zemax's FFT PSF Grid difference, sphere as it is Grid difference, sphere reversed
2 deg39.060.0770.0880.09130.09060.03480.0038

Same wavefront, a different Strehl ratio. Zemax's Wavefront Map is the same, to 1e-6 waves, in these designs, and the Huygens Strehl ratio is not:

  • 2 deg: fold_one_away has the same wavefront map, and Zemax's Huygens Strehl ratio 0.077, with its exit pupil position at +39.06 mm.
  • 2 deg: fold_out_of_plane has the same wavefront map, and Zemax's Huygens Strehl ratio 0.089, with its exit pupil position at -39.06 mm.
  • 2 deg: fold_periscope has the same wavefront map, and Zemax's Huygens Strehl ratio 0.089, with its exit pupil position at -39.06 mm.

Zemax's FFT PSF. Its text prints no Strehl ratio and its values are "not normalized". Read as a Strehl ratio, the largest value of its grid is on the scale where a perfect wavefront peaks at 1, as the fields where nothing tells the two signs apart show (nearly diffraction limited, so that the wavefront map's own Strehl ratio is known): 0 deg: FFT PSF peak 0.9912, wavefront map 0.9911, Huygens 0.991. That scale is read off those fields, not computed: Zemax gives no unaberrated PSF of the same sampling. The peak is a pixel of the 256 x 256 grid, so it can sit a little below the true peak. Where a column shows a dash, Zemax was not asked for the FFT PSF there, or for a wavefront map.

What is and is not shown. Shown: Zemax's Huygens grid is reproduced by RayCrafter with the sphere reversed, and by nothing else we tried. Not shown: why Zemax's Huygens PSF uses the sign it does, and why the Strehl ratio of Zemax's wavefront map (or its FFT PSF) differs from RayCrafter's by what the table gives (the programs sum the light differently: Zemax's FFT takes plane waves, RayCrafter and Zemax's Huygens PSF sum the wavelets of the reference sphere).

Rays

Both programs trace a hexapolar pupil, with the first point of each ring at +x, so the rays that both trace can be paired one by one: RayCrafter's spot diagram (6 rings) with Zemax's ray trace (96 rings).

Spot diagrams about the chief ray: Zemax's rays (red dots) and RayCrafter's (blue dots).
Spot diagrams about the chief ray: Zemax's rays (red dots) and RayCrafter's (blue dots).
The rays both programs trace: worst difference at the image, against field.
The rays both programs trace: worst difference at the image, against field.

RayCrafter's own plots

What RayCrafter's window and report draw, with Zemax's points over them (open markers).

Some rays are stopped. Zemax's RMS spot and RMS wavefront against field count them all the same, so those two plots do not compare like with like where they are.

The pupil of each field: the rays Zemax lets through and those it stops.
The pupil of each field: the rays Zemax lets through and those it stops.
RMS spot radius against field angle.
RMS spot radius against field angle.
Strehl ratio and RMS wavefront against field angle.
Strehl ratio and RMS wavefront against field angle.
Distortion, f-tan and f-theta.
Distortion, f-tan and f-theta.
Field curvature, tangential and sagittal.
Field curvature, tangential and sagittal.
MTF (one wavelength) at 0°.
MTF (one wavelength) at 0°.
MTF (one wavelength) at 2°.
MTF (one wavelength) at 2°.
MTF (all wavelengths) at 0°.
MTF (all wavelengths) at 0°.
MTF (all wavelengths) at 2°.
MTF (all wavelengths) at 2°.

The folded layout

RayCrafter's 3D scene from the side, the end and above.
RayCrafter's 3D scene from the side, the end and above.
Zemax: seen from the end (x left, y up).
Zemax: seen from the end (x left, y up).
Zemax: seen from above (y right, z down).
Zemax: seen from above (y right, z down).
Zemax: seen obliquely.
Zemax: seen obliquely.

The numbers behind the rows

For the rows that have no plot of their own. Zemax's values are from our own run; RayCrafter's from its analysis of the project.

First orderZemaxRayCrafter
effective focal length mm-85.1-85.1
f number21.2821.28
FieldChief ray, Zemax (mm) Chief ray, RayCrafter (mm)Share through, Zemax (%) Share through, RayCrafter (%)RMS spot, Zemax (mm) RMS spot, RayCrafter (mm) Strehl, ZemaxStrehl, RayCrafter Worst ray position difference (mm) Worst ray slope difference
0°0-1.337e-301001000.0019320.0019320.9910.99124.688e-145.435e-16
2°-3.074-3.07471.01710.085580.050940.0770.088181.073e-137.268e-16

Lens data

The radius and thickness in the project file beside the radius Zemax holds, with Zemax's catalogue and index for each glass.

Zemax #TypeRadius, RayCrafter (mm)Radius, Zemax (mm)Thickness (mm)GlassSemi-diameter (mm)
1Standard (stop)62.7562.754N-BK7 SCHOTT, n = 1.51827412.7
2Standard-45.71-45.712.5SF5 SCHOTT, n = 1.67647212.7
3Standard-128.23-128.23313.512.7
7Standard62.7562.754N-BK7 SCHOTT, n = 1.51827412.7
8Standard-45.71-45.712.5SF5 SCHOTT, n = 1.67647212.7
9Standard-128.23-128.23181.90804812.7

How Zemax was run

By make_zemax_reference.py, the same way for every design, on 2026-12-03 22:21, on fold_one_up.zmx exactly as exported (0 failed steps). zmx_export.json ties that file to the project, and the run refuses a file that does not fit it. What is asked for, and why: zemax_analyses.md; every file: Zemax_reference_output.

Reproduce

export UV_PROJECT_ENVIRONMENT=~/uv_venvs/evaluation_mac
uv run python -m evaluation_tools.from_raycrafter.export_zmx --check fold_one_up
uv run python -m evaluation_tools.from_raycrafter.compare_zemax fold_one_up
uv run python -m evaluation_tools.build_summary

27 quantities compared.