Skip to content

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
julia
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 the ray (and its end point, if it has an intersection) with a point

Polarization kwargs

  • show_polarization = false: overlay the E-field curve for a PolarizedRay (throws an ArgumentError for 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 the t = 0 snapshot Re{E⊥·exp(i·k·s)} along the accumulated optical path s. Values finer than plotted length / 2000 are clamped with a warning.

  • pol_amplitude = nothing: curve amplitude [m] at the maximum |E⊥|, default pol_λ/4

  • pol_ppl = 32: sample points per pol_λ along the curve

  • pol_color = :crimson: field curve color

  • pol_linewidth = 2.0: field curve line width

Makie kwargs

  • color = :blue: ray color. color = :wavelength draws each ray in the display color of its wavelength, see wavelength_color, e.g. to show the rays of white light after a prism; color = (:wavelength, 0.3) sets the opacity

  • linewidth = 1.0: ray line width

  • transparency = true: ray transparency

Additional kwargs are passed into the linesegments plot of the ray.

source

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
julia
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 a Beam{T, <:PolarizedRay} (throws an ArgumentError for 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 the t = 0 snapshot Re{E⊥·exp(i·k·s)} along the accumulated optical path s. Values finer than plotted length / 2000 are clamped with a warning.

  • pol_amplitude = nothing: curve amplitude [m] at the maximum |E⊥|, default pol_λ/4

  • pol_ppl = 32: sample points per pol_λ along the curve

  • pol_color = :crimson: field curve color

  • pol_linewidth = 2.0: field curve line width

source

Groups of beams ​

BeamletOptics.render! Method
julia
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.

source

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.

julia
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
julia
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.

julia
wavelength_color(450e-9)   # blue
wavelength_color(650e-9)   # red
source

Polarization 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.

julia
render!(ax, beam; show_polarization=true, pol_color=:orange)