## 3 Methodology
### Contour Fitting Based on Single-Frame and Multi-Frame Point Clouds  
Comparing defect point clouds with nominal point clouds is an effective method for defect detection. Nominal point clouds are typically generated in two ways: CAD modeling and fitting. Although CAD modeling can construct a standard workpiece model, point clouds acquired by laser scanners often contain noise and outliers and require transformation at a certain scale. As a result, it is difficult to ensure that the number of points  
Figure 9: Illustration of normal vector and curvature deviations. in the acquired point cloud closely matches that of the nominal model, which introduces unnecessary errors, as a point cloud analysis is conducted on a point-by-point basis. Therefore, we employed the fitting method, directly deriving the nominal contour from the acquired point cloud. This approach allowed for a more accurate and direct comparison by aligning the nominal model to the actual surface geometry, minimizing the effects of noise and misalignment. Although statistical filtering can effectively remove most noise and outliers, some still remain, which introduces bias in the fitting process. Furthermore, our objective was to fit the nominal model from the defective point cloud; however, the most distinct characteristic of the defective regions was their irregularity and insufficient number of points, which complicated the fitting. As a result, we did not aim to fit the complete workpiece model but instead fit a partial nominal contour. In fact, for objects with symmetrical structures, such as magnetic tiles, a single nominal contour can represent the entire workpiece, as the entire object is essentially an ordered arrangement of multiple nominal contours. As shown in Figure 10, we performed fittings in both the x- and y-directions, and both methods could generate a complete contour. In the x-direction, a contour corresponded to one frame of the laser scanner, thus we referred to it as a single-frame point cloud. In contrast, in the y-direction, a contour was composed of multiple frames of point clouds, and we referred to it as a multi-frame point cloud. The fitting result in the x-direction was a straight line, while the fitting result in the y-direction was a curve. Specifically, we used the least-squares method [82] to achieve the fitting process. In the y-direction, during our fitting process, we assumed that the data points could be described by a quadratic function, expressed as follows:  
\[z_{y}=ay^{2}+by+c \tag{11}\]  
where \(a\), \(b\) and \(c\) are the parameters of the fitting function, \(y\) is the independent variable, and \(z\) is the dependent variable. Our objective was to find the optimal parameters \(a\), \(b\), and \(c\) that minimized the residuals for all data points. The residuals were defined as the difference between the actual value \(z_{a}\) and the fitted value \(z_{y}\). We then constructed the objective function \(S_{y}\), and by minimizing \(S_{y}\), we obtained the best parameter set, as expressed in the following equation:  
\[S_{y}=\sum_{i=1}^{n}\left(z_{ai}-\left(ay_{i}^{2}+by_{i}+c\right)\right)^{2} \tag{12}\]  
Figure 10: Contour fitting of single-frame and multi-frame point clouds based on least-squares method. Similarly, for the fitting in the x-direction, a linear equation was given in the form:  
\[z_{x}=kx+d \tag{13}\]  
where \(z\) is the dependent variable, \(x\) is the independent variable, \(k\) is the slope of the fitted line, and \(d\) is the intercept. The expressions for \(k\) and \(d\) were as follows:  
\[k=\frac{n\sum x_{i}z_{i}-\sum x_{i}\sum z_{i}}{n\sum x_{i}^{2}-(\sum x_{i})^{2}} \tag{14}\]  
\[b=\frac{\sum z_{i}-k\sum x_{i}}{n} \tag{15}\]  
Next, the objective function \(S_{x}\) was constructed, expressed as:  
\[S_{x}=\sum_{i=1}^{n}\left(z_{ai}-\left(kx_{i}+d\right)\right)^{2} \tag{16}\]  
To assess the accuracy of the fitting results, we used the coefficient of determination (\(R^{2}\)) [83], a commonly used statistical measure to evaluate the goodness of fit.