This project aims to create a basic geometric optical analysis software. My interest is mostly in analyzing photographic lens designs.
The project combines solutions from the following open source projects:
- RayOptics - a Java port of Michael Hayford's Ray-Optics.
- BEAM FOUR - incorporates BeamFour, originally written by the late Michael Lampton.
The project has two fairly independent components:
- This is derived from Michael Hayford's Ray-Optics project. This version is mainly focused on photographic lenses.
- Can import lens specifications in the format supported by PhotonsToPhotos Optical Bench.
- Can export to Zemax, BEAM FOUR, MJH Ray Optics.
- Features a command line tool that takes in the lens specification and generates the following outputs:
- Spot diagrams (SVG)
- Layout diagrams (SVG)
- Geometric / Diffraction MTF by Field plots (SVG)
- Ray aberration plots
- OPD plots
- Paraxial report
- Zemax file
- A markdown README that brings together above
- For examples see links below.
- Features an optimizer with the following capabilities:
- Set variables on surface properties, widths. Aspherics are supported.
- Set goals targeting MTF, ray aberrations or spot sizes.
- Constrain by paraxial parameters.
- Constrain curvatures and thicknesses to avoid altering the design drastically.
- Add weights to influence the outcome.
- The BeamFour implementation is undergoing refactoring to separate the UI layer from the core ray tracing and analytics functionality. This is still work in progress.
- Since BeamFour input files are hard to create manually, there is a facility in the RayOptics component to generate BeamFour inputs from a lens specification. This facility is limited to photographic lenses.
- The MTF feature in BeamFour has been updated to match the RayOptics functionality for computing single wavelength MTFs for a specific field.
- Perhaps the biggest challenge is to make the optimizer useful in real world scenarios and be able to compete with the likes of Zemax.
- I would like the project to evolve so that some of the UI capabilities in BeamFour can be combined with the optimization and analytics capabilities in RayOptics. The main issue is that BeamFour is more general, whereas RayOptics understands photographic lenses. Still, the BeamFour UI capabilities such as viewing a lens in simulated 3-D is very helpful.
- There are many more analytic capabilities that could be added to RayOptics.
- Reverse Engineered Leica Noctilux M 50mm f1.0
- Reverse Engineered Noct Nikkor 58mm f1.2
- Nikkor Z 58mm f0.95S Noct from Patent
- Leica R Summicron 50mm f2 from Patent
These are a small selection. The Examples folder holds generated reports for many more lenses.
- LensTool2 command line tool - options, input format and generated outputs.
- LensTool2 Optimizer - describes how to set up optimization runs in the prescription file.
- Glass catalogs - glass catalogs used by Beam42.
- rayoptics-cpp - a faithful C++ port of the Java RayOptics module, maintained using LLMs.
- r/LensPatents - a related Reddit forum on lens patents and designs.
Citations follow the style used by Optica (formerly OSA) journals: author(s), "title," journal volume, pages (year), DOI.
-
D. P. Feder, "Optical Calculations with Automatic Computing Machinery," J. Opt. Soc. Am. 41, 630–635 (1951), doi:10.1364/JOSA.41.000630. This short paper provides equations for ray tracing for rotationally symmetric surfaces, including aspherics. Equations are provided in a format suitable for computer programs. Additionally, this paper also covers calculation of image aberrations. Warren J. Smith, Modern Optical Engineering, describes the algorithms in this paper.
-
G. H. Spencer and M. V. R. K. Murty, "General Ray-Tracing Procedure," J. Opt. Soc. Am. 52, 672–678 (1962), doi:10.1364/JOSA.52.000672. This paper presents generalized ray tracing equations that cover not only rotationally symmetric surfaces (including aspherics) but also diffraction gratings. The paper allows for surfaces to have their own local axes. The ray tracing in rayoptics module is based on this paper.
-
R. E. Hopkins and R. Hanau, "Fundamental Methods of Ray Tracing," Chap. 5 in Military Standardization Handbook: Optical Design, MIL-HDBK-141 (U.S. Defense Supply Agency, Washington, DC, 1962). Available from EverySpec. It covers ray tracing equations for rotationally symmetric surfaces including aspheric surfaces. The equations are presented in a form suited for implementation in computer programs. The final equations in this document are very similar to Feder's equations. This document goes into details of how these equations are derived. Daniel Malacara, Handbook of Optical Design, describes the ray tracing equations found in this document.
-
H. H. Hopkins, "Calculation of the Aberrations and Image Assessment for a General Optical System," Optica Acta 28, 667–714 (1981), doi:10.1080/713820605. RayOptics calculation of optical path difference is based on this paper.
-
A. Mikš, "Dependence of the wave-front aberration on the radius of the reference sphere," J. Opt. Soc. Am. A 19, 1187–1190 (2002), doi:10.1364/JOSAA.19.001187. Reference for the infinite-reference-sphere wavefront calculation in the Ray-Optics port.
-
G. H. Golub and J. H. Welsch, "Calculation of Gauss Quadrature Rules," Math. Comp. 23, 221–230 (1969), doi:10.1090/S0025-5718-69-99647-1. Nodes and weights from the eigenvalues and eigenvectors of a tridiagonal Jacobi matrix.
-
G. W. Forbes, "Optical system assessment for design: numerical ray tracing in the Gaussian pupil," J. Opt. Soc. Am. A 5, 1943–1956 (1988), doi:10.1364/JOSAA.5.001943; erratum, J. Opt. Soc. Am. A 6, 1123 (1989), doi:10.1364/JOSAA.6.001123. Original paper on the Gaussian quadrature pupil sampling pattern. Very effective!
-
B. J. Bauman and H. Xiao, "Gaussian quadrature for optical design with noncircular pupils and fields, and broad wavelength range," in International Optical Design Conference 2010, Proc. SPIE 7652, 76522S (2010), doi:10.1117/12.872773. Open-access version: LLNL-CONF-442492, UNT Digital Library.
-
E. Elliott, K. Moore, C. Normanshire, S. Gay, J. Aiona, and M. G. Nicholson, "Contrast optimization: a faster and better technique for optimizing on MTF," in International Optical Design Conference 2017, Proc. SPIE 10590, 1059014 (2017), doi:10.1117/12.2292761. Very effective optimization approach that directly targets MTF.
-
J. J. Moré, B. S. Garbow, and K. E. Hillstrom, User Guide for MINPACK-1, Argonne National Laboratory report ANL-80-74 (1980), doi:10.2172/6997568. Nonlinear equation and least-squares solvers used for ray aiming and optimization.
-
T. Steinich and V. Blahnik, "Optical design of camera optics for mobile phones," Adv. Opt. Technol. 1, 51–58 (2012), doi:10.1515/aot-2012-0002. Source of the wavelength weights used for the weighted polychromatic MTF.
The RayOptics module is in large part based on foundational work done by others.
The biggest piece is ported from on Michael Hayford's Ray-Optics. Unless specified otherwise the results are verified by capturing results from upstream and comparing them to project generated results. Discrepancies in results are due to differences in math functions between Python libs and Java; results can differ even though mathematical operations are identical.
The methodology used for these tests is covered in UPSTREAM_VERIFICATION.md.
| Computation | Origin and implementation | Verification | Reference |
|---|---|---|---|
| Sequential optical model: surfaces, gaps, apertures, fields, wavelengths and coordinate transforms | Ported model and specification classes | Upstream comparison | Ray-Optics |
| Surface sag, normals and intersections: spherical, conic, even-polynomial and radial-polynomial aspheres | Ported surface profiles | Upstream comparison | Spencer and Murty (1962) |
| Sequential real-ray tracing: local coordinates, refraction, reflection and optical path | Ported RayTrace kernel |
Upstream comparison | Spencer and Murty (1962) |
| Paraxial tracing and first-order properties: focal lengths, principal planes, pupils, numerical apertures, magnification and optical invariant | Ported FirstOrder, ParaxModel and supporting calculations |
Upstream comparison | Ray-Optics |
| Third-order aberrations: Seidel sums and aspheric contributions | Ported ThirdOrder calculations |
Upstream comparison | Ray-Optics |
| Chief-ray and pupil aiming, including wide-angle entrance-pupil location | Ported Trace and Wideangle calculations, using Java numerical solvers |
Upstream comparison | Ray-Optics |
| Vignetting factors and pupil-coordinate mapping | Ported VigCalc and field calculations |
Upstream comparison | Ray-Optics |
| Transverse ray aberrations and defocus | Ported ray/image-plane geometry, exposed through project analysis classes | Upstream comparison | Ray-Optics |
| Wavefront aberration and optical path difference (OPD), including refocusing and finite/infinite reference-sphere calculations | Ported WaveAbr; project analysis classes provide fan evaluation |
Upstream comparison | Hopkins (1981); Mikš (2002) |
| Wavefront grids, FFT point-spread function (PSF) and PSF sampling/scaling | Ported RayGrid and Analyses, with a project correction to pupil masking |
Upstream comparison | Ray-Optics |
| Grid-sampled spot intercepts | Ported SpotAnalysis.spot() and eval_grid() |
Upstream comparison of ray fans rather than a separate spot-grid result | Ray-Optics |
- The port uses Java solvers in place of SciPy, so solver-dependent results can differ within convergence tolerances.
- An intentional difference with upstream is that PSF calculation retains valid zero-OPD pupil samples
- Another difference is that the Glass model is not based on upstream, it is mostly internal with some bits based on GNU Optical.
The "Project" label means that this is an implementation in Beam42.
Also noted are areas where Codex and Claude have added significant value.
| Computation or output | Origin and implementation | Verification Status | Reference |
|---|---|---|---|
| Hexapolar pupil sampling | Derived from GNU Optical | Good | GNU Optical |
| Gaussian-quadrature pupil sampling | Project, with Codex and Claude | Ongoing | Forbes (1988, with erratum); Bauman and Xiao (2010) |
| Gauss-Legendre nodes and weights | Numerical Recipes, and alternative based on Netlib gaussq.f, using the Golub-Welsch method |
Good | Golub and Welsch (1969) |
| Weighted spot centroid, RMS radius, maximum radius and polychromatic spot statistics | Project | Good | |
| Geometric PSF, line-spread functions and monochromatic/polychromatic geometric MTF | Project | Good | Steinich and Blahnik (2012) for wavelength weights |
| Monochromatic diffraction OTF/MTF | Follows Michael Hayford's diffraction-MTF notebook | Ongoing | Hayford's notebooks |
| Polychromatic Diffraction MTF by field | Project, with Codex and Claude | Ongoing | |
| Contrast analysis and optimization residuals from sheared-pupil wavefront differences | Project, with Codex and Claude | Ongoing | Elliott et al. (2017) |
| Exit-pupil aiming for contrast analysis and frequency calibration | Project, with Codex and Claude | Ongoing | Hopkins (1981); Elliott et al. |
| Measured transmitted-pupil maps and contrast pupil maps | Project, with Claude | Ongoing | |
| Optimizer core with variables, goals, constraints, merit function | Project | Ongoing | |
| Optimizer Builder and LensTool2 configuration pipeline | Project, with Codex and Claude | Ongoing | |
| Least squares (MINPACK) | MINPACK Levenberg-Marquardt solver (lmder); MINPACK Powell hybrid (dogleg) solver (hybrd1). Ported from the Netlib MINPACK Fortran, including tests |
Good | Moré et al. (1980) and MINPACK license for MINPACK |
| Scalar root finding (secant method) | Ported from SciPy's secant method in scipy/optimize/_zeros_py.py |
Good | SciPy secant implementation |
| Scalar root finding (Brent method) | BeamFour, follows Numerical Recipes | Good | BeamFour; W. H. Press et al., Numerical Recipes in C, 2nd ed. (1992) |
| FFT calculations | jfftpack plus project FFT utilities | Good | jfftpack license and attribution |
| Glass-catalog lookup and wavelength-dependent refractive indices | Project; nd/vd dispersion comes from GNU Optical |
Good | |
| Lens layout construction | Project, with Codex | Good | |
| Plotting and SVG rendering | Derived from GNU Optical | Good | GNU Optical; license notices |
| Analysis reports, importers and exporters | Project | Ongoing |
- My fork of GNU Optical: https://github.com/dibyendumajumdar/goptical
- RayOptics (python) by Michael Hayford, who worked many years at an optical software company: https://github.com/mjhoptics/ray-optics.
- rayoptics4j - a partial port of above. See https://github.com/BeamFour/rayoptics4j
- Optiland: (python): https://github.com/HarrisonKramer/optiland
- Rayopt (python): https://github.com/quartiq/rayopt
- An older C project 'ray' originally written by Don Wells at NRAO implements Feder's equations for ray tracing. https://github.com/dibyendumajumdar/ray
- Geopter (C++,Qt): https://github.com/heterophyllus/Geopter
Here are some other projects that I have not personally tried out
- Astree (C++): https://github.com/edeforas/Astree
- Opticspy (python): https://github.com/Sterncat/opticspy
- Pyrate (python) https://github.com/mess42/pyrate
- A Matlab/Octave project: https://github.com/heterophyllus/OpticalDesign-Toolbox
- Kraken - Optical Simulator (python): https://github.com/Garchupiter/Kraken-Optical-Simulator
- OpticSim (Julia) by Microsoft: https://github.com/microsoft/OpticSim.jl
- An attempt to maintain a commercial product KDP is here: https://github.com/dinosauria123/Koko. Lots of spaghetti Fortran code, unfortunately.
The project includes code derived from several open-source projects. See the individual license notices in the source code and the LICENSE files:
- LICENSE-GPL-3.0.txt - the overall license for everything in rayoptics module,
and the license of the code derived from Goptical: mainly the
org.redukti.dataandorg.redukti.renderpackages, plusQuaternion,Transform3,Triangle2,Vector2PairandVector3Pairinorg.redukti.mathlib. - LICENSE-ray-optics.txt - BSD 3-Clause, for the code derived from Michael Hayford's ray-optics, by way of rayoptics4j.
- LICENSE-Minpack.txt - for the code derived from MINPACK.
- LICENSE-jfftpack.txt - for the code derived from jfftpack.
- beam42/LICENSE.txt - GNU GPL v2, for the
beam42module only; see below.
Each source file carries its own notice identifying which of the above it falls under. Files that are not derived
from any external project - original Beam42 code - are marked with a This code is part of Beam42 project header
and are licensed under GPL v3 or later, same as the overall project.
The overall license is GNU GPL v3 or later.
The beam42 module derives from BeamFour, which is GPL-2.0,
and it is kept under that license.
BeamFour is a standalone product. If the GPL-2.0 licensing of this module is a concern, the beam42 directory
can be removed — delete it along with its <module> entry in the root pom.xml.