Artificial Intelligence doing Ray Tracing with FreeCAD and Optics Workbench

04 Dec 2026 - tsp
Last update 04 Dec 2026
Reading time 7 mins

Watch on YouTube Watch on YouTube β†—

In my first article about Artificial Intelligence doing CAD[4] I gave an LLM agent access to a real CAD system and let it inspect the geometry it had produced. The TechDraw additions[5] took that a step further and used the same geometry to prepare drawings for human workshops. For optical assemblies the Optics Workbench provides a convenient design environment.

Suppose one is designing a lens assembly or a system of mirrors. The optical surfaces, their positions and the space available for mounts and apertures all put constraints on the same design. In FreeCAD, one can model those parts together and use the Optics Workbench to trace rays from the source through the assembly to a detector. A change to a mirror angle or a lens spacing can then be checked against the beam path and the positions of the detector hits. The small parabolic mirror[6] shown previously shows this approach on a mirror designed to collect light inside a transmission electron microscope, where the shape of the surrounding holder was part of the ray-tracing model.

Version 0.0.3 gives an agent access to the optional Optics Workbench[2] through mcpFreeCAD[3], so it can iterate on the design and run a geometrical ray trace in the same FreeCAD document. The examples below illustrate a few steps in that workflow using simple layouts. The release also adds several fixes and more capabilities to the TechDraw features discussed lately.

FreeCAD rendering of the full two-grating setup, showing the point source, both lenses, the grating plates and the detector

From CAD Geometry to a Ray Trace

The starting point is an FreeCAD document. A solid can become a lens, a surface can act as a mirror and a baffle can be assigned as an absorber by the appropriate relations. The bridge creates native Optics Workbench objects linked to the source shapes. The lens and its optical properties are available in FreeCAD. With the compatible add-on installed in the FreeCAD instance, mcpFreeCAD exposes the available optics tools to the agent. This works with a remote FreeCAD instance as well.

CAD material cards describe properties of the solid for the mechanical model. The optical model supplies the refractive index the workbench uses to simulate the propagation of a ray. One lens can use a constant index, while another uses an installed Sellmeier model[7] to evaluate the index at the rays wavelength. The material assignment can be made per solid to model various components in the same setup.

An agent can create individual rays or a parallel beam, run the trace and read the hit coordinates. It can also request the FreeCAD viewport as an image through MCP. The coordinates give the location of each hit on an optical element or detector. An oblique view shows the route through the assembly and helps locate a misplaced element or an unexpected interception. After a change to the scene, a fresh trace provides the results for comparison.

The two views below show a separate three-dimensional trace. The first mirror turns a parallel beam from the X direction into Y. The second mirror turns the beam upwards along Z, and all nine rays reach the detector above it. The view from the other side makes the two reflection points easier to see.

Two oblique FreeCAD views of nine rays travelling from a source to the first mirror, turning towards the second mirror and then rising to a detector

The same kind of tracing can be used with curved surfaces and the surrounding hardware. In the mirror project linked above, the parabolic surface and its holder were already part of the CAD model used for the optical check[6].

Three-dimensional Optics Workbench trace of rays leaving the sample region, striking a parabolic mirror and travelling along the machined holder

A Point Source and Two Reflection Gratings

The first example starts with a fan of rays emitted from one point. The first lens makes them nearly parallel. The two colours represent two different wavelengths. At the first reflection grating the colours take different directions, and a second grating redirects them towards the final lens. That lens brings the rays back towards the detector.

The two gratings were prepared in the native Optics Workbench. The MCP tools can work with that existing models, set up the rays, trace them and read back where they intersect the optical elements. In this example the trace returned ten hits at each grating and ten at the detector. The detector close-up shows the last part of the path, where the nearly parallel bundles converge again.

Top view of the complete folded path from the point source through both gratings to the detector

Close-up of the final lens bringing two bundles of rays towards the detector plane at the right

Moving a Lens in a Four-Lens Train

The second example starts with parallel rays passing through multiple lenses. The second lens moves 13 mm downstream along the optical axis, and the rays are traced again with the detector in the same position. All nine rays still reached it, but the span between the outermost hits changed from about 10.72 mm to 9.76 mm.

Two views of the four-lens setup with the same detector on the right, before the move above and with the second lens 13 mm downstream below

Then an ordinary CAD solid is placed at the edge of the incoming beam and assigned as an absorber. Three rays end at the baffle and six reach the detector. The trace shows which rays are intercepted and the agent can check the count by reading the hits on each object.

What Changed in TechDraw

The previous article[5] used pitch circles to describe repeated holes on a flange. It can be easier to give each hole an identifier and put its coordinates in a table. The new tools build that table from selected hole centres relative to an explicitly chosen origin and axes. Repeated holes of the same size can also get a measured diameter callout with a quantity. A blind-hole callout uses a separate measured depth along the bore axis.

There is now also support for explicit thread callouts and for the conventional partial root circle in supported thread end views. The thread designation, pitch and tolerance class come from the design requirements. One reason this matters is that a circular projection of a drilled hole gives the agent very little to go on when deciding what the workshop is supposed to do with it.

Datums and supported geometrical tolerance frames can now be attached to inspected features. Section hatching has configurable patterns, scale and orientation, and the drawing checks cover printed units, feature attachments and more cases where rendered text crosses linework. The checks can flag a misplaced callout or inconsistent units, while reading the drawing as a whole helps to determine whether it communicates the requirements someone needs to make and inspect the part.

References

This article is tagged:


Data protection policy

Dipl.-Ing. Thomas Spielauer, Wien (webcomplainsQu98equt9ewh@tspi.at)

This webpage is also available via TOR at http://rh6v563nt2dnxd5h2vhhqkudmyvjaevgiv77c62xflas52d5omtkxuid.onion/

Valid HTML 4.01 Strict Powered by FreeBSD IPv6 support