> For the complete documentation index, see [llms.txt](https://docs.kostacloud.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.kostacloud.com/kostacloud/geometric-surface-types/zernike-surface.md).

# Zernike Surface

KostaCLOUD offers various definitions to Zernike Surfaces, as every field, institution, and researcher has their preference to the ordering of Zernike Polynomials, normalization, etc. For this reason, KostaCLOUD allows you to pick your representation.

In KostaCLOUD Zernike Polynomials are defined as follows:

$$
\begin{cases}
::::: N\_n^m R\_n^{|m|}(r) \cos(m\theta) & m> 0 \\
:::: N\_n^m R\_n^{|m|}(r) & m = 0 \\
-N\_n^m R\_n^{|m|}(r) \sin(m\theta) & m < 0
\end{cases}
$$

$$N\_n^m$$ are the **Normalization Coefficients**. These can be set to 1 to keep the polynomials Un-Normalized. Or for those who want the Zernike Polynomials to remain normalized, these coefficients are:

$$
N\_n^m = \sqrt{\frac{2(n+1)}{1+\delta\_{m,0}}}
$$

$$R\_n^{|m|}(r)$$ are the **Radial Zernike Polynomials**, which are defined by the following sum:

$$
R\_n^{|m|}(r) = \sum\_{s=0}^{(n-|m|)/2}\frac{(-1)^s (n-s)!}{
s!(\frac{n+|m|}{2}-s)!(\frac{n-|m|}{2}-s)!}r^{n-2s}
$$

An important consideration when dealing with these polynomials is that the radius (r) of the polynomial function must be normalized to the unit circle, as Zernike polynomials are orthogonal over the unit-circle. Therefore Zernike Surfaces are **regularized** to their respective aperture **maximum radius**. An example of this regularization is shown below, where each shape is shown to fit within the unit circle.

<figure><img src="/files/oTkVB7oZ30N8C7p4AifP" alt=""><figcaption><p>Regularization of non-circular apertures.</p></figcaption></figure>

## Numerical Validation

We have also verified the numerics for the first 37 Noll Zernike Polynomials and we have the Errors tabulated below with Zernike term normalization and we tabulate the error for 1000 points along a line segment from 0 to Rmax at 20 degrees. This is the Floating point (double precision) error of two methods we calculate the first 37 Zernike functions using extended precision and explicit equations and then compare this result to double precision result using Hypergeometric functions. Please note in Double precision floating point the Significand/Mantissa has 52 bits stored in IEEE 754 which means that relative to 1 in decimal should have about 15 digits, and in special cases this can be up to 17 significant digits.&#x20;

Below is an image from the second part of the numerical analysis, because in this part of the analysis we find that the radial component is the driver for numerical error. We plot the average error and the absolute error.

<figure><img src="/files/C8lOSrRtjbatJVefeOp3" alt=""><figcaption><p>Plotted Numerical Error for Zernike Polynomial Radial component versus Noll index.</p></figcaption></figure>

Upon fitting this data we get a fit-line with an R^2 of 0.984 for the following Equation:

$$
\text{Err}(\text{idx}) = {\mathrm e}^{ 0.8680000000 \ln \left(\text{idx} \right)- 35.45981043}
$$

If we extrapolate out a little bit we can calculate the numerical Sag error for 1nm. Since these calculations are done in mm, the maximum Noll index Zernike can be calculated by solving for idx:

$$
\text{idx}(\text{Err}) ={\mathrm e}^{ 40.85231617+ 1.152073733 \ln \left(\text{Err}  \right)}
$$

This would correspond to a Noll index of 6.75e10 with a Zernike Coefficient of 1 on Normalized Zernikes.&#x20;

| Noll Index | Zernike Dual Index \[n,m] | Max Error (Rel to 1) |
| ---------- | ------------------------- | -------------------- |
| 1          | 0,0                       | 0                    |
| 2          | 1,1                       | 4e-16                |
| 3          | 1,-1                      | 2e-16                |
| 4          | 2,0                       | 1.219e-15            |
| 5          | 2,-2                      | 7.7e-16              |
| 6          | 2,2                       | 8.1e-16              |
| 7          | 3,-1                      | 8.7e-16              |
| 8          | 3,1                       | 2.234e-15            |
| 9          | 3,-3                      | 1.178e-15            |
| 10         | 3,3                       | 5.6e-16              |
| 11         | 4,0                       | 3.499e-15            |
| 12         | 4,2                       | 3.498e-15            |
| 13         | 4,-2                      | 2.570e-15            |
| 14         | 4,4                       | 7.6e-16              |
| 15         | 4,-4                      | 1.716e-15            |
| 16         | 5,1                       | 6.887e-15            |
| 17         | 5,-1                      | 2.582e-15            |
| 18         | 5,3                       | 2.828e-15            |
| 19         | 5,-3                      | 5.797e-15            |
| 20         | 5,5                       | 9.1e-16              |
| 21         | 5,-5                      | 2.612e-15            |
| 22         | 6,0                       | 7.984e-15            |
| 23         | 6,-2                      | 6.514e-15            |
| 24         | 6,2                       | 7.682e-15            |
| 25         | 6,-4                      | 6.967e-15            |
| 26         | 6,4                       | 1.416e-15            |
| 27         | 6,-6                      | 2.450e-15            |
| 28         | 6,6                       | 1.030e-15            |
| 29         | 7,-1                      | 4.737e-15            |
| 30         | 7,1                       | 1.3067e-14           |
| 31         | 7,-3                      | 1.1700e-14           |
| 32         | 7,3                       | 6.531e-15            |
| 33         | 7,-5                      | 8.700e-15            |
| 34         | 7,5                       | 1.908e-15            |
| 35         | 7,-7                      | 2.342e-15            |
| 36         | 7,7                       | 2.262e-15            |
| 37         | 8,0                       | 1.3135e-14           |

From this data we can see that n seems to be the biggest contributor on loss of precision, therefore we should look explicitly at the radial part of the Zernike polynomial. We perform the same analysis at 0deg angle to get a better understanding of numerical precision as Polynomial order gets quite large:

| Noll Index | Zernike Index \[m,0] | maxerr     |
| ---------- | -------------------- | ---------- |
| 2          | 1                    | 7.4340E-16 |
| 4          | 2                    | 1.0199E-15 |
| 7          | 3                    | 1.9477E-15 |
| 11         | 4                    | 2.1583E-15 |
| 16         | 5                    | 3.7206E-15 |
| 22         | 6                    | 3.3561E-15 |
| 29         | 7                    | 6.6609E-15 |
| 37         | 8                    | 6.9594E-15 |
| 46         | 9                    | 1.1183E-14 |
| 56         | 10                   | 1.1904E-14 |
| 67         | 11                   | 1.6403E-14 |
| 79         | 12                   | 1.6981E-14 |
| 92         | 13                   | 2.2165E-14 |
| 106        | 14                   | 2.3049E-14 |
| 121        | 15                   | 2.9538E-14 |
| 137        | 16                   | 3.0361E-14 |
| 154        | 17                   | 3.7170E-14 |
| 172        | 18                   | 3.7687E-14 |
| 191        | 19                   | 4.5026E-14 |
| 211        | 20                   | 4.6228E-14 |
| 232        | 21                   | 5.2889E-14 |
| 254        | 22                   | 5.4489E-14 |
| 277        | 23                   | 6.0251E-14 |
| 301        | 24                   | 6.1179E-14 |
| 326        | 25                   | 6.5899E-14 |
| 352        | 26                   | 6.7084E-14 |
| 379        | 27                   | 7.0519E-14 |
| 407        | 28                   | 7.1839E-14 |
| 436        | 29                   | 7.3628E-14 |
| 466        | 30                   | 7.4845E-14 |
| 497        | 31                   | 7.4841E-14 |
| 529        | 32                   | 7.5952E-14 |
| 562        | 33                   | 7.8031E-14 |
| 596        | 34                   | 7.9430E-14 |
| 631        | 35                   | 8.2194E-14 |
| 667        | 36                   | 8.2758E-14 |
| 704        | 37                   | 1.0280E-13 |
| 742        | 38                   | 1.0438E-13 |
| 781        | 39                   | 9.6065E-14 |
| 821        | 40                   | 9.7141E-14 |
| 862        | 41                   | 1.2747E-13 |
| 904        | 42                   | 1.2943E-13 |
| 947        | 43                   | 1.1515E-13 |
| 991        | 44                   | 1.1606E-13 |
| 1036       | 45                   | 1.5433E-13 |

#### References

1. J. Schwiegerling, *Optical specification, fabrication, and testing*, SPIE, Bellingham, Washington (1000 20th St. Bellingham WA 98225-6705 USA) (2014).


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.kostacloud.com/kostacloud/geometric-surface-types/zernike-surface.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
