gradoptics.optics.lens

class gradoptics.optics.lens.Lens

Bases: gradoptics.optics.base_optics.BaseOptics, abc.ABC

Base class for lenses.

abstract sample_points_on_lens(nb_points, device='cpu')

Sample points uniformly on the lens

Parameters
  • nb_points – Number of points to sample (int)

  • device – The desired device of returned tensor (str). Default is 'cpu'

Returns

(tuple) Sampled points (torch.tensor) and p(A) (float)

class gradoptics.optics.lens.PerfectLens(f=0.05, na=0.714, position=None, m=0.15, transform=None, eps=1e-15)

Bases: gradoptics.optics.lens.Lens

Models a thin lens.

__init__(f=0.05, na=0.714, position=None, m=0.15, transform=None, eps=1e-15)
Parameters
  • f – Focal length (float)

  • na – Inverse of the f-number (float)

  • position – Position of the lens (list)

  • m – Lens magnification (float)

  • transform – Transform to orient the lens (BaseTransform)

  • eps – Parameter used for numerical stability in the different class methods (float). Default is '1e-15'

get_ray_intersection(incident_rays)

Computes the times t at which the incident rays will intersect the object.

Parameters

incident_rays – The incident rays (Rays)

Returns

Times t (torch.tensor)

intersect(incident_rays, t)

Returns the rays reflected or refracted by the optical element.

Parameters
  • incident_rays – The incident rays (Rays)

  • t – The times at which the incident rays will intersect the optical element (torch.tensor)

Returns

(tuple) - Reflected or refracted rays (Rays) - A boolean mask that indicates which incident rays were reflected or refracted ― some rays may not be

reflected or refracted for example, due to total internal reflection, which is not modelled at this point (torch.tensor)

sample_points_on_lens(nb_points, device='cpu')

Sample points uniformly on the lens

Parameters
  • nb_points – Number of points to sample (int)

  • device – The desired device of returned tensor (str). Default is 'cpu'

Returns

(tuple) Sampled points (torch.tensor) and p(A) (float)

plot(ax, s=0.1, color='lightblue', resolution=100)

Plots the optical element on the provided axes.

Parameters

ax – 3d axes (mpl_toolkits.mplot3d.axes3d.Axes3D)

class gradoptics.optics.lens.ThickLens(n_lens, n_ext, R, d, transform)

Bases: gradoptics.optics.lens.Lens

Models a thick lens using Snell’s law.

__init__(n_lens, n_ext, R, d, transform)
Parameters
  • n_lens – Index of refraction of the lens (float)

  • n_ext – Index of refraction of the external medium (float)

  • R – Radius of curvature of the lens (float)

  • d – Thickness of the lens (float)

  • transform – Transform to orient the lens (BaseTransform)

get_focal_length()

Approximates the focal length of the lens based on its properties

Returns

Approximation of the focal length (float)

get_normal(points)

Return the normal of the lens at the given points. The normals are oriented towards the center of the lens

Parameters

points – 3d positions (torch.tensor)

Returns

Normals at the given points (torch.tensor)

get_ray_intersection(incident_rays)

Computes the times t at which the incident rays will intersect the object.

Parameters

incident_rays – The incident rays (Rays)

Returns

Times t (torch.tensor)

intersect(incident_rays_, t_)

Returns the rays reflected or refracted by the optical element.

Parameters
  • incident_rays – The incident rays (Rays)

  • t – The times at which the incident rays will intersect the optical element (torch.tensor)

Returns

(tuple) - Reflected or refracted rays (Rays) - A boolean mask that indicates which incident rays were reflected or refracted ― some rays may not be

reflected or refracted for example, due to total internal reflection, which is not modelled at this point (torch.tensor)

plot(ax, resolution=200, **kwargs)

Plots the optical element on the provided axes.

Parameters

ax – 3d axes (mpl_toolkits.mplot3d.axes3d.Axes3D)

sample_points_on_lens(nb_points, device='cpu')

Sample points uniformly on the lens

Parameters
  • nb_points – Number of points to sample (int)

  • device – The desired device of returned tensor (str). Default is 'cpu'

Returns

(tuple) Sampled points (torch.tensor) and p(A) (float)