traceDirectedRays
R2026bTrace rays from specific origins along specific directions through optical system
Since R2026b
Description
traces rays through the optical system using additional options specified by one or more
name-value arguments. For example, rayBundle = traceDirectedRays(opsys,Name=Value)Directions=[0 0.1 1] specifies a
ray direction with direction cosines along the global x-,
y-, and z-axes.
Examples
Trace a ray parallel to the optical axis from a point located before the first surface.
Load a double Gauss lens from a ZMX file into the workspace.
First, create a double Gauss optical system.
opsys = zmximport("DoubleGaussLens.zmx");Create a field point at a global position.
fp = fieldPoint(ReferenceFrame="Global",Position=[0 3 -2]);
opsys.FieldPoints(1) = fp;Trace rays from the field point.
rayBundle = traceDirectedRays(opsys);
Display the optical system and add the traced rays.
hv = view2d(opsys); addRays(hv,rayBundle)

Load a double Gauss lens from a ZMX file into the workspace.
Create a double Gauss optical system.
opsys = zmximport("DoubleGaussLens.zmx");Define multiple origin points and ray directions.
origins = [0 0 -3; 0 0 -4; 0 1 -3; 0 -1 -2]; dirs = [0 0 1; 0 cosd(75) cosd(15); 0 cosd(80) cosd(10); 0 cosd(65) cosd(25)];
Trace rays at a single wavelength with all ray properties.
lambda = 550;
rayBundle = traceDirectedRays(opsys,Origins=origins,Directions=dirs,Wavelengths=lambda,RayProperties="All");Display the optical system in 2-D and add the traced rays.
hv = view2d(opsys); addRays(hv,rayBundle)

Input Arguments
Optical system, specified as an opticalSystem object.
Name-Value Arguments
Specify optional pairs of arguments as
Name1=Value1,...,NameN=ValueN, where Name is
the argument name and Value is the corresponding value.
Name-value arguments must appear after other arguments, but the order of the
pairs does not matter.
Example:
rayBundle = traceDirectedRays(opsys,Directions=[0 0.1 1]) specifies a
ray direction with direction cosines along the global x-,
y-, and z-axes.
Starting points for ray tracing, specified as one of these values:
N-by-3 numeric matrix — Each row contains the [x y z] global coordinates for one origin point. N is the number of rays.
Array of
FieldPositionobjects — Each field point must have a"Global"or"Object"reference frame.
By default, the starting field points are the FieldPosition
objects in the FieldPoints property of the opticalSystem
object, defined relative to a global or object coordinate system. If the optical
system does not contain any field points, then the function uses a field point at the
global position [0 0 −0.2(Zext)], where
Zext is the total axial extent of the
optical system geometry along the global z‑axis.
Ray direction cosines, specified as one of these options:
1-by-3 numeric vector — The direction cosines of a single ray along the x-, y-, and z-axes in global coordinates. The function traces this direction from every origin.
N-by-3 numeric matrix — The direction cosines of N rays. Each row contains the direction cosines of a ray along the x-, y-, and z-axes in global coordinates. The function traces all N directions from every origin. N is the number of rays.
The function normalizes the directions automatically, so you do not need to normalize each row.
Data Types: double
Wavelengths for ray tracing, specified as an M-element numeric vector, in nanometers. The function traces every ray at each wavelength. M is the number of wavelengths.
Data Types: double
Additional ray properties to compute, specified as a string scalar, string array, character vector, or cell array of character vectors with one or more of these values.
The traceDirectedRays function returns the specified ray
properties as additional fields in the RayData property of rayBundle. Each value
of RayProperties, except "All", creates a
field of the same name in RayData.
RayProperties Value | Field Value in RayData |
|---|---|
| Fresnel reflection and transmission coefficients at each interface, bulk transmission and phase shift, and the total transmittance through the optical system, represented as a structure with these fields.
|
| Polarization transformation matrices for each ray and surface intersection, represented as a structure with these fields.
|
| Adds all additional ray properties to
|
Data Types: string | char | cell
Output Arguments
Traced ray data, returned as an array of RayBundle
objects.
Version History
Introduced in R2026b
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Seleccione un país/idioma
Seleccione un país/idioma para obtener contenido traducido, si está disponible, y ver eventos y ofertas de productos y servicios locales. Según su ubicación geográfica, recomendamos que seleccione: .
También puede seleccionar uno de estos países/idiomas:
Cómo obtener el mejor rendimiento
Seleccione China (en idioma chino o inglés) para obtener el mejor rendimiento. Los sitios web de otros países no están optimizados para ser accedidos desde su ubicación geográfica.
América
- América Latina (Español)
- Canada (English)
- United States (English)
Europa
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)