## 2 Double B-Spline Curve-Fitting for Tool-Tip Position and Tool Orientation under Fitting Tolerance
### Tool-Tip Position Curve-Fitting  
To fit successive linear segments, a cubic B-spline curve is used as the initial curve to guarantee C2-continuity (C2-continuity is necessary for continuous acceleration in feedrate scheduling). Besides geometric continuity, the fitting error and curvature are taken into consideration as criteria of a fitted curve. The fitting error affects the dimensional accuracy of the machined workpiece, hence must be regulated under fitting tolerance. The curvature, which affects the motion kinematics (the nominal velocity in feedrate scheduling), should be as small as possible but not under strict limitation. The fitting error of tool-tip position is satisfied if the Hausdorff distance between the fitted curve and the tool-tip position polyline is not greater than the fitting tolerance \(\varepsilon_{p}\) in the WCS. For a curve segment \(\mathbf{C}(s_{k-1})\mathbf{C}(s_{k})\)and a line segment \(\overline{\mathbf{p}_{k-1}\mathbf{p}_{k}}\), the Hausdorff distance is [15]:  
\[ \begin{array}{l}\text{Dis}_{H}(\overline{\mathbf{p}_{k-1}\mathbf{p}_{k}}, \mathbf{C}(s_{k-1})\mathbf{C}(s_{k}))=\\ \max\{\max_{\mathbf{p}\in\overline{\mathbf{p}_{k-1}\mathbf{p}_{k}}}\{\text{ Dis}(\mathbf{p},\mathbf{C}(s_{k-1})\mathbf{C}(s_{k}))\},\max_{\mathbf{C}\in \mathbf{C}(s_{k-1})\mathbf{C}(s_{k})}\{\text{Dis}(\mathbf{C},\overline{ \mathbf{p}_{k-1}\mathbf{p}_{k}})\}\},\end{array}  \tag{1}\]  
where \(\text{Dis}(\mathbf{a},\mathbf{b})\) is the Euclidean distance between \(\mathbf{a}\) and \(\mathbf{b}\). Since the explicit calculation of the Hausdorff distance by its definition between the fitted curve and the polyline is very computation-complex, the fitting error is classified into two categories. The first is called point error that indicates the approximation error between the fitting curve and the data points. The second is called chord error that represents the approximation error between the fitting curve and the linear segments. To fit the tool-tip position data, we start with a cubic B-spline curve to satisfy point error. A cubic B-spline curve defined as linear combination of control points \(\mathbf{P}_{i}\) and cubic B-spline basis functions \(N_{i,d}(u)\) is given by [33]:  
\[\mathbf{C}(u)=\sum\limits_{i=0}^{m}N_{i,d}(u)\mathbf{P}_{i},\quad 0\leq u\leq 1, \tag{2}\]  
where \(d\) stands for degree of the curve and in this case \(d=3\). The B-spline basis functions defined on a non-descending knot vector \(\mathbf{U}=\{0,\,0,\,0,\,u_{4},\dots,\,u_{n},\,1,\,1,\,1\}\) are calculated recursively as follows [33]:  
\[\left\{ \begin{array}{l}N_{i,0}(u)=\left\{\begin{array}{ll}1,\quad u_{i} \leq u<u_{i+1}\\ 0,\quad\text{otherwise}\\ N_{i,d}(u)=\frac{u-u_{i}}{u_{i+d}-u_{i}}N_{i,d-1}(u)+\frac{u_{i+d+1}-u}{u_{i+ d+1}-u_{i+1}}N_{i+1,d-1}(u).\end{array}\right.\end{array} \right. \tag{3}\]  
The cubic B-spline curve that passes through a set of tool-tip position data points \(\mathbf{p}=\{\mathbf{p}_{i}\in R^{3}|i=0,1,\dots,m\}\) is determined once the knot vector \(\mathbf{U}\) and control points \(\mathbf{P}_{i}\) are decided. The curve parameter value \(\bar{u}_{i}\) corresponding to data point \(\mathbf{p}_{i}\) and the knot vector \(\mathbf{U}\) are responsible for the shape and parameterization of the B-spline curve. \(\bar{u}_{i}\) is assigned using the cumulative chord length parameterization [33]:  
\[\left\{ \begin{array}{l}\bar{u}_{0}=0,\,\bar{u}_{m}=1;\\ \bar{u}_{k}=\bar{u}_{k-1}+\frac{\|\mathbf{p}_{k}-\mathbf{p}_{k-1}\|}{L},\quad k =1,\dots,m-1,\end{array} \right. \tag{4}\]  
where \(L=\sum\limits_{k=1}^{m}\|\mathbf{p}_{k}-\mathbf{p}_{k-1}\|\). The knot vector \(\mathbf{U}=[u_{0},\,u_{1},\dots,\,u_{n+4}]\) is built by averaging parameter values from Equation (3) as follows [33]:  
\[\left\{ \begin{array}{l}u_{0}=\dots=u_{3}=0,\,u_{n+1}=\dots u_{n+4}=1;\\ u_{j+3}=\frac{1}{3}\sum\limits_{i=j}^{j+2}\bar{u}_{i},\quad j=1,2,\dots,n-3. \end{array} \right.