1. Introduction
For the planning and the realization of sophisticated optical setups in laboratories, a large number of software tools are available to support the user during the design and the actual setup phase. For the design, the optical elements (e.g., mirrors, lenses, diffraction gratings, laser crystals, etc.) can first be placed in a virtual laboratory space (e.g., on a virtual optical breadboard) and the propagation of the light (e.g., a laser beam) is described by tracing a bundle of light rays with an appropriate wavelength spectrum mimicking the real (and laterally extended) beam along the intended path. Such a virtual setup, which should resemble the real setup as closely as possible, can help to optimize the design and to ensure that different optical elements do not interfere with the beam path where it is not intended. Problems with the setup, which can be caused by overlap or blocking of the elements and/or the beam, can be identified (and mitigated) before realizing the assembly of the optical elements in the lab. A detailed and realistic planning becomes all the more essential, the more optical elements are included in the actual setup. Such an approach helps to save time and effort during the setup phase [
1,
2,
3,
4].
Most well-established ray-tracing software tools like Zemax, Fred, Comsol or Optica [
5,
6,
7,
8] describe the propagation of realistic beams through optical setups by tracing thousands of rays through the setup, including the correct and detailed description of reflection, diffraction and wavelength-dependent refraction on complex lens surfaces or other optical elements in the setup. Such immensely powerful software tools have—among others reasons—been developed for the optimization of setups with respect to achieving minimal (and realistic) focal spot sizes of ray distributions at different positions in the setup by means of geometrical optics. Furthermore, they come with extensive graphical user interfaces (GUIs) and give the user the possibility to choose from an impressive amount of parameters and options to describe lenses and mirrors in a very precise way. While these software solutions clearly provide the user with extremely powerful tools for a large variety of classical optics design tasks, like the mitigation of aberration in multi-element camera lenses, these programs can sometimes be less suited for the visualization of laser setups before their actual construction in the lab. The very precise—but sometimes too complicated—description of optical elements and ray distributions can prove to be time-consuming and sometimes unnecessary for setups using low divergence, quasi-monochromatic beams. The programs offer a huge amount of options and parameters to set for rather simple assemblies, often without offering reasonable default values, which complicates the design where it might not be absolutely necessary. Especially opto-mechanical elements, which may play a crucial role when it comes to the actual implementation in the lab, are often not at all or only approximately included in the description with the established software tools and require precise and detailed manual positioning and selection if available. On top of that, some of these tools may come with non-negligible license costs and sometimes with no or rather intricate application programmer interfaces (APIs), which might render the quick scripting, modularization and integration into other existing simulation tools extremely time-consuming or even impossible.
For those reasons we decided to develop and implement a new software tool called LaserCAD [
9], which follows a Python-script based approach [
10,
11,
12]. The idea behind LaserCAD is that the setup is defined in a language close to geometric optics—e.g., using terms like
and
—together with a list of available optical elements requiring only a minimal number of parameters to be defined, while all values come with default settings. All elements will by default be placed on the optical axis if not specified differently and come with an automatically selected and adapted mount and post assembly that can be changed easily whenever necessary. When executed in a standard Python terminal, LaserCAD produces a comprehensive text output including name, type, position and normal direction of each element and beam in the terminal for debugging. As the graphical backend, we use FreeCAD [
13], an open-source 3D computer-aided design (CAD) software. When the script is executed in FreeCAD, each beam, element and mount will be rendered and shown in an interactive window for visualization and post processing.
A key feature of LaserCAD is its purely script-based design philosophy, which resembles the modular and extensible nature of Latex documents. This approach ensures that optical setups are fully defined through concise Python scripts, making the system lightweight, scalable, and easily integrable as a Python library. Despite this simplicity, the framework remains highly flexible and can be expanded with user-defined elements, analysis tools, or algorithms whenever required. A strong emphasis is placed on the inclusion of opto-mechanical components, which are incorporated by default in every setup. These can be freely customized or extended, allowing users to represent realistic laboratory conditions with minimal additional effort. The unique combination of a professional CAD backend—enabling precise mechanical design, positioning, and scalability up to finite element analysis—with a Python-based ray-tracing framework for optical simulation provides an exceptionally powerful yet accessible tool. This integration allows users to perform detailed optical and mechanical design within a single environment while maintaining full extendability toward more complex algorithms, optimization procedures, or analysis modules implemented as plug-ins.
The remainder of this paper is structured as follows:
Section 2 describes all relevant classes for the program and their hierarchy. In
Section 3, the used ray-tracing algorithms for geometrical optics are presented, and in
Section 4 we show some use cases of LaserCAD.
3. Ray Tracing Algorithms
The ray tracing algorithms follow the well-established standard equations that are widely used in modern optics simulation tools [
7,
17,
18,
19]. Nevertheless, we will define these equations in this context, as they define the scientific base for the comparison of LaserCAD’s simulation results to those from other software tools. Choosing, e.g., a plane mirror as an example for an optical element (which is by default taken to be thin and planar), its front surface can be described as a plane, which fulfills for all
in this plane
with the mirror’s position
(by default located at the center of the front surface) and its normal
. Using the definition from Equation (
1), a ray with starting point
and direction
will propagate the length
until it reaches the center of this mirror. Inserting this value of
L in Equation (
1) defines the intersection point of the ray with the mirror’s front surface. For a spherical surface (i.e., a surface being part of a sphere with radius
R and center position
), the length
L of the light ray is given by
with
being the vector pointing from the ray’s starting position to the sphere’s center. The intersection point is again calculated by Equation (
1) and marks the starting point for the next ray. It is worth noting that we intentionally decided to let the rays be reflected even when the intersection lies outside of the aperture of the element. By allowing this, no rays are deleted during the calculation, and the 3D output enables the user to quickly check for potential clipping of beams.
The direction
of the new ray depends on the incident ray’s direction
and on the type of the optical element. In the context of a mirror, the law of reflection defines the new ray’s direction
where
is the surface normal in the intersection point
between the mirror surface and the ray. For a plane mirror,
is identical to the element’s normal; for a spherical mirror, the normal can be calculated by the normalized distance of
.
Diffraction of a light ray at the surface of a reflection grating is calculated by adding the reciprocal grating vector
to the parallel component
of the incident ray’s wave vector
. The reciprocal grating vector and wave vector are defined by
where
g is the line spacing,
the unit vector pointing perpendicular to the grating lines and the grating’s normal, and
the wavelength of the incoming ray. The parallel (p) and normal (n) components of the incoming ray’s wave vector are given by
Adding the reciprocal wave vector
m-times to the incoming ray’s parallel component
gives the diffracted ray’s parallel wave vector component
with
m being the diffraction order. Note that the absolute value of the wave vector remains constant, since the wavelength does not change during the diffraction process. The output wave vector
as well as the diffracted ray direction
reads
To describe refraction effects, LaserCAD uses ABCD matrices rather than applying Snell’s law at curved surfaces. Since LaserCAD was intended for modeling optical setups including laser radiation, all scenarios should fulfill the paraxial condition and therefore be suitable for applying optical matrices. In this approximation, elements like lenses can be described completely by their focal length, so that detailed knowledge about surface curvature, material and refractive index is not needed. The elements of optical matrices, in addition, allow for a quick characterization of the entire
. To apply the ABCD matrix formalism in 3D, the vector
of the incident ray has to be split into its normal (
n), radial (
d) and sagittal (
s) components, which are sketched in
Figure 2:
The radial vector
is defined by the difference between the intersection point
and the lens center
, while the sagittal direction
is perpendicular to the meridional
-
-plane and the normal vector
is identical to the components normal. The meridional component
as well as the sagittal component
of
is approximated to be constant during refraction.
From these components the characteristic parameters
and
, describing the distance and divergence of a ray from the optical axis, are derived as
and can be inserted in the well known vector matrix formalism to compute the outgoing parameters
and
[
18,
20].
The refracted ray’s direction
is then given by
In addition to geometrical optics, LaserCAD also includes diffraction effects—as they occur, e.g., when using finite focal spot sizes—by means of Gaussian optics. Gaussian beams can be described by the combination of their central axis implemented as a 1D ray and their complex
q-parameter
with
x being the distance from the beam waist’s position on the axis and
its Rayleigh length [
18,
20]. Any effect of optical elements will be described by changing the axis analog to the algorithms described above and then calculating
according to the matrix formalism for Gaussian beams [
20,
21]
4. Code Examples
To show the general handling of LaserCAD, we will present a few use cases as examples. The following code first constructs a magnifying 2-lens Kepler-type telescope and then sends a square beam through it, consisting of 5 × 5 individual rays, each initially separated by 2 mm in the lateral direction. All length values in LaserCAD are given in mm, beam divergence values are given in radians, and turning angles, e.g., of mirrors, are given in degrees.
![Applsci 15 11893 i001 Applsci 15 11893 i001]()
Beams (or individual rays) and lenses are subsequently added to the
container object, which handles the positioning of the elements by advancing the optical axis according to the
function. The diameter of the second lens is changed by the aperture command, which also causes an automatic change in the second lens’s mount to a fitting 2″ model. The 3D rendered model will be produced by the
function; the result is shown in
Figure 3. Rays, lenses, default mounts and posts are all placed and fit to the default beam height of 80 mm, a value that can be changed easily by altering the position
. The necessary line of code
![Applsci 15 11893 i002 Applsci 15 11893 i002]()
will lead to the output of
Figure 4, where a new 1/2″ post holder and post were automatically inserted to fit to the new beam height.
To demonstrate the use and capabilities of mirror assemblies, we show the code, which will construct an anastigmatic mirror telescope.
![Applsci 15 11893 i003 Applsci 15 11893 i003]()
After the initialization of the
, a light source is defined and added. In this case it is a cylindrical beam with a radius of 2 mm. With the
function, the optical axis is advanced by 350 mm, which creates an equally long beam before adding the first mirror. The orientation of mirrors is usually defined indirectly in their constructor with the help of their deflection angles
and
(e.g., in the third line by phi = 0, theta = 180 − 8). These angles describe how the reflected beam is rotated with respect to the incoming beam. While the first angle gives the desired beam deflection in the
plane, the second gives the deflection out of this plane. A perfect back reflection of the beam would be achieved by choosing
, a plane mirror for
deflection by
. To avoid blocking the path of the outgoing beam by previous optical elements, both mirrors need to be rotated from
incidence. In this case, an angle of
was chosen in both directions,
and
, equally, to reduce astigmatism as proposed in [
22]. Curved mirrors are furthermore defined via their radius of curvature, which was chosen to be 250 mm and leads to a necessary distance of 250 mm between the mirrors, which was performed again by the
function. The last propagation call sets the length of the outgoing beam to 350 mm.
Figure 5 shows the complete setup.
To change in the second mirror mount from the Polaris™ K1 [
23] to the KS1 mount [
24] from Thorlabs™, the following line:
![Applsci 15 11893 i004 Applsci 15 11893 i004]()
is executed, that also changes the post from 1" to the adjustable 0.5″ post.
To test the calculation of the spectral phase for ultrashort laser pulse analysis with LaserCAD, a pulse stretcher using reflective gratings for a chirped pulse amplification setup [
25] was modeled in LaserCAD and Mathematica™ [
8] and the lengths and positions of the different rays were compared. The rendered output of both scenarios is shown in
Figure 6. The output shows the expected shape of an Offner-type stretcher setup, with LaserCAD having incorporated the opto-mechanical periphery as well. To validate the physical properties, the group delay dispersion was calculated by summing the ray lengths and calculating the derivative of this length with respect to wavelength. The result of LaserCAD was computed to
showing less than
deviation from the Mathematica™ computation of
as well as from the theoretical formula of Treacy
[
26]. The whole stretcher was scripted in about 100 lines of Python code, including comments, and took only a few seconds to render on a standard desktop PC using an Intel™ Xeon™ W-2123 processor with 3.60 GHz and four cores. Regarding the performance, it should be mentioned that the computation time for the actual ray tracing and positioning of the optics is, in all tested scenarios, negligible against the rendering time from FreeCAD for the 3D output, which in the current version 1.0.0 uses only the processor and a single core. Still, even a whole chirped pulse amplification laser system was computed and rendered in less than one minute on the aforementioned PC. A template of it can be found in the modules folder of the LaserCAD project [
9].
Scenarios like the previous ones with all optical elements were benchmarked against professional ray tracing software tools, including COMSOL and Optica [
7,
8], and showed good agreement. Taking the focal spot size of a concave mirror, for example, the Comsol calculation showed a maximal spread of
, whereas LaserCAD calculated it to be
, resulting in a deviation of about 1‰. The report of these comparisons is published in the project’s manual folder on GitHub [
27].
6. Discussion
We designed an open-source parametric software toolkit for scripting and rendering complex optical setups with few lines of code and high flexibility of used models and objects. The vast variety of predefined professional optomechanics, together with easy-to-adjust optics and customizable ray-tracing algorithms with well-set default values, make it possible to visualize setups with a minimal amount of required parameters. Since the output is produced by a state-of-the-art CAD program, the user has an unprecedented ability to post-process and complete the output with further details and preconstructed objects like vacuum chambers and more. To the best of our knowledge, this synergy, which forms a unified workflow allowing both optical and mechanical aspects to be treated simultaneously, renders the LaserCAD software framework unique among all comparable solutions.
Another application that shows the potential of LaserCAD is the automated generation of alignment aids, such as spacers or simple mounts, which can subsequently be 3D printed to facilitate the practical realization of the setup in the laboratory. This approach has already been realized in our group to accelerate and streamline the construction of a compressor by undergraduates. The use of the popular Python programming language not only makes the software beginner-friendly but also enables possible collaborations with other ray-tracing, machine learning and optimization software packages, either as directly imported Python modules or via APIs to professional optic design software like Quadoa [
29]. In this manner, LaserCAD could be used for preliminary prototyping of projects before the optics positions can be transferred to specialized simulation software tools.
In contrast to commercial software packages such as Zemax or Fred, the focus of LaserCAD does not lie in the high-performance tracing of millions of rays or in the microscopic optimization of focal spot sizes. Instead, the main goal is the realistic visualization and mechanical consistency of complete laboratory setups, using only the minimal number of rays necessary to represent the optical beam path in a meaningful and computationally efficient way. This makes the program particularly suited for experimental planning and educational purposes, where conceptual clarity and spatial awareness are more important than sub-micron precision. In the near future we plan the inclusion of LightPipes [
30] for wave optics simulations.