# Stable Evaluation of 3D Zernike Moments for Surface Meshes
## 2 Moments from 3D Shapes
### Numerical Instabilities Associated with the Zernike Polynomials  
Let us first look at the radial polynomials. \(R_{nl}\) is a polynomial of degree \(n\). For large values of \(n\), special care is needed for computing them, and direct application of Equation (9) is bound to numerical instabilities, as described in Figure 1.  
The values of \(R_{80,0}(r)\) as a function of \(r\), based on a stable evaluation of the polynomial function vary in the interval \([-1.57,7.20]\), where the largest value is reached for \(r=0\). Numerical application of Equation (9) wrongly indicates that \(R_{80,l}(r)\) varies in the interval \([-4149,4\times 10^{13}]\) (results not shown). This is due to the fact that the coefficients \(Q_{80,0,r}\) are large (up to \(10^{29}\)), as illustrated in panel B of Figure 1. Those coefficients alternate from positive to negative due to the presence of the term \((-1)^{v}\), leading to large cancellations and ultimately to a small value for the polynomial. Computing correctly those cancellations requires very high precision usually not available with standard double precision in programming languages. It is possible to use arbitrary precision libraries to solve this issue, but it is in fact not necessary. As was noticed multiple times for the 3D Zernike radial polynomials (see for example [56; 57]) the radial polynomial \(R_{nl}\) can be expressed as a Jacobi polynomial:  
\[R_{nl}(r)=r^{l}P_{\frac{n-2l}{2}}^{(0,l+3/2)}(2r^{2}-1). \tag{19}\]  
Equation (19) allows the results available in the literature for the Jacobi polynomials to be translated for the 3D radial functions. In particular, we have the following recurrence relation (it was also derived in [54])  
\[R_{nl}(r)=(K_{1}(n,l)r^{2}+K_{2}(n,l))R_{n-2l}(r)+K_{3}(n,l)R_{n-4J}(r), \tag{20}\]  
where the coefficients \(K_{i}\) are defined as:  
\[k_{0} = (n-l)(n+l+1)(2n-3),\] \[k_{1} = (2n-1)(2n+1)(2n-3),\] \[k_{2} = \frac{1}{2}(-2n+1)(2l+1)^{2}-\frac{k_{1}}{2},\] \[k_{3} = -(n-l-2)(n+l-1)(2n+1),\] \[K_{1}(n,l) = \frac{k_{1}}{k_{0}},\quad K_{2}(n,l)=\frac{k_{2}}{k_{0}},\quad K _{3}(n,l)=\frac{k_{3}}{k_{0}}. \tag{21}\]  
This recursive formula is only valid for \(l\leq n-4\). This can be addressed by noticing that  
\[R_{nn}(r) = r^{n},\] Figure 1.0  
This recurrence allows for a stable computation of all \(R_{nl}(r)\), even for large orders. Figure 1.1 _Instabilities in evaluating the \(R_{nl}\) radial polynomials._ In panel (**A**), we show the values of \(R_{80,0}(r)\) as a function of \(r\), based on a stable evaluation of the polynomial function (see text for details). In panel (**B**), we show the values of the coefficients \(Q_{80,0,r}\), the monomial expansion of \(R_{80,0}(r)\). The geometric moments of a shape can be computed accurately even for large orders, see for example [52; 53]. Those moments can then be used to evaluate the 3D Zernike moments, as described in the section above. Converting the geometric moments to Zernike moments require, however, that the factor \(\chi^{rst}_{nlm}\) be computed (where \(nlm\) refers to the indices for the Zernike moments, while \(rst\) refers to the indices for the geometric moments). As defined in (18), the factors \(\chi^{rst}_{nlm}\) depend on the coefficients \(Q_{nlv}\) and therefore they are bound to suffer from the same numerical instabilities. We illustrate this in Figure 1.2  
As expected, the \(\chi^{rst}_{nlm}\) vary significantly over a large range of values. This was already observed by [PERSON] and colleagues in their attempts to parallelize the computation of Zernike moments [46] and is the main reason that the computation of Zernike moments is usually limited to order below \(N=50\). One solution to solve this problem would be to derive recurrence relationships for the \(\chi^{rst}_{nlm}\). [PERSON] et al. provided such a recurrence. However, their relationships still involve the computations of the factors \(Q_{nlv}\) (see their Equation (13e)) and as such do not solve the numerical instabilities.