## 2 Modeling and Experimental Procedures
### Theoretical coordinate system  
The process of fine matching requires translation and rotation operation of six degrees of freedom, to achieve accurate alignment between the surfaces of the measured and theoretical systems. In the spatial coordinate system, the rotation and translation coordinate transformation corresponds to the rigid body transform. According to the transfer matrix, the point \(P(x,y,z)\) in the measured surface changed to point \(P^{\prime}\) (\(x^{\prime},y^{\prime},z^{\prime}\)) in the theoretical coordinate system, as shown in the Equation (1).  
\[\begin{bmatrix}x^{\prime}\\ y^{\prime}\\ z^{\prime}\\ 1\end{bmatrix}=\begin{bmatrix}&R_{3\times 3}&\begin{matrix}tx\\ ty\\ tz\\ 0\end{bmatrix}&\begin{matrix}x\\ y\\ z\\ 1\end{matrix}\end{bmatrix} \tag{1}\]  
where \(tx\), \(ty\) and \(tz\) represent the shifts in the x, y and z directions respectively. \(R_{3\times 3}\) is the rotation matrix, which is defined as Equation (2):  
\[R_{3\times 3}=\begin{bmatrix}\cos\gamma&-\sin\gamma&0\\ \sin\gamma&\cos\gamma&0\\ 0&0&1\end{bmatrix}\begin{bmatrix}\cos\beta&0&\sin\beta\\ 0&1&0\\ -\sin\beta&0&\cos\beta\end{bmatrix}\begin{bmatrix}1&0&0\\ 0&\cos\alpha&-\sin\alpha\\ 0&\sin\alpha&\cos\alpha\end{bmatrix} \tag{2}\]  
Figure 1: Schematic diagram of matching surface between measured and designed.  
Figure 2: Fixture used for rough positioning to make the measuring and theoretical coordinate system close.  
where \(\alpha\), \(\beta\) and \(\gamma\) are the rotation angles along the x, y and z axes respectively. The point \(\mathrm{Q}_{ij}(X_{ij},Y_{ij},Z_{ij})\) is the closest point of the theoretical surface to the point \(P_{ij}(X^{\prime}_{ij},Y^{\prime}_{ij},Z^{\prime}_{ij})\), the deviation can be calculated by Equation (3).  
\[F(\alpha,\beta,\gamma,tx,ty,tz)=\sum\abs{Q_{ij}-P_{ij}}^{2}. \tag{3}\]  
The best matching condition is defined as the minimum value of the function, namely, the sum of the distance between each point on the measured surface and the corresponding projection point on the theoretical surface are all in their minimum. Through multi-parameter optimization and based on the least squares principle and iterative precision adjustment, the optimal position parameters can be obtained and then the surface matching is complete. In such cases, the surface form error function is  
\[E=Z_{ij}-Z^{\prime}_{ij}. \tag{4}\]  
The evaluation parameters PV and RMS of surface form error were defined as Equations (5) and (6):  
\[PV=max(E)-min(E) \tag{5}\]  
\[RMS=\sqrt{\frac{1}{m}\sum_{i=1}^{m}E_{i}} \tag{6}\]  
where \(m\) is the number of points on the measured surface.  
During the process of freeform surface compensation machining, it is necessarily required to judge whether the surface form error meets the requirement. When the form error exceeds the tolerance, the obtained surface form error will be used to compensate the tool cutting path. The flow chart of the compensation process is shown in Figure 3. It should be noted that form error is regarded as the surface to be removed next in the process of surface matching. The surface error is reversed and superimposed on the initial ideal surface which will act as the new freeform surface to be processed. Because of the existence of random error, it is estimated that there will be repeated fluctuations in error, and the surface form error needs to be compensated several times until it is within the tolerance.