Ray tracing
The ray tracer sends rays through the optics in a scene. Lenses bend them by their focal length, mirrors fold them, splitters branch them, apertures clip them and detectors stop them.
Trace it
Section titled “Trace it”The beam expander of Curd et al. (2015), Fig. 1A: a lens of 45 mm then a lens of 400 mm, 445 mm apart.
trace_bundle sends a bundle of rays from the laser; each ray becomes a beam in the drawing.
# The x8.9 beam expander of Curd et al., Methods 88, 37-47 (2015), Fig. 1A, traced (1 unit = 4 mm)from optodraw import Laser, Lens, Scenefrom optodraw.core.raytrace import trace_bundle
scene = Scene(title="Beam expander", platform="free_space")laser = scene.add(Laser(center=(-78, 0), wavelength=488, label="488 nm laser"))lens1 = scene.add(Lens(center=(-58, 0), focal_length=45 / 4, aperture=6, label="f = 45 mm"))lens2 = scene.add(Lens(center=(-58 + (45 + 400) / 4, 0), focal_length=400 / 4, aperture=24, label="f = 400 mm"))rays = trace_bundle(scene, (laser, "out"), rays=7, width=2.0, exit_length=16)for ray in rays: scene.add(ray.as_beam(wavelength=488, width=0.25))scene.fit_frame(margin=8)sceneThe traced rays carry numbers you can check:
# How much wider is the beam after the expander?start = max(abs(ray.points[0].y) for ray in rays)end = max(abs(ray.points[-1].y) for ray in rays)print(f"{end / start:.1f} times wider (400 mm / 45 mm = {400 / 45:.1f})")8.9 times wider (400 mm / 45 mm = 8.9)
Options
Section titled “Options”| Argument | Does |
|---|---|
rays |
How many rays in the bundle |
width |
The bundle’s width at the source |
divergence_deg |
Spread from a point, like a lamp or a fibre tip |
exit_length |
How far a ray runs after the last part |
mode |
"physical" (true hit points) or "schematic" (snaps to part centres) |
trace_branched(scene, (laser, "out")) traces one ray that splits at every splitter.
What it supports
Section titled “What it supports”Thin lenses and curved mirrors (in the plane and in height), flat mirrors, splitters and dichroics by wavelength, refraction by index, gratings by order, apertures, periscopes, retroreflectors and absorbers. In the editor, Trace re-traces live as you move a part.
How it works
Section titled “How it works”Each part declares its optical faces: a segment, a kind and its numbers (focal length, index, cutoff). The
tracer finds each ray’s next face, applies it, and carries the ray’s height along, so a 3D bundle comes to
a true focus. A part’s optical_interfaces() returns its faces; None lets the tracer build them from the
part’s type.
from optodraw.core.raytrace import OpticalInterface
OpticalInterface(p1=(0.0, -5.0), p2=(0.0, 5.0), # the face, in the part's own frame kind="lens", # lens | mirror | beam_splitter | dichroic | refract # | grating | aperture | filter | relay | retro # | absorber | schematic efl=30.0) # the focal length; a mirror has f = R/2Where it falls short
Section titled “Where it falls short”One wavelength per trace. Lenses and curved mirrors are thin elements: no thick-lens aberrations. The bundle is geometric, with no Gaussian waist or diffraction limit. Plain mirrors reflect from both sides.
Curd, A. et al. Construction of an instant structured illumination microscope. Methods 88, 37-47 (2015). doi:10.1016/j.ymeth.2015.07.012