Smoothing and compressing algorithm of toolpath with complex contour in NC machining

The continuous short line segment processing method in CNC machining has the defect of frequent fluctuation of feedrate, which affects the quality and efficiency. For this problem, the local and global methods are common solutions. The local method is to insert transition curves at the corners to obtain a smooth toolpath, but this method does not essentially reduce the number of accelerations and decelerations, and it is difficult to insert transition curves between tiny straight sections. Although the global method can obtain smooth tool trajectories, the parametric interpolation method is not suitable for middle- and low-end CNC machine tools. The article proposes an adaptive tool path generation method with the original part contour as the research object and discretizes the NURBS curves into smooth trajectories consisting of large segments of straight lines and circular arcs. The article mimics the crawling characteristics of snakes and designs a double-headed snake algorithm based on the least squares method to implement this process. First, given the start and end points of the curve, two snakeheads search for the maximum linear and circular segments that satisfy the error constraint in the curve direction. The winner will then be selected as the candidate track segment through a competition mechanism. Finally, all trajectory segments are connected to obtain a smooth tool path. Experiments show that the toolpath data of the method in this paper are reduced by 75.56% compared with commercial CAM software when the contour error threshold is the same, and the contour error is reduced by more than one order of magnitude when the number of toolpath segments is equal. In addition, the method in this paper can obtain a smoother machining surface and more stable cutting force, thus achieving a win‒win situation of quality and efficiency.


Introduction
The rapid development of computer-aided geometric design (CAGD) has enabled the precise mathematical representation of complex contours, making the machining of irregularly contoured parts a hot topic in academic research and industrial applications [1]. The NURBS has been defined by the International Organization for Standardization as the only data exchange standard for computer-aided design/ manufacturing (CAD/CAM) because of its superior shape representation capabilities [2], and most commercial CAD/ CAM software use NURBS as the mathematical representation of parts [3,4]. Therefore, enhancing the processing capability of CNC machine tools to the NURBS curves can improve the machining quality and efficiency of parts, and further increase the machining performance and level of machine tools.
General CNC machine tools only have linear and circular interpolation functions, which cannot accurately track the intended curve trajectory, so the curve needs to be discretized to obtain the cutting position (CL) [5,6]. Therefore, the machining of complex parts on these machines is divided into two main steps. The first is tool trajectory planning, which discretizes the curve into continuous short-line segment trajectories. The second is feedrate planning, which aims to control the cutter to adjust the feed rate according to the curvature variations. Therefore, the impact of toolpath planning on machining quality and efficiency cannot be ignored [7]. The discretization of parametric curves can be summarized in the following three methods, i.e., equal parameter discretization, equal chord length or equal arc length discretization, and equal chord error discretization [8]. For example, He et al. [9], and Zou et al. [10] uniformly divide the parameters of the spline curve to obtain the toolpath. However, this method is not easy to control the contour error between the toolpath and the original curves, and it may need to adjust the division steps of the parameters several times to obtain the toolpath that meets the error requirement. Liu et al. [11] addressed the path planning problem of welding robots by discretizing the spatial curves by the equal chord error and equal arc length methods. Du et al. [12] discretized the curves by the equal chord error method. Zhao et al. [13] searched for the maximum chord error by the golden mean method.
The curve discretization can be created as a polygon approximation problem by first capturing n interpolation points on a complex curve and then replacing that curve with a continuous short-line segment trajectory composed of these points [14]. The objective is to carry as much geometric information of the original curve with as few interpolation points as possible within the error margin [15,16]. The Douglas-Peucker algorithm [17] (D-P) is a classic algorithm in the field of trajectory data compression. For instance, Sim et al. [18] used the D-P algorithm to remove redundant points on the flight trajectory of an unmanned aerial vehicle (UVA) for path optimization. Zhao [19] also used the D-P algorithm for ship trajectory compression. However, the threshold value of the D-P method is difficult to determine and tends to filter the geometric information of the original trajectory.
Although the abovementioned methods can obtain tool trajectories that meet the geometric accuracy requirements, the following two drawbacks cannot be ignored. First, the large number of short line segments means that the machine needs frequent acceleration and deceleration, which is especially obvious in high-speed machining, so the machining efficiency is greatly reduced, and the frequent vibration will also reduce the life of the machine. Second, the unsmooth toolpath causes the poor surface quality of the part. Nam et al. [20] proposed an S-shaped feedrate planning method to improve machining efficiency. Tajima et al. [21] considered the dynamic performance of the machine tool and constructed a circular velocity transition model at the corners to improve the tool articulation speed between adjacent micro-line segments. Huang et al. [22] introduced a bidirectional scanning algorithm in acceleration and deceleration feedrate scheduling to ensure continuity between adjacent feed rate profiles. However, the above work does not essentially reduce the number of accelerations and decelerations. The research on tool trajectory smoothing can be summarized as local and global methods [23]. For instance, Zhang et al. [24] inserted a micro-arc at the corner to obtain a smooth tool path. Park [25] divides the NURBS curve into discrete points and then fits the curve with a bicircular arc between adjacent points. Fan et al. [26] and Zhang et al. [27] used quadratic Bézier curves to smooth the corners. Vincent et al. [28] and Zhao et al. [29] used cubic B-samples as transition curves. Zhang et al. [30] inserted five NURBS curves at the corners of the continuous linear tool path to obtain the G4 continuous toolpath.
Although the local method can obtain smooth tool trajectories, the length of many trajectory segments in actual machining is in the micron range, which will increase the difficulty of the algorithm or even make it ineffective [31]. In addition, several scholars have focused on the global method to reconstruct the micro-linear segments as parametric curves. He et al. [32] and Yau et al. [33] first generated the G-code data by CAM software and then fitted it to a NURBS curve. Liu [34] compressed the large amount of tool location data with double-chord error and then reconstructed it into NURBS curves by the least squares method. References [35][36][37][38] are considered from the perspective of reducing the complexity of the algorithm by first selecting a set of dominant points on the original data points and then fitting them to the B-spline. Although the global method can obtain a smooth toolpath, it is not easy to promote in ordinary machine tools because only a few high-end machines have parametric curve interpolation capabilities [39]. In addition, almost all CNC machines support linear and circular interpolation, so the G-code command interpolation method still dominates the industry [40].
To achieve a higher level of quality and efficiency for ordinary CNC machines, this paper considers both the compression of the number of trajectory segments and trajectory smoothing, and directly discretizes NURBS into a combination of large-sized linear and circular arc segments. In this paper, a double-headed snake algorithm (DHS) is designed to implement the process. The two snake heads represent the linear segment search engine (LSSE) and the arc segment search engine (ASSE), respectively. The function of the LSSE is to determine the longest straight-line segment that meets the accuracy requirements through the forward-backward search strategy, and the ASSE is to search the longest arc segment that meets the accuracy requirements through the least-squares method. When the longest straight-line and circular-arc segments with the same starting point are acquired, the current toolpath segment can be selected by the campaign mechanism. Finally, check whether the current toolpath segment satisfies the smoothing condition, i.e., whether the angle between its start direction and the end direction of the previous toolpath segment exceeds the given threshold value. The content of the article is organized as follows: The definition and properties of NURBS curves and the least-squares-based arc fitting method are given in Section 2. Section 3 is the core of the approach 1 3 in this paper and will describe the details of the two-headed algorithm. Section 4 will categorically discuss the smoothing conditions between straight and circular segments and derive the corresponding formulas. Section 5 is the simulation and experimental analysis, and Section 6 is the conclusions.

The definition and derivation of NURBS
A k times NURBS curve can be defined as where {P i } are the control vertices that form the control polygon,{ i } are the weights corresponding to each control vertex, and {N i,k } is the n + k + 2th K-order B-spline basis function defined by the non-uniform node vector U shown in Eq. (2).
Equation (3) is called the de Boor-Cox recurrence formula. In particular, Eq. (1) degenerates to a non-uniform B-spline curve when the weight factor i =1 . If the vector values in Eq. (2) are uniformly varying except for k + 1 nodes at the ends, the curve further degenerates to a quasi-uniform B-spline. To obtain the exact curvature of the curve, the derivative of the NURBS curve is needed. First, the derivatives of the B-spline and basis functions are given without proof as follows: Then according to reference [4], let where A(u)= ∑ n i=0 N i,k P i i is a vector-valued function and is the numerator of Eq. (1), (u)= ∑ n i=0 N i,k i . The r-order derivative of A(u) is obtained by Leibniz's formula as Thus, the formula for the r-order derivative of the NURBS curve can be obtained as where A (r) , C (r) (u) , and (i) (u) can be obtained from Eq. (5).

The selection of feature points
The arc is a curve of equal curvature, and when used to approximate complex curves, each arc segment usually does not include multiple extreme points or inflection points of the curve. Therefore, the interval where the endpoints of the arc segments fall can be predetermined by the feature points consisting of the inflection points and the extreme value points, which can accelerate the convergence speed of the DHS algorithm. The curvature has two expressions: absolute and relative. The absolute curvature is positive, which only reflects the bending degree of the curve, while the relative curvature can be positive or negative, which reflects both the bending degree and direction of the curve. The relative curvature is calculated as follows: If a negative value is obtained through Eq. (8), the curve will be deflected clockwise along the direction of the parameter, while a positive value implies counterclockwise. Therefore, if the curvature value changes sign, it means that the point is the inflection point of the curve, as shown in Fig. 1.
The extreme points in Fig. 1a correspond to the extreme points of curvature in Fig. 1b, and the inflection point is the point where the relative curvature is zero and the left and right sides have different signs. The extreme value point and the inflection point of the curve should satisfy the following conditions, respectively.
Therefore, adding the starting and ending points of the curve, the set of feature points of the curve is

The least squares-based arc fitting
The least squares method is a simple and effective optimization method, and the idea is to find the unknown parameters in the objective function by minimizing the sum of squared errors given a set of samples.
Given a sequence of points P on a complex curve, assuming that P s and P e are the starting and ending points, respectively, and are passed by the arc segment, then the objective function can be expressed as where P m is the midpoint of P s P e and e = (e 1 , e 2 ) is the normal unit vector of P s P e . Let x i − P mx = x i y i − P my = y i , then the objective function can be reduced to According to the extreme value condition, let the first order derivative of Eq. (10) be zero to find the unknown parameter as w h e r e H 1 = ∑ � Thus, the center and radius of the arc segment can be expressed as follows: It is worth noting that the circular segments obtained by Eq. (12) only satisfy the convergence condition in the least squares sense, which does not necessarily meet the actual machining accuracy requirements. Therefore, the following constraint should be added: where con denotes the error threshold set by the algorithm.

The search for the longest arc segment
Mathematically, any three points that are coplanar but not co-linear can uniquely determine a circle, and when these points are co-linear, the radius will tend to infinity. On this basis, the following two corollaries are given to search for the longest arc segment that satisfies the contour accuracy. Corollary 1: For a set of discrete points captured arbitrarily on a curve, it is always possible to find a unique arc that approximates these points in a least-squares sense and minimizes the contour error.
Corollary 2: Arbitrarily set a starting point P start from the curve, then make a point P sch moving along the curve from P start , while performing the arc fitting operation in Section 2.3 for the points between P start and P sch . Theoretically, at least one arc segment can be found to traverse the beginning three points exactly. When the points between P start and P sch do not satisfy Eq. (13), then the points after P sch will no longer meet the accuracy requirement, and the arc segment obtained at this time is the longest one.
Since each set of points can be uniquely solved by the method in Section 2.3, the correctness of corollary 1 is obvious. Unfortunately, corollary 2 is not easy to prove mathematically, but this conclusion was drawn from our experiments on partial curves, so it is not a bad idea to explore a new approach from the point of view of practical applications. Therefore, the above inferences make it possible to search for the longest circular segment that satisfies the accuracy requirement, and the interval dichotomy shown in Fig. 2 will be used for this purpose. Let P be the point cloud data obtained from the curve, and let P start and P end be the start and end points of the curve, respectively. The search point P sch is the moving point between P start and P end , and when the algorithm converges, P start and P sch are the starting and ending points of the arc segment; at this point, P sch is called the target point. Suppose the target point is located in the interval [P up , P dow ] (see Fig. 2), then the longest arc can be confirmed by Algorithm 1.

The search for the longest straight line segment
The core idea of this part is to make the search point P sch move along the curve direction from the starting point P start and find the longest straight line segment P start P sch so that the contour error between the line segment P start P sch and the curve meets the requirement. The process will be implemented by the forward-backward search strategy with variable step size, as described in Algorithm 2.

Algorithm 2 The forward-backward search strategy
Input: point cloud P Output: The start and end of a straight line segment Step1: Given an initial search point P sch =P start and P sch ∈ P , initialization step t = 1 Step2: Start searching Step2.1: Let sch = sch + t Step2.2: Calculate the chord error between the line P start P sch and the curve Step2.3: If < con , let t = 2t, return Step2.1. Else if = con , go to step3. Else if > con , if t = 1, let sch = sch − 1 , go to Step3, otherwise, let sch = sch − t , t = 1, go to Step2.1 Step3: Output linear segment P start P sch

Overall design
The bodies of snakes have an excellent sinuous nature and they can crawl along arbitrarily complex trajectories. In this paper, a double-headed snake (DHS) search algorithm is designed to implement the toolpath generation process by this property. The main structure of the algorithm is shown in Fig. 3.
The DHS algorithm consists of four parts: head, neck, waist, and tail. The head part includes two independent search engines, where the LSSE searches for the longest straight line segment ( seg_l ) by Algorithm 2 and the ASSE searches for the largest arc segment ( seg_a ) by Algorithm 1. The neck sets up a campaign mechanism to select the best trajectory segment ( seg_best ) from seg_l and seg_a . For the best data compression, the algorithm selects the segment with the largest span in the curve direction as the winner. The waist is the smoothing module of the DHS algorithm, which functions to check whether the smoothing conditions are satisfied between the current trajectory segment seg_best(i) and the previous trajectory segment seg_best(i − 1) , and various smoothing checks are discussed categorically in Section 4. The tail is the Fig. 2 Search for the longest arc by interval dichotomy data storage module, which includes data caching and storage functions. The data caching records only the last trajectory segment and participates in the smoothing condition check in the next cycle of search. The data storage function serves to record all trajectory segments until the end of the algorithm.
The P start is pushed forward at the end of each search round, so that the curve is discretized into a combination of straight and circular segments as the snake climbs from the start to the end of the curve.

Conditions for trajectory smoothing
There are three cases of connection between adjacent trajectory segments, straight line to straight line, straight line to arc segment, and arc segment to arc segment. Figure 4a shows the smoothing transition model between linear segments, in which P start is the starting point of the current trajectory segment and the ending point of the previous one, v and u are the unit vectors of these two trajectory segments along the forward direction, respectively. To ensure the surface quality of the part, when the angle between v and u exceeds a given value, it is necessary to insert a transition arc between these two trajectory segments.

Straight line to straight line
In Fig. 4a, P cs and P ce are the starting and ending points of the transition arc, O c and r c are the center and radius, respectively. The circle with P cs as the center and the error constraint con as the radius is the error circle, so the maximum contour error occurs at P cs . From the geometric relationship, we have The starting and ending coordinates of the transition arc are 2. Arc segment to arc segment As shown in Fig. 4b, O 1 and O 3 are adjacent arc segments, and then the transition arc O c should be tangent to both the two arc segments and the error circle. According to the geometric relationship is not difficult to derive a 1 b 2 ) . Substituting Eq. (17) into ① yields the following quadratic equation for r:

Then, Eq. (16) can be simplified by combining ①-② and ②-③ as
1 . The radius of the transition arc can be obtained by Eq. (18), but there exist positive and negative solutions to this equation, which correspond to the cases of external and internal tangency, respectively. Since the transition arc is always external tangent to the three circles, the calculation result should take the positive one. Figure 4c and d show the arc transition models in the same and opposite directions. Assuming that O and r are the center and radius of the arc segment, respectively, then the transition arc should be tangent to both the arc segment, the error circle, and the linear segment. Let OP s and O c P ce intersect at P m , | | OP m | | = r} , then the following equation can be obtained from the geometric relationship in Fig. 4c. (14) r c = con cos( ∕2)∕(1 − cos( ∕2))

Substituting Eq. (24) into Eq. (19) yields
The rest of the unknown quantities are calculated by the same formula as Eq. (22).

The generation of toolpath and error analysis
To verify the feasibility and effectiveness of the DHS algorithm, this paper conducts experiments through a "dolphin" curve of length 675.6525, as shown in Fig. 5. The DHS algorithm will be compared with the equal chord error method, the D-P algorithm, and the commercial CNC software Mastercam, and its advantages and disadvantages will be analyzed in terms of contour accuracy, compression efficiency, and program running time.
The experimental platform is Dell OptiPlex 390, the processor is Intel Pentium CPU G630@2.7 GHz, Windows 10 operating system, and the software version is MATLAB 2018a. A point cloud of capacity 30,030 is captured uniformly on the curve as the input for the equal chord error method and the D-P method. For fairness, the DHS algorithm partitions the parameter U at 0.0000333 intervals to obtain point cloud data of the same capacity. Since the Mastercam method is generated directly by the software, it does not participate in the speed evaluation of the algorithm. Setting the error threshold to con =0.1 mm, the experimental situation is as follows: Figure 6 shows the toolpaths generated by the four methods. It is obvious that the D-P method, the equal chord error method, and the Mastercam all approximate the original curve with continuous straight line segments, and the greater the curvature, the more discrete points. Instead, the DHS algorithm discretizes the original curve into a combination of circular and linear segments, which significantly reduces the number of trajectory segments. The experimental data are listed in Table 1.
In Table 1, N denotes the initial iteration point, n denotes the discrete points of the toolpath generated by the algorithm, max denotes the maximum chord error, t is the program running time, and L denotes the total length of the toolpath obtained by the corresponding method in the table. Since the memory and CPU usage of the computer is a dynamic process, the time in the table is the average value of the program run 10 times. It is clear from the data in Table 1 that the toolpath generated by the DHS algorithm has the least number of data points under the same accuracy constraint, which is 74.4% less than the D-P algorithm, 63.93% less than the equal chord error method, and 75.56% less than the Mastercam method. In fact, this great difference can be explained mathematically and geometrically, as illustrated in Fig. 7.   Fig. 7, the same curve is approximated using continuous straight-line segments and circular arc segments, and it is obvious that when the error threshold and curve length are the same, the straight-line segments are more wasteful in terms of quantity. Considering that the length of the straight-line segment is very small in actual machining, the local curve can be approximated as a circular arc with R as the radius, as shown in the dashed box in the figure. Therefore, it is not difficult to deduce from the Pythagorean theorem that where L is the length of the linear segment and its relationship with R and com can be expressed as Since com is usually a small positive number in actual processing, it is easy to see that com is positively correlated with L. Taking partial derivatives of Eq. (26) yields Therefore, there is also a positive correlation between R and L, which means that when the curvature becomes larger (R decreases), the length of straight-line segments becomes shorter, thus increasing the number of trajectory segments.
In terms of program speed, among the three methods besides the Mastercam, the D-P method has the longest running time and the equal chord error method has the shortest. Although the DHS algorithm is slower than the equal chord error method, it still maintains a fast speed of 1.54 s. For contour accuracy, all four methods mentioned above meet the established requirements. In addition, the difference between the length of the tool trajectory and the original curve can reflect the cumulative error to some extent. From this perspective, the total length of the toolpath generated by the DHS algorithm is closer to the actual value, and therefore the cumulative error is minimal.
The data in Table 2 reflect the performance of the four methods in terms of contour accuracy when the number of discrete points is the same.
As seen from the data in Table 2, when n = 100, the maximum contour error of the DHS algorithm is reduced by 96.67% compared to the D-P algorithm, 93.67% compared to the equal chord error, and 97.29% compared to the commercial software Mastercam. The improvement in accuracy is more than one order of magnitude, which means that the method in this paper can obtain higher accuracy with the same number of tool trajectory segments. In addition, the difference between the trajectory length of the DHS algorithm and the original curve length is only 0.0003 mm, which remains the best among the four methods.
The above analysis demonstrates the great potential of the DHS algorithm in terms of accuracy and toolpath compression, while the latter is inseparable from the length of the G-code. Therefore, the algorithm is promising for improving the machining quality and efficiency of economic machine tools.

The analysis of speed fluctuations
High-speed machine tools can often achieve feed rates of several hundred millimeters per second or more. Since the motility of the machine tool is limited, there are  . 7 Toolpaths generated by the four methods frequent accelerations and decelerations in the machining method of continuous short-line segments, which brings difficulties and challenges in high-speed machining. Therefore, the primary purpose of this section is to verify whether the tool trajectory generated by the DHS algorithm has smoother speed fluctuations compared to other methods for the same feedrate control algorithm. The volatility of the feedrate will be analyzed by simulation due to the lack of high-speed machine equipment.
The circular corner velocity articulation model in the literature [24] is used and tested by a seven-segment S-shaped velocity planning algorithm. Set the maximum acceleration A = 500 mm/s 2 , Jerk J = 5000 mm/s 3 , and programming speed F = 100 mm/s. The experimental results are shown in Fig. 8. Figure 8 shows the feedrate curves obtained by the S-type speed planning algorithm. In terms of running time, the DHS algorithm reduces 69.71% compared to the D-P algorithm, 65.14% compared to the equal chord error method, and 70.71% compared to Mastercam, which shows that the DHS algorithm can reach a higher feed rate and improve machining efficiency.
The above experiments show that the DHS algorithm can reduce the number of accelerations and decelerations by compressing the number of toolpath segments. In addition, the reduction in number means an increase in the length of each trajectory segment, which gives the machine enough time to accelerate to a higher speed. Thus, the DHS algorithm both slows down the speed fluctuations and increases the machining efficiency.

Analysis of physical experiments
To verify the realistic possibility of the proposed method in this paper, we experimented with a vertical CNC machine. For cost reasons, the experiment was conducted only with the commercial software Mastercam as a comparison. The equipment used in this experiment is a VDL-600A vertical machining center, a piezoelectric three-way force measuring instrument YDCB-III05B, and a digital microscope, as shown in Fig. 9.
To ensure the comparability of the experimental results, the same type of tools, materials, and processing parameters were used for the experiments, as shown in Table 3.
The laps in Table 3 indicate the number of CNC program cycles, the purpose of which is to cut the material to a sufficient depth to allow the surface quality of the contoured sides to be observed. The performance of the DHS algorithm and the Mastercam in terms of machining surface smoothness and cutting force fluctuations will be analyzed in this section. Setting the contour error threshold con = 0.1 mm, the experimental results are shown as follows: Figure 10 shows the overall machining results obtained by the Mastercam and the DHS algorithm. The four zones of large curvature are marked with red dashed boxes, and the sides of each zone are photographed separately with a digital microscope, as shown in Figs. 11 and 12. The green axis in the figure is the measurement scale of the microscope, each small scale has a length of 0.1 mm, and the red numbers are the length data obtained by the measurement function.   It is clear from Fig. 11 that the machined surface of the workpiece in the region of large curvature is not smooth, even though the contour error threshold satisfies the established value. The measurement data from the microscope indicated that the minimum length of the cut segment in the local area was approximately 0.86 mm, while the maximum exceeded 2 mm. Therefore, more discrete points are required to obtain a smoother machined surface, which will undoubtedly increase the burden on the CNC machine. The zoomed-in view of the local area shown in Fig. 12 corresponds to the DHS algorithm. Compared to the Mastercam method shown in Fig. 11, the DHS algorithm achieves a smoother machined surface for the same contour error threshold. Combined with the data in Table 1, it is easy to see that the DHS algorithm can achieve better machining quality with fewer toolpath segments under the same contour error constraint.
The cutting force is an essential factor often considered in CNC machining, and its frequent changes can cause shock and vibration in the machine tool, thus affecting the machining quality and even shortening the life of the cutter and equipment. Given the overwhelming amount of cutting force data generated during the machining process, the article only intercepts the force data generated when the cutter runs to zone 2 for analysis, as shown in Fig. 13.
As shown in Fig. 13, there is no significant abrupt change in cutting force for the DSH algorithm, and the overall trend is relatively smooth as the curvature of the tool trajectory changes. In contrast, the Mastercam method shows significant mutations and fluctuations. In addition, the stepped black dashed line in Fig. 13b reflects the changing characteristics of the cutting force, which means that the cutting force between adjacent tool trajectory segments also changes abruptly. Therefore, compared with the Mastercam method, the DHS algorithm can make the machining process more stable.

Conclusions
1. In this paper, the least squares-based toolpath smoothing and compressing algorithm is proposed to address the problems of heavy G-code volume, low machining quality, and efficiency in traditional continuous shortline segment machining. A simple and effective doubleheaded snake (DHS) algorithm is designed to implement the process by discretizing the complex curves into a combination of linear and arc segments. 2. Compared with the equal chord error method, D-P algorithm, and commercial CAM software, the DHS algorithm can obtain fewer trajectory data with the same constraint of contour error threshold, and the amount of trajectory data of the DHS algorithm is 63.93%, 74.4%, and 75.56% less than the above three methods, respectively. In addition, when the number of trajectory segments is the same, the contour error of the DHS algorithm is reduced by more than one order of magnitude compared to the equal chord error method, the D-P algorithm, and the Mastercam.
The DHS algorithm is experimentally validated to be suitable for economical CNC machines and can achieve excellent machining quality. In a practical sense, this method can enhance the ability of low-and mid-range machine tools to handle complex curves, thus improving the overall performance of these machines. Perhaps this would be a good solution for those companies that want to improve the machining quality but lack high-end machine equipment. In the subsequent research, we intend to develop the corresponding function module in the sheet metal processing system (SheetCUT_CAM V1.0) owned by our laboratory. The G-code can be output by simply entering the spline curve, the error threshold, and the cutter information.
Author contribution LZ completed the theoretical analysis, experimental design, and manuscript writing. JL is responsible for collecting literature and organizing experimental results. CO and JM assessed the feasibility of the methods and provided supporting analyses. XL was responsible for guiding the research direction and methodology and received grant support. All authors read and approved the final manuscript.
Funding This research is supported by the National Natural Science Foundation of China (NSFC) (grant no. 52165062) and Guangxi Natural Science Foundation Program (grant no. 2020JJD160004).

Data availability
The datasets used or analyzed during the current study are available from the corresponding author on reasonable request.
Code availability Not applicable.

Declarations
Ethics approval and consent to participate All authors agreed with the consent to participate.