$npx -y skills add matlab/matlab-agentic-toolkit --skill matlab-model-opticsBuild, import, analyze, tolerate, and optimize optical systems using the Optical Design and Simulation Library. Use when the user asks about optical systems, ray tracing, geometric optics, Zemax import, optical coatings, tolerancing, or optical design optimization.
| 1 | # Optical Design and Simulation Library |
| 2 | |
| 3 | Use this skill when the user is working with the **Optical Design and Simulation Library** to build, import, analyze, tolerate, or optimize optical systems in MATLAB. |
| 4 | |
| 5 | This library may also be referred to as: |
| 6 | - **Optical Design and Simulation Library** |
| 7 | - **Optics Support Package** |
| 8 | - **Optics Add-On** |
| 9 | - **Optics Library** |
| 10 | - **Optics Toolbox** |
| 11 | |
| 12 | Use **Optical Design and Simulation Library** as the canonical name in responses unless the user explicitly uses a different name. |
| 13 | |
| 14 | ## When to Use |
| 15 | |
| 16 | Use this skill when the user asks about: |
| 17 | - Optical Systems |
| 18 | - Ray Tracing |
| 19 | - Geometric Optics based analysis like lens distortion, spot diagrams, chromatic aberration, astigmatism and ray fans |
| 20 | - Paraxial Optics |
| 21 | - Optical Coatings |
| 22 | - Polarization or EM analysis (computing Fresnel Coefficients) |
| 23 | - Glass Materials and Glass Catalogs |
| 24 | - Zemax import |
| 25 | - Optical Tolerancing |
| 26 | - Optical System Design and Optimization |
| 27 | - Dynamic optical systems in Simulink (see `references/dynamic-optical-systems-simulink.md`) |
| 28 | |
| 29 | ## When NOT to Use |
| 30 | |
| 31 | Do **not** use this skill when: |
| 32 | - The user is working with physical optics or wave optics (diffraction, interference, coherence) |
| 33 | - The user is working with fiber optics or photonics |
| 34 | - The user needs image processing or computer vision (use Image Processing Toolbox instead) |
| 35 | - The task is purely about Simulink modeling without optical system involvement |
| 36 | |
| 37 | ## First Steps |
| 38 | |
| 39 | When helping a user who is new to the library, start with discovery: |
| 40 | ```matlab |
| 41 | help optics |
| 42 | ``` |
| 43 | |
| 44 | To get more details for a specific function: |
| 45 | ```matlab |
| 46 | help lensDistortion |
| 47 | doc lensDistortion |
| 48 | ``` |
| 49 | |
| 50 | Many optics APIs are class methods. For class methods, use: |
| 51 | ```matlab |
| 52 | help className/functionName |
| 53 | doc className/functionName |
| 54 | ``` |
| 55 | |
| 56 | Example: |
| 57 | ```matlab |
| 58 | help opticalSystem/add |
| 59 | ``` |
| 60 | |
| 61 | Use examples in the documentation when the user asks for a larger end-to-end workflow. |
| 62 | |
| 63 | ## Sample ZMX Files |
| 64 | |
| 65 | The Optical Design and Simulation Library ships sample Zemax (`.zmx`) files in the `opticsdata` folder within the support package install location. To find the path: |
| 66 | |
| 67 | ```matlab |
| 68 | spkgRoot = fullfile(matlabshared.supportpkg.getSupportPackageRoot, "toolbox", "images", "supportpackages", "opticsdata"); |
| 69 | dir(fullfile(spkgRoot, "*.zmx")) |
| 70 | ``` |
| 71 | |
| 72 | When a user asks to work with a standard optical system (e.g., "a Cooke triplet", "a doublet", "a telephoto lens") but does not provide their own file: |
| 73 | 1. List the available `.zmx` files in the `opticsdata` folder |
| 74 | 2. Pick the sample system that best matches the user's request |
| 75 | 3. Import it using `zmximport` |
| 76 | |
| 77 | This avoids asking the user for a file path when a suitable sample already exists. |
| 78 | |
| 79 | ## Core Concepts |
| 80 | |
| 81 | ### opticalSystem |
| 82 | |
| 83 | `opticalSystem` is the central object representing a physical optical system. |
| 84 | ```matlab |
| 85 | opsys = opticalSystem(Wavelengths=[486.134 587.562 656.281]); |
| 86 | ``` |
| 87 | |
| 88 | ### opticalMaterial |
| 89 | |
| 90 | `opticalMaterial` represents a glass or optical material. |
| 91 | ```matlab |
| 92 | mat = opticalMaterial([1.5168 64.17]); |
| 93 | mat = pickGlass("N-BK7"); |
| 94 | ``` |
| 95 | |
| 96 | ### opticalCoating |
| 97 | |
| 98 | `opticalCoating` represents a thin-film coating applied to surfaces. |
| 99 | ```matlab |
| 100 | oc = opticalCoating(CoatingMaterial=["MgF2" "TiO2"], LayerMaterialIndex=[1 2 1 2], LayerThickness=[1 0.5 1 0.5], PrimaryWavelength=550); |
| 101 | oc = pickCoating("AR_MgF2_VIS"); |
| 102 | addCoating(opsys, oc); |
| 103 | addCoating(opsys, oc, CoatingSide="front"); |
| 104 | ``` |
| 105 | |
| 106 | ## Coordinate Systems |
| 107 | |
| 108 | Refer to the MATLAB Documentation page called **"Coordinate Systems in Optical Design"** to learn about the coordinate system conventions used to construct optical systems. |
| 109 | |
| 110 | ### Field Point Angle Convention |
| 111 | |
| 112 | When creating a field point with `fieldPoint(Angles=[Hy Hx])`: |
| 113 | - `Hy` — vertical field angle (degrees) |
| 114 | - `Hx` — horizontal field angle (degrees) |
| 115 | |
| 116 | Example — a field point at 10 degrees vertical: |
| 117 | ```matlab |
| 118 | fp = fieldPoint(Angles=[10 0]); |
| 119 | ``` |
| 120 | |
| 121 | A field point at 10 degrees horizontal: |
| 122 | ```matlab |
| 123 | fp = fieldPoint(Angles=[0 10]); |
| 124 | ``` |
| 125 | |
| 126 | ### TiltAngles Convention |
| 127 | |
| 128 | `TiltAngles=[Rx Ry Rz]` specifies rotations in degrees about each axis: |
| 129 | - `Rx` (first element) — rotation about the X-axis |
| 130 | - `Ry` (second element) — rotation about the Y-axis |
| 131 | - `Rz` (third element) — rotation about the Z-axis |
| 132 | |
| 133 | Example — a mirror tilted 45 degrees about the X-axis: |
| 134 | ```matlab |
| 135 | addMirror(opsys, TiltAngles=[45 0 0]); |
| 136 | ``` |
| 137 | |
| 138 | ## Common Interaction Patterns |
| 139 | |
| 140 | ### Pattern: Build → Visualize → Analyze |
| 141 | |
| 142 | Many user requests follow this sequence: |
| 143 | 1. Build or import an optical system |
| 144 | 2. Define field points and wavelengths |
| 145 | 3. Run an analysis function |
| 146 | 4. Inspect returned values |
| 147 | 5. Visualize results |
| 148 | |
| 149 | ```matlab |
| 150 | %% 1. Build |
| 151 | opsys = opticalSystem(Wavelengths=587.562); |
| 152 | addRefractiveSurf |