## 2 Double B-Spline Curve-Fitting for Tool-Tip Position and Tool Orientation under Fitting Tolerance
### Tool Orientation Curve-Fitting  
The tool orientation data \(\mathbf{o}=\{\mathbf{o}_{i}\in R^{3}|i=0,1,\ldots,m\}\) are expressed by the spherical coordinates \(\mathbf{o}_{i}=[o_{iI},o_{ij},o_{iK}]\) in the WCS. Unlike curve-fitting of the tool-tip position, the tool orientation is fitted to the Cartesian coordinates that map from the given spherical coordinates to ensure that the magnitude of  
Figure 4: Fitting error and curvature of planar five-point example.  
Figure 3: Fitted curve of planar five-point example.  
the orientation vector remains unity [22]. The mapping from the spherical coordinates to the Cartesian coordinates is obtained as follows:  
\[\left\{\begin{array}{l}\alpha_{i}=\cos^{-1}(o_{iK})\\ \gamma_{i}=\tan^{-1}(o_{iI}/o_{iI}),\end{array}\right. \tag{8}\]  
where \(\alpha_{i}\) and \(\gamma_{i}\) are actually the rotary drive commands \(\theta_{Ai}\) and \(\theta_{Ci}\) in the MCS respectively. And the inverse mapping is in the following form:  
\[\left\{\begin{array}{l}o_{iI}=\sin\theta_{Ai}\sin\theta_{Ci}\\ o_{iI}=\sin\theta_{Ai}\cos\theta_{Ci}\\ o_{iK}=\cos\theta_{Ai}.\end{array}\right. \tag{9}\]  
The fitting tolerance of the tool orientation is given as \(\varepsilon_{o}\) in the WCS. Since the tool orientation is smoothed in the MCS, it is necessary to convert \(\varepsilon_{o}\) to \(\varepsilon_{\theta}\) which denotes the fitting tolerance of the tool orientation in the MCS.  
As shown in Figure 5, we assume \(O^{\prime}\) is the orientation position after O rotates \(\varepsilon\) in the WCS and \(O_{t}\) is the transitional orientation position that rotates \(\Delta\alpha\) away from the \(z_{w}\)-axis to reach \(O^{\prime}\). The lengths of edge \(\overline{OO_{t}}\), \(\overline{O_{t}O^{\prime}}\), and \(\overline{OO^{\prime}}\) are obtained as:  
\[\left\{\begin{array}{l}a=2\sin\alpha\sin(0.5\Delta\beta)\\ b=2\sin(0.5\Delta\alpha)\\ c=2\sin(0.5\varepsilon).\end{array}\right. \tag{10}\]  
Since \(\Delta\alpha\), \(\Delta\beta\), and \(\varepsilon\) are extremely small, \(O_{o}\), \(O_{t}\), and \(O^{\prime}\) are approximately collinear. Thus we have \(\angle O_{o}O_{t}O\approx\angle OO_{t}O^{\prime}\approx 90^{\circ}\) and Equation (10) can be simplified as:  
\[\left\{\begin{array}{l}a=(\sin\alpha)\Delta\beta\\ b=\Delta\alpha\\ c=\varepsilon.\end{array}\right. \tag{11}\]  
Figure 5: Fitting error and curvature of planar five-point example.  
Because \(\angle O{O_{t}}O^{\prime}\approx 90^{\circ}\), we have \(a^{2}+b^{2}=c^{2}\), that is \((\sin\alpha)^{2}\Delta\beta^{2}+\Delta\alpha^{2}=\varepsilon^{2}\) which lead to \(\varepsilon^{2}\leq\Delta\alpha^{2}+\Delta\beta^{2}={\varepsilon_{\theta}}^{2}\). Since \(\varepsilon\leq\varepsilon_{o}\), the fitting error of the tool orientation is satisfied if \(\varepsilon_{\theta}\leq\varepsilon_{o}\). Without loss of generality, let \(\varepsilon_{\theta}\)=\(\varepsilon_{o}\).  
The B-spline curve in the \(\theta_{A}\theta_{C}\) Cartesian plane is obtained with the input of the mapped tool orientation data \(\mathbf{\theta}=\{(\theta_{Ai},\theta_{Ci})|i=0,1,\dots,m\}\) and fitting tolerance \(\varepsilon_{\theta}\) according to the procedure in Section 2.1 as:  
\[\mathbf{R}(v)=\sum_{i=0}^{n}N_{i,d}(v)\theta_{i}. \tag{12}\]  
The tool orientation spline \(\mathbf{o}(v)=[o_{I}(v),o_{I}(v),o_{K}(v)]\) in the WCS is obtained using inverse mapping from Equation (9). It is noteworthy that the number of control points of the fitted curve depends on the initial curve and the fitting tolerance. Therefore the number of control points of the tool orientation is not necessarily the same as the tool-tip position.