Surfaces API Reference
The src.geometric_surface module contains all geometric optical surface types. Each surface implements differentiable ray intersection and Snell's law refraction.
Base Class
Surface
Base class for all geometric surfaces. Implements Newton's method intersection (with one differentiable step) and vector Snell's law refraction.
src.geometric_surface.Surface
Bases: DeepObj
Base class for all geometric optical surfaces.
A surface sits at axial position d (mm) in the global coordinate
system, has an aperture radius r (mm), and separates two optical
media. Subclasses override :meth:_sag and :meth:_dfdxy to define
their shape.
Ray–surface interaction is handled by three stages, implemented in
:meth:ray_reaction:
- Coordinate transform – ray is brought into the local surface frame.
- Intersection – solved via Newton's method (:meth:
newtons_method), using a non-differentiable iteration loop followed by a single differentiable Newton step to enable gradient flow. - Refraction / reflection – vector Snell's law (:meth:
refract) or specular reflection (:meth:reflect).
Attributes:
| Name | Type | Description |
|---|---|---|
d |
Tensor
|
Axial position of the surface vertex [mm]. |
r |
float
|
Aperture radius [mm]. |
mat2 |
Material
|
Optical material on the transmission side. |
is_square |
bool
|
If |
tolerancing |
bool
|
When |
Initialize a generic optical surface.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
r
|
float
|
Aperture radius [mm]. |
required |
d
|
float
|
Axial position of the surface vertex [mm]. |
required |
mat2
|
str or Material
|
Material on the transmission side
(e.g. |
required |
pos_xy
|
list[float]
|
Lateral offset |
[0.0, 0.0]
|
vec_local
|
list[float]
|
Local normal direction.
Defaults to |
[0.0, 0.0, 1.0]
|
is_square
|
bool
|
Use a square aperture.
Defaults to |
False
|
device
|
str
|
Compute device. Defaults to |
'cpu'
|
Source code in src/geometric_surface/base.py
init_from_dict
classmethod
ray_reaction
Compute the output ray after intersection and refraction/reflection.
Transforms the ray to the local surface frame, solves the intersection via Newton's method, applies vector Snell's law (or specular reflection), then transforms back to global coordinates.
When tolerancing is active, mat2_n_error is added to n2 to
simulate refractive-index manufacturing error.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ray
|
Ray
|
Incident ray bundle. |
required |
n1
|
float
|
Refractive index of the incident medium. |
required |
n2
|
float
|
Refractive index of the transmission medium. |
required |
refraction
|
bool
|
If |
True
|
Returns:
| Name | Type | Description |
|---|---|---|
Ray |
Updated ray bundle after the surface interaction. |
Source code in src/geometric_surface/base.py
intersect
Solve ray-surface intersection in local coordinate system.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ray
|
Ray
|
input ray. |
required |
n
|
float
|
refractive index. Defaults to 1.0. |
1.0
|
Source code in src/geometric_surface/base.py
newtons_method
Solve intersection by Newton's method in local coordinate system.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ray
|
Ray
|
input ray. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
t |
tensor
|
intersection time. |
valid |
tensor
|
valid mask. |
Source code in src/geometric_surface/base.py
refract
Calculate refracted ray according to Snell's law in local coordinate system.
Normal vector points from the surface toward the side where the light is coming from. d is already normalized if both n and ray.d are normalized.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ray
|
Ray
|
incident ray. |
required |
eta
|
float
|
ratio of indices of refraction, eta = n_i / n_t |
required |
Returns:
| Name | Type | Description |
|---|---|---|
ray |
Ray
|
refracted ray. |
References
[1] https://registry.khronos.org/OpenGL-Refpages/gl4/html/refract.xhtml [2] https://en.wikipedia.org/wiki/Snell%27s_law, "Vector form" section.
Source code in src/geometric_surface/base.py
reflect
Calculate reflected ray in local coordinate system.
Normal vector points from the surface toward the side where the light is coming from.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ray
|
Ray
|
incident ray. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
ray |
Ray
|
reflected ray. |
References
[1] https://registry.khronos.org/OpenGL-Refpages/gl4/html/reflect.xhtml [2] https://en.wikipedia.org/wiki/Snell%27s_law, "Vector form" section.
Source code in src/geometric_surface/base.py
normal_vec
Calculate surface normal vector at the intersection point in local coordinate system.
Normal vector points from the surface toward the side where the light is coming from.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ray
|
Ray
|
input ray. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
n_vec |
tensor
|
surface normal vector. |
Source code in src/geometric_surface/base.py
to_local_coord
Transform ray to local coordinate system.
When tolerancing is active, applies manufacturing error perturbations: d_error (axial shift), decenter_x/y_error (lateral shift), and tilt_error (rotation about the x-axis).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ray
|
Ray
|
input ray in global coordinate system. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
ray |
Ray
|
transformed ray in local coordinate system. |
Source code in src/geometric_surface/base.py
to_global_coord
Transform ray to global coordinate system.
When tolerancing is active, reverses the manufacturing error
perturbations applied in :meth:to_local_coord.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ray
|
Ray
|
input ray in local coordinate system. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
ray |
Ray
|
transformed ray in global coordinate system. |
Source code in src/geometric_surface/base.py
sag
Calculate sag (z) of the surface: z = f(x, y).
Valid term is used to avoid NaN when x, y exceed the data range, which happens in spherical and aspherical surfaces.
Calculating r = sqrt(x2, y2) may cause an NaN error during back-propagation. Because dr/dx = x / sqrt(x2 + y2), NaN will occur when x=y=0.
Source code in src/geometric_surface/base.py
dfdxyz
Compute derivatives of surface function. Surface function: f(x, y, z): sag(x, y) - z = 0. This function is used in Newton's method and normal vector calculation.
There are several methods to compute derivatives of surfaces
[1] Analytical derivatives: The current implementation is based on this method. But the implementation only works for surfaces which can be written as z = sag(x, y). For implicit surfaces, we need to compute derivatives (df/dx, df/dy, df/dz). [2] Numerical derivatives: Use finite difference method to compute derivatives. This can be used for those very complex surfaces, for example, NURBS. But it may suffer from numerical instability when the surface is very steep. [3] Automatic differentiation: Use torch.autograd to compute derivatives. This can work for almost all the surfaces and is accurate, but it requires an extra backward pass to compute the derivatives of the surface function.
Source code in src/geometric_surface/base.py
d2fdxyz2
Compute second-order partial derivatives of the surface function f(x, y, z): sag(x, y) - z = 0. This function is currently only used for surfaces constraints.
Source code in src/geometric_surface/base.py
is_valid
is_within_boundary
Valid points within the boundary of the surface.
Source code in src/geometric_surface/base.py
is_within_data_range
max_height
surface_with_offset
Calculate z coordinate of the surface at (x, y).
This function is used in lens setup plotting and lens self-intersection detection.
Source code in src/geometric_surface/base.py
surface_sag
Calculate sag of the surface at (x, y).
This function is currently not used.
Source code in src/geometric_surface/base.py
get_optimizer_params
Get optimizer parameters for different parameters.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lrs
|
list
|
learning rates for different parameters. |
[0.0001]
|
optim_mat
|
bool
|
whether to optimize material. Defaults to False. |
False
|
Source code in src/geometric_surface/base.py
get_optimizer
update_r
init_tolerance
Initialize tolerance parameters for the surface.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tolerance_params
|
dict or None
|
Tolerance for surface parameters. Supported keys (all optional, default values shown): .. code-block:: python |
None
|
References
[1] https://www.edmundoptics.com/knowledge-center/application-notes/optics/understanding-optical-specifications/ [2] https://wp.optics.arizona.edu/optomech/wp-content/uploads/sites/53/2016/08/8-Tolerancing-1.pdf [3] https://wp.optics.arizona.edu/jsasian/wp-content/uploads/sites/33/2016/03/L17_OPTI517_Lens-_Tolerancing.pdf
Source code in src/geometric_surface/base.py
sample_tolerance
Sample one set of random manufacturing errors for the surface.
Error distributions
- r_error: Uniform[-r_tole, 0] (aperture only shrinks).
- d_error: Normal(0, d_tole) axial position shift [mm].
- decenter_x/y_error: Normal(0, decenter_tole) lateral shift [mm].
- tilt_error: Normal(0, tilt_tole) tilt about x-axis [arcmin → rad].
- mat2_n_error: Normal(0, mat2_n_tole) refractive index offset.
Source code in src/geometric_surface/base.py
zero_tolerance
Reset all manufacturing errors to zero (nominal state).
Source code in src/geometric_surface/base.py
sensitivity_score
Compute first-order tolerance sensitivity scores via RSS formula.
For each parameter with a gradient, the score is:
tolerance_range² × gradient², which approximates the variance of
the loss contribution from that parameter's manufacturing error.
Returns:
| Name | Type | Description |
|---|---|---|
dict |
Sensitivity gradients and RSS scores keyed by surface index. |
Reference
[1] Page 10 from: https://wp.optics.arizona.edu/optomech/wp-content/uploads/sites/53/2016/08/8-Tolerancing-1.pdf
Source code in src/geometric_surface/base.py
draw_r
draw_widget
Draw widget for the surface on the 2D plot.
Source code in src/geometric_surface/base.py
create_mesh
Create triangulated surface mesh.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n_rings
|
int
|
Number of concentric rings for sampling. |
32
|
n_arms
|
int
|
Number of angular divisions. |
128
|
color
|
List[float]
|
The color of the mesh. |
[0.06, 0.3, 0.6]
|
Returns:
| Name | Type | Description |
|---|---|---|
self |
The surface with mesh data. |
Source code in src/geometric_surface/base.py
get_polydata
Get PyVista PolyData object from previously generated vertices and faces.
PolyData object will be used to draw the surface and export as .obj file.
Source code in src/geometric_surface/base.py
| Parameter | Type | Description |
|---|---|---|
r |
float |
Aperture radius (mm) |
d |
float |
Axial vertex position (mm), differentiable |
mat2 |
Material |
Material on the transmission side |
is_square |
bool |
Square aperture if True, circular if False |
Key methods:
| Method | Description |
|---|---|
ray_reaction(ray, n1, n2) |
Main interface: intersect + refract/reflect |
intersect(ray, n) |
Ray-surface intersection (overridden by subclass) |
refract(ray, n1, n2) |
Vector Snell's law |
reflect(ray) |
Specular reflection |
sag(x, y) |
Surface height \(z(x, y)\) |
normal_vec(ray) |
Surface normal at intersection |
surf_dict() |
Serialize to dictionary |
get_optimizer_params(lrs) |
Return parameter groups for optimizer |
Spheric
Spherical surface defined by curvature \(c = 1/R\).
src.geometric_surface.Spheric
Bases: Surface
Spherical refractive surface parameterized by curvature.
The sag function is:
.. math::
z(x, y) = \frac{c \rho^2}{1 + \sqrt{1 - c^2 \rho^2}}, \quad
\rho^2 = x^2 + y^2
Attributes:
| Name | Type | Description |
|---|---|---|
c |
Tensor
|
Surface curvature |
Initialize a spherical surface.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
c
|
float
|
Surface curvature |
required |
r
|
float
|
Aperture radius [mm]. |
required |
d
|
float
|
Axial vertex position [mm]. |
required |
mat2
|
str or Material
|
Material on the transmission side. |
required |
pos_xy
|
list[float]
|
Lateral offset |
[0.0, 0.0]
|
vec_local
|
list[float]
|
Local normal direction.
Defaults to |
[0.0, 0.0, 1.0]
|
is_square
|
bool
|
Square aperture flag. Defaults to
|
False
|
device
|
str
|
Compute device. Defaults to |
'cpu'
|
Source code in src/geometric_surface/spheric.py
intersect
Solve ray-surface intersection in local coordinate system using analytical method.
Sphere equation: (x)^2 + (y)^2 + (z - R)^2 = R^2, where R = 1/c Ray equation: p(t) = o + t*d Solve quadratic equation for intersection parameter t.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ray
|
Ray
|
input ray. |
required |
n
|
float
|
refractive index. Defaults to 1.0. |
1.0
|
Returns:
| Name | Type | Description |
|---|---|---|
ray |
Ray
|
ray with updated position and opl. |
Source code in src/geometric_surface/spheric.py
154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 | |
is_within_data_range
Invalid when shape is non-defined.
max_height
init_tolerance
Initialize tolerance parameters for the surface.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tolerance_params
|
dict
|
Tolerance for surface parameters. |
None
|
Source code in src/geometric_surface/spheric.py
sample_tolerance
Randomly perturb surface parameters to simulate manufacturing errors.
zero_tolerance
sensitivity_score
Tolerance squared sum.
Source code in src/geometric_surface/spheric.py
get_optimizer_params
Activate gradient computation for c and d and return optimizer parameters.
Source code in src/geometric_surface/spheric.py
surf_dict
Return surface parameters.
Source code in src/geometric_surface/spheric.py
zmx_str
Return Zemax surface string.
Source code in src/geometric_surface/spheric.py
where \(\rho^2 = x^2 + y^2\).
| Parameter | Type | Description |
|---|---|---|
c |
float |
Curvature \(= 1/R\) in mm\(^{-1}\) (differentiable) |
Has an analytical intersect() solving the sphere-ray quadratic (faster than Newton's method).
Optimizer parameters: [lr_d, lr_c]
Aspheric
Even-asphere surface: spherical base with conic constant and polynomial corrections.
src.geometric_surface.Aspheric
Aspheric(r, d, c, k, ai, mat2, ai2=None, pos_xy=[0.0, 0.0], vec_local=[0.0, 0.0, 1.0], is_square=False, device='cpu')
Bases: Surface
Even-order aspheric surface.
The sag function is:
.. math::
z(
ho) = rac{c\, ho^2}{1 + \sqrt{1-(1+k)c^2 ho^2}} + \sum_{i=2}^{n} a_{2i}\, ho^{2i}, \quad ho^2 = x^2 + y^2
The polynomial starts at the 4th-order term (a4) because the 2nd-order
term competes with the base curvature c.
All coefficients c, k, and ai are differentiable torch
tensors so they can be optimised with gradient descent.
Attributes:
| Name | Type | Description |
|---|---|---|
c |
Tensor
|
Base curvature [1/mm]. |
k |
Tensor
|
Conic constant. |
ai2 |
Tensor or None
|
2nd-order aspheric coefficient (legacy). |
ai |
Tensor
|
Even-order aspheric coefficients
|
Initialize an aspheric surface.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
r
|
float
|
Aperture radius [mm]. |
required |
d
|
float
|
Axial vertex position [mm]. |
required |
c
|
float
|
Base curvature |
required |
k
|
float
|
Conic constant ( |
required |
ai
|
list[float] or None
|
Even-order aspheric coefficients
starting from the 4th-order term: |
required |
mat2
|
str or Material
|
Material on the transmission side. |
required |
ai2
|
float or None
|
2nd-order aspheric coefficient
from legacy data. Included in sag but not optimised.
Defaults to |
None
|
pos_xy
|
list[float]
|
Lateral offset |
[0.0, 0.0]
|
vec_local
|
list[float]
|
Local normal direction.
Defaults to |
[0.0, 0.0, 1.0]
|
is_square
|
bool
|
Square aperture flag.
Defaults to |
False
|
device
|
str
|
Compute device. Defaults to |
'cpu'
|
Source code in src/geometric_surface/aspheric.py
enable_reparam
Optimize normalized parameters while keeping physical coefficients readable.
Source code in src/geometric_surface/aspheric.py
disable_reparam
Write normalized parameters back to physical tensors and remove the transform.
Source code in src/geometric_surface/aspheric.py
update_r
Update surface radius and preserve physical coefficients under reparam.
Source code in src/geometric_surface/aspheric.py
is_within_data_range
Invalid when shape is non-defined.
max_height
get_optimizer_params
Get optimizer parameters for the asphere.
When reparam=True the optimizer targets normalized hidden
parameters so that c, k, and ai live on comparable
scales — designed for single-lr optimizers like BFGS. With
reparam=False (the default), per-order learning-rate scaling
is applied to the raw physical parameters, which is correct for
Adam and other per-parameter-lr optimizers.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lrs
|
list
|
learning rates for |
[0.0001, 0.0001, 0.01, 0.0001]
|
optim_mat
|
bool
|
whether to optimize material. Defaults to False. |
False
|
reparam
|
bool
|
optimize normalized hidden parameters. Defaults to False. |
False
|
Source code in src/geometric_surface/aspheric.py
init_tolerance
Perturb the surface with some tolerance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tolerance_params
|
dict
|
Tolerance for surface parameters. |
None
|
References
[1] https://www.edmundoptics.com/capabilities/precision-optics/capabilities/aspheric-lenses/ [2] https://www.edmundoptics.com/knowledge-center/application-notes/optics/all-about-aspheric-lenses/?srsltid=AfmBOoon8AUXVALojol2s5K20gQk7W1qUisc6cE4WzZp3ATFY5T1pK8q
Source code in src/geometric_surface/aspheric.py
sample_tolerance
Randomly perturb surface parameters to simulate manufacturing errors.
Source code in src/geometric_surface/aspheric.py
zero_tolerance
sensitivity_score
Tolerance squared sum.
Source code in src/geometric_surface/aspheric.py
surf_dict
Return a dict of surface.
Source code in src/geometric_surface/aspheric.py
zmx_str
Return Zemax surface string.
Source code in src/geometric_surface/aspheric.py
| Parameter | Type | Description |
|---|---|---|
c |
float |
Curvature (differentiable) |
k |
float |
Conic constant (differentiable) |
ai |
list[float] |
Polynomial coefficients \([a_4, a_6, a_8, \ldots]\) (differentiable) |
Optimizer parameters: [lr_d, lr_c, lr_k, lr_ai]
Per-order learning rate scaling: \(\text{lr}_{a_{2n}} = \text{lr\_base} / r^{2n}\)
Reparametrization
For L-BFGS optimization, parameters are normalized to \(\sim\mathcal{O}(1)\):
# Enable: stores normalized phi tensors
surface.enable_reparam()
# Disable: restores physical values
surface.disable_reparam()
# Dynamic radius update (preserves physical coefficients)
surface.update_r(new_r)
Aperture
Aperture stop surface. Subclasses Plane with no refraction — only clips rays outside the clear aperture.
src.geometric_surface.Aperture
Bases: Plane
Aperture surface.
Source code in src/geometric_surface/aperture.py
ray_reaction
Compute output ray after intersection and refraction.
draw_widget
Draw aperture wedge on the figure.
Source code in src/geometric_surface/aperture.py
draw_widget3D
Draw the aperture as a circle in a 3D plot.
Source code in src/geometric_surface/aperture.py
create_mesh
Create triangulated surface mesh.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n_rings
|
int
|
Number of concentric rings for sampling. |
32
|
n_arms
|
int
|
Number of angular divisions. |
128
|
color
|
List[float]
|
The color of the mesh. |
[0.0, 0.0, 0.0]
|
Returns:
| Name | Type | Description |
|---|---|---|
self |
The surface with mesh data. |
Source code in src/geometric_surface/aperture.py
get_optimizer_params
Activate gradient computation for d and return optimizer parameters.
Source code in src/geometric_surface/aperture.py
surf_dict
Dict of surface parameters.
zmx_str
Used as the aperture stop in lens systems. Has update_r() for curriculum aperture growth.
Plane
Flat surface (\(z = 0\) in local frame). Base class for Aperture, Mirror, and ThinLens.
src.geometric_surface.Plane
Bases: Surface
Plane surface.
Examples:
- IR filter.
- Lens cover glass.
- DOE base.
The following surfaces inherit from Plane
- Aperture.
- Mirror.
- ThinLens.
Source code in src/geometric_surface/plane.py
intersect
Solve ray-surface intersection in local coordinate system and update ray data.
Source code in src/geometric_surface/plane.py
normal_vec
Calculate surface normal vector at intersection points in local coordinate system.
Normal vector points from the surface toward the side where the light is coming from.
Source code in src/geometric_surface/plane.py
get_optimizer_params
Activate gradient computation for d and return optimizer parameters.
Source code in src/geometric_surface/plane.py
Mirror
Flat mirror surface. Subclasses Plane with reflect() instead of refract().
src.geometric_surface.Mirror
Mirror(r, d, mat2='air', pos_xy=[0.0, 0.0], vec_local=[0.0, 0.0, 1.0], is_square=True, device='cpu')
Bases: Plane
Mirror surface.
Source code in src/geometric_surface/mirror.py
ray_reaction
Compute output ray after intersection and reflection with the mirror surface.
Source code in src/geometric_surface/mirror.py
ThinLens
Ideal thin lens with focal length \(f\). Implements paraxial phase approximation.
src.geometric_surface.ThinLens
ThinLens(r, d, f=100.0, pos_xy=[0.0, 0.0], vec_local=[0.0, 0.0, 1.0], is_square=False, device='cpu')
Bases: Plane
Thin lens surface.
Source code in src/geometric_surface/thinlens.py
get_optimizer_params
Activate gradient computation for f and d and return optimizer parameters.
Source code in src/geometric_surface/thinlens.py
refract
For a thin lens, all rays will converge to z = f plane. Therefore we trace the chief-ray (parallel-shift to surface center) to find the final convergence point for each ray.
For coherent ray tracing, we can think it as a Fresnel lens with infinite refractive index. (1) Lens maker's equation (2) Spherical lens function
Source code in src/geometric_surface/thinlens.py
| Parameter | Type | Description |
|---|---|---|
f |
float |
Focal length in mm (differentiable) |
QTypeFreeform
Forbes Q-polynomial freeform surface (Qbfs). Orthogonal polynomial basis for reduced sensitivity to coefficient errors.
src.geometric_surface.QTypeFreeform
QTypeFreeform(r, d, c, k, qm, mat2, r_norm=None, pos_xy=[0.0, 0.0], vec_local=[0.0, 0.0, 1.0], is_square=False, device='cpu')
Bases: Surface
Q-type (Forbes Qbfs polynomial) freeform surface.
This surface type uses Forbes Q-polynomials to represent rotationally symmetric aspheric departures from a base conic surface. The representation is well-suited for optimization due to the orthogonality of the basis functions.
Attributes:
| Name | Type | Description |
|---|---|---|
c |
tensor
|
Curvature of the base surface (1/radius of curvature) |
k |
tensor
|
Conic constant |
r_norm |
float
|
Normalization radius for Q polynomials (typically equals r) |
qm |
tensor
|
Q polynomial coefficients [a_0, a_1, ..., a_{n-1}] |
Initialize Q-type freeform surface.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
r
|
float
|
Aperture radius of the surface |
required |
d
|
float
|
Distance from origin to surface vertex |
required |
c
|
float
|
Curvature of the base surface (1/radius of curvature) |
required |
k
|
float
|
Conic constant (k=0 for sphere, k=-1 for paraboloid) |
required |
qm
|
list
|
Q polynomial coefficients [a_0, a_1, ..., a_{n-1}] |
required |
mat2
|
str or Material
|
Material after the surface |
required |
r_norm
|
float
|
Normalization radius. Defaults to r. |
None
|
pos_xy
|
list
|
Surface center position [x, y]. Defaults to [0, 0]. |
[0.0, 0.0]
|
vec_local
|
list
|
Local surface normal. Defaults to [0, 0, 1]. |
[0.0, 0.0, 1.0]
|
is_square
|
bool
|
Whether aperture is square. Defaults to False. |
False
|
device
|
str
|
Torch device. Defaults to "cpu". |
'cpu'
|
Source code in src/geometric_surface/qtype.py
init_from_dict
classmethod
Initialize surface from a dictionary specification.
Source code in src/geometric_surface/qtype.py
is_within_data_range
Check if points are within valid surface data range.
For conic surfaces with k > -1, there's a maximum valid radius.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
tensor
|
x coordinates |
required |
y
|
tensor
|
y coordinates |
required |
Returns:
| Name | Type | Description |
|---|---|---|
tensor |
Boolean mask of valid points |
Source code in src/geometric_surface/qtype.py
max_height
Maximum valid height (radial distance).
Source code in src/geometric_surface/qtype.py
get_optimizer_params
Get optimizer parameters for different surface parameters.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lrs
|
list
|
Learning rates for [d, c, k, q_coefficients]. |
[0.0001, 0.0001, 0.01, 1e-06]
|
decay
|
float
|
Decay factor for higher-order Q coefficients. |
0.1
|
optim_mat
|
bool
|
Whether to optimize material parameters. |
False
|
Returns:
| Name | Type | Description |
|---|---|---|
list |
Parameter groups for optimizer |
Source code in src/geometric_surface/qtype.py
init_tolerance
Initialize tolerance parameters for manufacturing error simulation.
Source code in src/geometric_surface/qtype.py
sample_tolerance
Sample random manufacturing errors.
zero_tolerance
surf_dict
Return dictionary representation of surface.
Source code in src/geometric_surface/qtype.py
zmx_str
Return Zemax surface string.
Note: Zemax uses a different Q-type representation (QTYPE surface). This export is approximate and may need adjustment for specific Zemax versions.
Source code in src/geometric_surface/qtype.py
where \(u = \rho / r_{\text{norm}}\).
Diffractive Surfaces
Phase surfaces for diffractive optical elements (DOEs) and metalenses are in src.phase_surface:
| Surface | Description |
|---|---|
Binary2Phase |
Zemax Binary 2 even-order polynomial phase |
FresnelPhase |
Fresnel lens phase profile |
ZernikePhase |
Zernike polynomial phase |
PolyPhase |
General polynomial phase |
GratingPhase |
Diffraction grating phase |
CubicPhase |
Cubic phase mask |
NURBSPhase |
NURBS-based freeform phase |