Version (382 KB) by Yury
Optometrika MATLAB library implements analytical and iterative ray tracing approximation to optical image formation using Snell’s and Fresne
Updated 18 Jan 2022

Developer: Yury Petrov

Optometrika library implements analytical and iterative ray tracing approximation to optical image formation using Snell’s and Fresnel’s laws of refraction and reflection.
Currently, the library implements refractive and reflective general surfaces, aspheric (conic) surfaces with astigmatism, Fresnel surfaces, cones and cylinders (elliptic too), planes, circular and ring-shaped apertures, rectangular flat screens, spheroidal screens, and a realistic model of the human eye with accommodating lens and spheroidal retina. See example*.m files for examples of ray tracing in general (user-defined shape) lenses, aspheric lenses, Fresnel lenses, prisms, mirrors, and human eye.

The library traces refracted rays, including intensity loss at the refractive surface. Reflected rays are currently traced for mirrors and also for a single total internal reflexion or double refraction, if it happens. Note that the Bench class object is not a real physical bench, it is only an ordered array of optical elements, and it is your responsibility to arrange optical objects in the right order. In particular, if you need to trace rays passing through the same object multiple times, you have to add the object multiple times to the bench array in the order the object is encountered by the rays. For example, double refraction/reflection for cylindrical and conical surfaces can be calculated by adding the surface twice to the bench.

The library is very compact and fast. It was written using Matlab classes and is fully vectorized. It takes about 2 seconds to trace 100,000 rays through an external lens and the human eye (8 optical surfaces) on a 3 GHz Intel Core i7 desktop. Fresnel lens tracing is somewhat slower due to looping through the Fresnel cones describing the lens surface. Tracing through user-defined (general) surfaces is significantly slower due to iterative search of ray intersections with the surface.

Thank you for downloading Optometrika, enjoy it!

List of examples:

example1.m: tests the basic functionality of the Optometrika library
example2.m: demonstrates the Optometrika's optical model of the human eye
example3.m: demonstrates accommodation of the human eye by minimizing the retinal image
example4.m: tests a ring lens with the cosine surface profile defined in coslens.m
example5.m: tests planar mirrors
example6.m: tests planar and parabolic mirrors (a Newtonian refractor telescope)
example7.m: tests a Fresnel lens
example8.m: tests a lens with polynomial aspheric terms
example9.m: tests cone mirrors
example10.m: tests cylinder and cone surfaces with double refraction
example11.m: demonstrates ray tracing for rays originating inside the human eye
example12.m: draws a lens and determines its front surface, back surface, and total height. Makes an animated gif of the lens and an engineering drawing of the lens.
example13.m: tests refraction through the lens edge and backward rays refraction (sub-aperture Maksutov-Cassegrain telescope)
example14.m: tests refraction through a lens with astigmatism (different vertical and horizontal radii of curvature)
example15.m: simulates a hexagonal array of spherical micro lenses
example16.m: demonstrates STL export of various lenses

Cite As

Yury (2024). Optometrika (https://github.com/caiuspetronius/Optometrika), GitHub. Retrieved .

MATLAB Release Compatibility
Created with R2018b
Compatible with any release
Platform Compatibility
Windows macOS Linux

Inspired by: hist2

Inspired: asphere parameters

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Versions that use the GitHub default branch cannot be downloaded

Version Published Release Notes

Fixed a bug in Aperture.m incorrectly displaying rectangular aperture orientation on the bench

Fixed a bug preventing displaying a point image on a screen

Bug fixing

Fixed incorrect surface normals calculation for surfaces with polynomial terms, added inner diameter (a hole) to the Plane surface , extended export_stl() to Plane surfaces.

Fixed a bug affecting backward propagating rays interacting with hyperbolic surfaces.

Maintained as a GitHub repository now.

Changed export_stl() function to work correctly with the stlwrite() function bulid into Matlab 2018b.

Updated the export_stl() function to export GeneralLens class surfaces.

Added export_stl() function for lens surface export in STL format. See example16.
Various bug fixes

Various bug fixes

Added several new materials
Fixed several bugs, including the one preventing the library working on pre-2016 Matlab versions

Added STL and DXF export of a lens's 3D shape and 2D profile respectively to the draw_lens_engineering() function. Install stlwrite() and DXFLib to use this functionality.

Minor bug fixes.

Added engineering drawing of Fresnel lenses to draw_lens_engineering(). See example7 for an example.
Fixed a bug in Fresnel surface rotation.

Added rectangular apertures. See example4.
Fixed various bugs in the FresnelLens implementation

Implemented astigmatic lens surfaces: use a 2x1 vector for the radius of curvature (see example14).
Implemented elliptical cone/cylinder surfaces: use a 2x1 vector for the cone/cylinder diameter (see example10).
Various bug fixes

Implemented ray tracing for backward-propagating rays (example13)
Various bug fixes

Bug fixes

Added flange option to the draw_lens_engineering() function.

Various bug fixes.

Added draw_lens_engineering() function to automatically generate engineering drawing for lens manufacturers. Currently only lenses without holes are implemented. See example12 for a demo.

Example12 illustrates the use of lens_dims() function to draw a lens (full surface) and calculate its sags and volume.
Various bug fixes.

For a new way to display rays, see example11.
Added density information for many materials in refrindx.m. Use lens_dims() function to get lens volume.
Example11 demonstrates tracing from inside the human eye.
Various bug fixes.

Total internal reflection enabled. Various bug fixes related to multiple refraction/reflexion.

Added cylindrical surfaces, including double refraction on such surfaces (example 10). Fixed some bugs.

Added a cone-shaped surface ConeLens()
Added ring-aperture option for all surfaces except the FresnelLens.
Rays missing optical elements are not discarded any more but traced to the next element.
General bug fixes

Added AsphericLens class describing strongly aspheric surfaces (conic + even polynomial terms, example8).
Added a fast focal_point() function looking for the bundle's focal point without iterations (example1).

Added a Fresnel lens implementation. Added operations on a bench, such as bench rotation, element prepending and removal.

Replaced the missing Bench.m file.

Various bug fixes and improvements. Spheroidal screens are implemented now by the Retina object.

Some bug fixes and improvements, added spheroidal screens implemented by the Retina class.

Added basic documentation to the classes.

Added: (i) appending ray bundles to an existing bundle, (ii) mirror elements (general, conic, planar). To specify a surface as a mirror use 'mirror' glass specifier (see example5.m and example6.m).

Small bug fixes.

Added tracing through general (user-defined) surfaces (see example4.m).

Fixed a bug affecting ray tracing through strongly hyperbolic surfaces.

Fixed a bug which affected ray tracing through extremely hyperbolic surfaces.

To view or report issues in this GitHub add-on, visit the GitHub Repository.
To view or report issues in this GitHub add-on, visit the GitHub Repository.