# pygrin¶

A basic collection of routines to ray trace through graded index (GRIN) lenses with a parabolic radial profile.

## Usage¶

Example Light paths in a 0.25 pitch GRIN lens from an ancient Melles Griot Catalog:

```import pygrin as grin
n = 1.608
length = 5.37
diameter = 1.8

ffl = grin.FFL(n,pitch,length)
efl = grin.EFL(n,pitch,length)
na = grin.NA(n,pitch,length,diameter)

angle = grin.max_angle(n,pitch,length,diameter)
print('expected pitch = 0.29,            calculated %.2f' % pitch)
print('expected FFL = 0.46 mm,           calculated %.2f' % ffl)
print('expected NA = 0.46,               calculated %.2f' % na)
print('expected full accept angle = 55°, calculated %.0f°' % (2*angle*180/np.pi))
print('working distance = %.2f mm'%(efl-ffl))
```

Produces:

```expected pitch = 0.29,            calculated 0.29
expected FFL = 0.46,              calculated 0.47
expected NA = 0.46,               calculated 0.46
expected full accept angle = 55°, calculated 55°
working distance = 1.43 mm
```

But the real utility of this module is creating plots that show the path of rays through a GRIN lens. For examples, see <https://pygrin.readthedocs.io>

## Installation¶

Source code is available at <https://github.com/scottprahl/pygrin> or the module can be installed using pip:

```pip install pygrin
```

## pygrin Package¶

### Functions¶

 `ABCD`(n_0, pitch, length, z) ABCD matrix for meridonal ray propagation. `BFL`(n_0, pitch, length) Back focal length of a grin lens. `EFL`(n_0, pitch, length) Effective focal length of a grin lens. `FFL`(n_0, pitch, length) Front focal length of a grin lens. `NA`(n_0, pitch, length, diameter) Numerical aperture of a grin lens in air. `cardinal_points`(n_0, pitch, length[, offset]) Cardinal points of a grin lens relative to first surface. `full_meridional_curve`(n_0, pitch, length, …) Points on a path from an object to image through a GRIN lens. `gradient`(pitch, length) Gradient of a grin lens based on its pitch and length. `hyperbolic_secant_profile_index`(n_0, alpha, r) Index of a hyperbolic secant grin lens at a particular radius. `image_distance`(n_0, pitch, length, s) Image distance for an object. `image_mag`(n_0, pitch, length, s) Transverse magnification of an object located at s. `max_angle`(n_0, pitch, length, diameter) Maximum acceptance angle of a grin lens in air. `meridional_curve`(n_0, pitch, length, r_i, …) Points on path of a ray passing through a grin lens. `parabolic_profile_index`(n_0, pitch, length, r) Index of a parabolic grin lens at a particular radius. `period`(grad, length) Period or pitch of a grin lens based on its gradient and length. `plot_principal_planes`(n_0, pitch, length, …) Create a plot for a grin lens showing the cardinal points.

# Changelog¶

## v0.4.1¶

• update function parameters for sphinx automodapi

## v0.4.0¶

• sphinx documentation
• plot_principal_plt -> plot_principal_planes

## v0.3.0¶

• renamed pitch() to period() to avoid stepping on the name.
• fix pylint warnings
• fix pep257 warnings
• fix pyroma warnings

## v0.2.0¶

• improve description