Rendering rays and beams
Rays and beams are drawn as 3D lines: all ray segments of a ray, a beam (including its child beams) or a beam group are drawn by a single linesegments plot. A ray without an intersection is drawn with the finite length flen, since its actual length is infinite. live_render! draws the same plot and updates it after a solve, see Live rendering. Example renderings can be found in the Basic rays, Basic beam and Beam groups sections.
Single rays
BeamletOptics.render! Method
render!(axis, ray; kwargs...)Renders a ray as a 3D line into the specified axis.
Keyword args
flen = 1.0: plotted length of the infinite ray in case of no intersection in [m]show_pos = false: marks the starting position of theray(and its end point, if it has an intersection) with a point
Polarization kwargs
show_polarization = false: overlay the E-field curve for aPolarizedRay(throws anArgumentErrorfor a non-polarized ray)pol_λ = nothing: visualization wavelength [m], default = total plotted length / 20. This is a plotting parameter, not the physical ray wavelength; the curve shows thet = 0snapshotRe{E⊥·exp(i·k·s)}along the accumulated optical paths. Values finer thanplotted length / 2000are clamped with a warning.pol_amplitude = nothing: curve amplitude [m] at the maximum |E⊥|, defaultpol_λ/4pol_ppl = 32: sample points perpol_λalong the curvepol_color = :crimson: field curve colorpol_linewidth = 2.0: field curve line width
Makie kwargs
color = :blue: ray color.color = :wavelengthdraws each ray in the display color of its wavelength, seewavelength_color, e.g. to show the rays of white light after a prism;color = (:wavelength, 0.3)sets the opacitylinewidth = 1.0: ray line widthtransparency = true: ray transparency
Additional kwargs are passed into the linesegments plot of the ray.
Beams of rays
A Beam is rendered by drawing every ray of the beam tree, including all child beams created at beamsplitters. Keyword arguments such as color or linewidth are passed on to the plot of the segments.
BeamletOptics.render! Method
render!(axis, beam; kwargs...)Render the entire beam of rays into the specified 3D-axis. All ray segments are drawn by a single linesegments plot.
Keyword args
Refer to the plotting method of the AbstractRay for a list of keyword arguments.
Polarization kwargs
show_polarization = false: overlay the E-field curve for aBeam{T, <:PolarizedRay}(throws anArgumentErrorfor a beam of non-polarized rays). The curve is drawn once for the whole beam tree, not per ray, to preserve phase continuity.pol_λ = nothing: visualization wavelength [m], default = total plotted length / 20. This is a plotting parameter, not the physical ray wavelength; the curve shows thet = 0snapshotRe{E⊥·exp(i·k·s)}along the accumulated optical paths. Values finer thanplotted length / 2000are clamped with a warning.pol_amplitude = nothing: curve amplitude [m] at the maximum |E⊥|, defaultpol_λ/4pol_ppl = 32: sample points perpol_λalong the curvepol_color = :crimson: field curve colorpol_linewidth = 2.0: field curve line width
Groups of beams
BeamletOptics.render! Method
render!(axis, beam_group; kwargs...)Renders the BeamletOptics.AbstractBeamGroup into the specified axis. The ray segments of all rendered beams are drawn by a single linesegments plot.
Keywords arguments
render_every = 5: renders only every e.g. fifth individual beam in the group
Refer to the plotting method of the AbstractRay for further keyword arguments. With show_polarization = true, each rendered beam has its own field curve.
Coloring by wavelength
color = :wavelength draws each ray in the display color of its own wavelength, e.g. to show white light that is dispersed by a prism: child beams that leave a dispersive element keep the color of their wavelength, and every beam of a beam group gets its own color. The opacity is set by color = (:wavelength, 0.3). The same option colors the envelope of Gaussian beamlets, segment by segment. live_render! takes it as well.
render!(ax, beam_group; color = :wavelength)
render!(ax, gauss; color = (:wavelength, 0.5))The color of a wavelength is available without a plotting backend via wavelength_color, e.g. to color other plots consistently:
BeamletOptics.wavelength_color Function
wavelength_color(λ) -> NTuple{3, Float64}The display color (r, g, b) (each in [0, 1], sRGB) of light of the vacuum wavelength λ [m], e.g. to draw rays in the color of their wavelength, see the color = :wavelength option of render!. Uses the piecewise linear approximation of Dan Bruton (violet at 380 nm over blue, cyan, green, yellow and orange to red at 780 nm) with a gamma of 0.8, and the intensity falls off to 30 % towards both ends of the visible range (380 to 420 nm and 700 to 780 nm).
Outside of 380 to 780 nm there is no visible color: the color of the nearest end of the spectrum is returned, i.e. a dim violet for UV and a dim red for IR, such that rays of an invisible wavelength are still drawn, and the color stays continuous. The result is a perceptual approximation for plots, not a colorimetric conversion.
The function is plain Julia and needs no plotting backend. Throws an ArgumentError unless λ is positive and finite.
wavelength_color(450e-9) # blue
wavelength_color(650e-9) # redPolarization overlay
For a PolarizedRay or a Beam of polarized rays, render!(ax, beam; show_polarization=true) overlays a curve that shows the electric field component perpendicular to the ray direction along the optical path. The appearance of the curve is controlled via the pol_* keyword arguments listed above. Passing show_polarization=true for non-polarized rays throws an ArgumentError. An example is shown in the Polarized rays section.
render!(ax, beam; show_polarization=true, pol_color=:orange)