Improved Particle Swarm Optimization Algorithm Based on a Three-Dimensional Convex Hull for Fitting a Screw Thread Central Axis

To meet the needs of three-dimensional (3D) measurement and to achieve the high-precision fitting of the central axis of a screw thread, this study performed complex processing of the 3D structures on the surface of the thread central axis. Moreover, this study examined the problems of long processing time and low accuracy caused by the use of a point cloud with a large data volume. An improved particle swarm optimization algorithm was used to develop a fitting method for the central axis of the three-dimensional (3D) thread of a 3D convex hull. SolidWorks was used to simulate the 3D parts of a standard thread, and the Point Cloud Library was used to generate a 3D simulated point cloud for the thread surface. The maximum deviation between the fitted line and the line obtained in the two-dimensional (2D) projection method was $0.12~\mu \text{m}$ . An experiment was conducted using data regarding the tip of the plug gauge surface. The variation in the distance between the obtained straight line and the 3D point cloud was smaller than that between the obtained straight line and the 2D point cloud. Moreover, the calculation speed was higher when using the 3D method than when using the 2D method.


I. INTRODUCTION
A screw thread is a complex three-dimensional (3D) structure with a spiral shape and a specific cross-section geometry. Screw thread measurements are performed on the section passing through the central axis of the screw thread [1].
At present, in 3D measurement, the method of determining the central axis of thread gauge still relies on the experience of the engineer to manually adjust, which not only increases the difficulty of subsequent measurement, but also increases the uncertainty of measurement results. In recent years, with the implementation of major instrument science and equipment development projects, it is very necessary to design a method that can quickly and accurately fit the central axis of the thread [2].
The associate editor coordinating the review of this manuscript and approving it for publication was Xujie Li . In order to obtain the precise data of the axis of the thread, Current screw thread testing instruments, such as the screw thread comprehensive measuring instrument, scan the screw thread along three dimensions [3] and obtain needle tip measurement data for the screw thread surface to form a point cloud. Then, a mathematical model is established and solved using a suit able fitting algorithm.
The fitting method usually adopts the least square method to calculate the minimum variance of the distance from the point cloud to the central axis to fit the central axis [4]. Due to the complexity of the surface morphology of the thread, dense point clouds are needed to describe it, which makes the calculation time required by the least square method too long and cannot adapt to the feature of large data volume brought by the smaller and smaller scanning resolution of the 3D measurement probe.
The selected optimization algorithm such as least square method (LS), mountain climbing (MC) algorithm, simulated annealing (SA) algorithm, and genetic algorithm (GA), must be able to process considerable data systematically and accurately. Furthermore, it should be able to avoid local optima to prevent errors caused by premature convergence [5].
Particle-Swarm Optimization (PSO) algorithm is one of the most popular metaheuristic algorithms [6], This algorithm was first proposed by Eberhart and Kennedy in 1995 [7]. Compared with other algorithms, the PSO algorithm has high calculation speed and accuracy. Numerous mathematical models have been designed to handle large amounts of data [8]. When particle swarm optimization is used to deal with multi-objective problems, the action range can vary over time to expand the search capability and avoid the premature convergence [9]. In 2019, the authors accelerated the algorithm particle optimization time by filtering out relevant and weakly relevant features [10]. Particle swarm optimization (PSO) algorithm is used to find the optimal wavelet transform parameters and to de-noise of electroencephalogram [9], [11]. PSO adjustment of adaptive parameters can make the population diversified and effectively improve the speed and accuracy of particle optimization [12], [13]. Mongpei and Liping found that appropriate changes in the inertia weight during iteration can significantly improve the optimization accuracy and convergence speed of the unimodal function as well as increase the optimization probability of the bimodal and multimodal functions [14].
You can find PSO algorithm tends to improve the weight fitness [15] to compensate for its tendency of falling into local optima. Therefore, to meet the aforementioned criteria, this study adopted a random incremental algorithm to calculate the 3D point cloud convex hull (CH) of the screw thread surface and filter out the point cloud of impurities on the outer surface of the screw thread for preventing the defect point cloud from influencing the alveolar surface and screw thread surface. A mathematical model for central axis fitting was established by minimizing the variance in the distance between the points on the screw thread surface and the central axis. The central axis fitting problem was converted into an optimization problem. An improved intelligent optimization algorithm, namely the improved particle swarm optimization (IPSO) algorithm, was used with the mathematical model to fit the screw thread axis. In this paper, chapter II introduces the mathematical model of the central axis, chapter III introduces the principle of IPSO algorithm, and chapter IV verifies feasibility of IPSO algorithm for fitting a screw thread central axis by experiment.

II. MATHEMATICAL MODEL OF THE SCREW THREAD AXIS
All the points on the central axis of the screw thread are located at the same distance from the screw thread outer diameter (or inner diameter) on a horizontal section. According to this characteristic, two points A (x a , y a , z a ) and B (x b , y b , z b ) are found within the nominal diameter of the screw thread. When the variance of the straight-line distances from a point in the point cloud data to the points A and B are minimized, the straight line determined by the points A and B is the central axis of the screw thread. The equation of this straight line can be expressed as follows: l : where x l , y l , and z l are the coordinates of the points on the straight line l.
Considering the aforementioned information, the problem of determining the central axis of the screw thread can be transformed into an optimization problem in which the coordinates of two points are determined subject to restrictions. Let M (x i , y i , z i ), i = 1, . . . , N , represent coordinate points in the point cloud dataset. The distance [16] from line l to M (x i , y i , z i ) is expressed as follows: After obtaining the set of distances from the point cloud to the line l, the variance of the distance set is calculated using the following equation: From Equations (1) -(3), the objective function can be obtained as follows: When substituting the point cloud data, the parameter values of x a , y a , z a , x b , y b , and z b for the smallest s 2 value are the coordinate points that must be achieved. The parameter set θ and the point cloud coordinate set X are set. Therefore, the mathematical model of the central axis of the screw thread can be expressed as follows:

III. IPSO ALGORITHM BASED ON A 3D CH A. CH
The CH is a basic concept in computational geometry. The definition of a 3D CH [17] is provided in the following text. For a set of discrete points in space, the CH is the convex polyhedron that contains all the points in the point set. In this study, the random incremental algorithm was used to obtain the CH of the screw thread point cloud, and the points defining the CH were arranged into a point set. The screw thread CH point set filters out the screw thread alveolar, hardware defects, and the interference point cloud formed by the scanning error, which reduces the calculations to be conducted by the algorithm, decreases the running time of the algorithm, and enhances the accuracy of the calculation.

B. IPSO ALGORITHM
The IPSO algorithm is an improved version of the PSO algorithm. In this study, the PSO algorithm is a bionic algorithm that assigns speed and direction to random particles within a parameter interval and randomly searches for the six-dimensional parameters that make Equation (4) valid.
When the PSO algorithm is used to fit the central axis, the result can be easily trapped by local optima because the screw thread parameter area is large; thus, erroneous results can be obtained. In the framework of the PSO algorithm, the coefficient that affects particle velocity is called the inertia weight factor. A high inertia weight factor allows the PSO algorithm to escape the local optima and facilitates global search, whereas a low inertia weight factor is conducive for a local search. Algorithm convergence is facilitated when a precise local search is conducted in the parameter region [18].
To prevent the premature convergence of the PSO algorithm, the inertia weight factor of the PSO algorithm was adaptively adjusted in the IPSO algorithm.

C. CH-IPSO ALGORITHM
By using the standard PSO algorithm, this study calculated the point cloud CH to filter out the errors caused by the screw thread alveolar and screw thread surface defects before performing calculations using the screw thread point cloud data. The inertia weight factor was updated prior to the optimization of each generation of particles [19]. The flowchart of the IPSO algorithm based on a 3D CH is displayed in Figure 1.

1) PROCESSING OF THE POINT SET OF THE 3D CH
The CH is calculated to obtain the point set that describes the smallest polyhedron containing all the points in the point cloud. This calculation can be achieved using a suitable algorithm.
The screw thread surface point cloud is a 3D cloud that contains a massive amount of data. The random incremental algorithm is used to calculate the CH effectively and quickly [20]. The calculation process is as follows: (1) First, use the filter function to find a boundary point P 1 on the x, y, and z axes, such as the point with the smallest x, y, and z values.
(2) Set two random points P 2 and P 3 that are not collinear with P 1 . Then, find a fourth point P 4 that is not coplanar with these three points to form a tetrahedron.
(3) If a new point P i is inside or on the boundary of the CH, the point is ignored. When a new point P i is outside the CH, as displayed in Figure 2(a), the horizontal plane of the original CH relative to P i must be calculated, as shown in Figure 2(b). Delete all the faces that can be observed from P i , and connect the points on the horizontal edge with P i to form a new CH, as illustrated in Figure 2(c).
(4) Traverse the remaining points in turn to form a 3D CH point set.

2) PARAMETER INITIALIZATION
The central axis is located inside the point cloud of the screw thread surface. Moreover, the maximum and minimum coordinate values of the two points of the fitted straight line do not exceed the sample point cloud data interval. Six parameters are initialized and limited to the value range of the sample point cloud, which can include points on the surface of the screw thread.
Then, the interval between A and B on the central axis can be limited as follows: The number of particles affects the calculation efficiency of the algorithm. When the number of particles is high, the calculation time of each iteration is long. When the number of particles is low, the iteration speed is high and premature convergence can easily occur. When fitting a low-order objective function for the central axis of a screw thread, high efficiency is achieved when the number of particles is < 100 [21]. After many experiments, the number of particles was set as 50 in this study.
A total of 50 particles (Particle jd (V jd , X jd )) with different velocities (V ) and positions (X ) are scattered in the parameter interval, where j is the particle index (j = 1, 2, . . . , 50) and d is the parameter index of the particle (d = 1, 2, . . . , 6). The particles are randomly distributed in the parameter interval, and the initial velocity of each particle is set to any value between 0 and 1, excluding 0 and 1.

3) FITNESS CALCULATION
Fitness is the criterion for judging the position of each particle. The central axis fitting model is used to determine whether two points achieve the optimal solution. Thus, the fitness p of the IPSO algorithm is equal to the value of the parameter θ corresponding to the current objective function f . This study adopted two types of fitness: the personal leader P jd = {P j1 , P j2 , . . . , P j6 }, j = 1, 2, . . . , 50, and the global leader P gd = {P g1 , P g2 , . . . , P g6 }. The self-optimal fitness is the position parameter corresponding to the optimal objective function value of the particle from the algorithm initiation to the present iteration. The global best fitness is the position parameter corresponding to the optimal solution of all particles from the algorithm initiation to the present iteration.

4) UPDATING THE PARAMETER
In the standard PSO algorithm, the inertia weight is fixed, which considerably limits the flexibility of the algorithm. For a large amount of data, complicated calculation, and long optimization time, the standard PSO algorithm always achieves premature convergence. The inertia weight formula used in this study is as follows: where f avg is the average value of the objective function from initiation to the present iteration, f best is the optimal objective function value from the initiation to the present iteration, w max is the maximum value of the inertia weight factor, and w min is the minimum value of the inertia weight factor. When the target values of the particles converge or tend to a local optimum, the inertia weight is increased. Moreover, when the target values of the particles are relatively dispersed, the inertia weight is decreased. For particles whose objective function value is less than the average target value, the inertia weight is low; thus, the particles are retained. By contrast, for particles whose objective function value is higher than the average target value, the inertia weight is high, which causes the particles to move to a better search area. The particle position and velocity represent the parameter data and optimization ability, respectively. The updating formulas for the particle velocity V and position X are as follows: where t is the number of iterations, c 1 and c 2 represent the individual and social learning factors, respectively. Each particle decides the position and speed of its next movement according to its optimal experience p jd and the global optimal p gd . The parameters r 1 and r 2 are random numbers ranging from 0 to 1. These parameters increase the diversity of the movement of the population particles.

5) TERMINATION PRINCIPLE
The algorithm is terminated when the number of iterations reaches a preset value or the target function iteration area is stable after multiple iterations.

IV. EXPERIMENTAL ILLUSTRATION A. SIMULATION
MATLAB software (MATLAB, MathWorks, Natick, MA, USA) was used to execute the IPSO algorithm based on a 3D CH for fitting the screw thread axis. The feasibility of the IPSO algorithm was verified by comparing the results with those of the projection method. SolidWorks 2012 (Dassault Systemes, Waltham, MA, USA) was used to draw a 3D model of a common internal screw thread surface with a nominal diameter of 80 mm and pitch of 4 mm according to the screw thread minor diameter and pitch diameter data of ISO general purpose metric screw threads (Part 1, Table 1) [22]. As displayed in Figure 3   used a common two-dimensional (2D) projection method to verify the results [23].
The 3D point cloud was projected to the xOy and yOz planes for calculating the center line on the projection surface. The obtained center line was used as a surface. The straight line was determined according to the intersection of two nonparallel surfaces [24]. The general equation of the central axis is given as follows: The calculation result displayed in Figure 5 was obtained when using the random incremental algorithm to calculate the CH of the 3D point cloud of the external screw thread.
The 3D point cloud of the external screw thread obtained after calculating the CH was imported into MATLAB; the parameter interval was limited to the point cloud area, and the number of particles was set as 50. Both the individual and social learning factors (c 1 and c 2 , respectively) had a value of 2. The maximum value of the inertia weight w min was 0.8; the minimum value of the inertia weight w max was 0.6; and the maximum number of iterations t max was 100. The IPSO algorithm was used to fit the simulated screw thread surface. Figure 6 displays the 3D fitting result of the central axis of the screw thread.
The coordinates of the two points determined by fitting the screw thread center axis by using the IPSO algorithm based  Figure 6 indicates that the straight line fitted using the projection method was approximately in agreement with the straight line fitted using the CH-IPSO algorithm.
This study used the maximum distance between the ends of two straight lines within the screw thread length to evaluate the degree of coincidence between the two straight lines. The flowchart of the Eva algorithm for the degree of coincidence is presented in the following text.
(1) For generating the parametric equations of the upper and lower sections (t 1 and t 2 ), the upper and lower extreme points are considered as the points on the surface and the fitted straight line is considered as the normal vector.
(2) The x, y, and z values of the intersection of the upper section t 1 , the known straight line, and the fitted straight line are obtained. The x, y, and z values of the intersection of the lower section t 2 , the known straight line, and the fitted straight line are also obtained.
(3) The Euclidean distances Eva 1 and Eva 2 between the ends of the fitted straight line and the known straight line are calculated.
(4) The max function is used to determine the maximum values of Eva 1 and Eva 2 .
Equation (1) was used to calculate the sum of the squares of the distances from l ty1 and l pso1 to the point cloud of the external screw thread. Moreover, the degree of agreement between l ty1 and l pso1 was calculated as presented in Table 1.
The screw thread center axis fitted using the IPSO algorithm based on a 3D CH was the same as the straight line fitted using the 2D projection method. Thus, the obtained simulation result was correct.

B. EXPERIMENTAL VERIFICATION
To verify the practicality of the IPSO algorithm, an SJ5900 high-precision 3D screw thread comprehensive measuring instrument with a resolution of 0.01 µm was used for establishing and measuring a screw thread plug gauge with the M80 × 4.6H specification. The tip data of the screw thread plug gauge were obtained using this instrument in cylindrical coordinates, as displayed in Figure 8. After coordinate transformation, the screw thread tip data displayed in Figure 9 were obtained.
The parameter interval was set to be restricted within the point cloud value area, and the 2D projection method was used to verify the IPSO algorithm. The algorithm parameters  w min = 0.6, and t max = 100. MATLAB was used to perform fitting with the IPSO algorithm. The resulting image is displayed in Figure 10.
The straight lines fitted using the projection method and IPSO algorithm can be expressed as follows: Equation (1) was used to calculate the sum of the squares of the distances from l pso2 and l ty2 to the tip data. The method presented in Section 3.1 was used to calculate the degree of agreement between l pso2 and l ty2 . To compare the running speeds of the IPSO and projection methods, these methods were implemented in MATLAB on a computer with an AMD Ryzen 5 4600H processor, and the results are listed in Table 2: Table 2 indicates that the conformity evaluation parameter (Eva) of the lines l pso2 and l ty2 obtained with the IPSO algorithm and projection method, respectively, was 0.27 µm. The variance of the distance between the line l pso2 and the point cloud obtained with the IPSO algorithm was smaller than the projection square; thus, the straight line l pso2 was closer to the true straight line than the straight line fitted using the projection method. Moreover, the IPSO algorithm required 4.21 s to fit a straight line and was faster than the projection method under the same hardware conditions.

C. COMPARISON EXPERIMENTS WITH OTHER ALGORITHMS
In order to compare the processing effect of the CH-IPSO, this paper combines IPSO with the latest algorithm [4] to fit the screw thread's central axis and the heuristic algorithm born in recent years. Monarch butterfly optimization (MBO) [25], Earthworm optimization algorithm (EWA) [26], Elephant herding optimization (EHO) [27], Moth search (MS) [28] algorithm based on B's data for comparison experiments. The MATLAB program was compiled on the computer with an AMD Ryzen 54600h processor. The minimum distance variance of the line obtained by above algorithms and B's data is calculated, and the change in the minimum variance of algorithms is shown in Figure 10. The experiment was repeated for 10 times, and the experimental results were shown in Table 3.
Combined with Figure 10 and Table 3, we can see that the proposed IPSO algorithm shows stronger stability and precision in the problem of fitting the central axis in the screw thread point cloud. In terms of processing speed, although it is not as fast as LS, its minimum variance is smaller than LS and closer to the real value. The MBO are suitable for the high-order function problem, but have poor performance in the low-order problem like the screw thread central axis's fitting. The single experiment optimization results of EWA, EHO and MS did not oscillate. However, due to the failure to filter out the disturbance point cloud, the results obtained from repeated experiments often changed, which could not be used in the current practical application of high-precision 3D thread measurement.
The 3D CH-IPSO algorithm can be used to process big data, has a short calculation time, has a high fitting accuracy, and provides accurate results. The 3D measurements have practical and experimental reference value.

V. CONCLUSION
In this study, a mathematical model was established for the central axis of a screw thread. Moreover, the 3D CH-IPSO algorithm was proposed to fit the screw thread central axis. The proposed method was evaluated using MATLAB software, SolidWorks 2012, and an SJ5900 high-precision comprehensive 3D screw thread measuring instrument. A 3D simulation and repeated experiment were conducted, and the following conclusions were obtained: First, the IPSO algorithm based on a 3D CH is feasible for fitting the central axis of a screw thread with a large amount of data.
Second, the proposed IPSO algorithm exhibited a higher accuracy for fitting the screw thread tip data measured using a screw thread comprehensive measuring instrument compared with fitting the straight line using the 2D projection method.
Third, although the IPSO algorithm proposed in this paper is not the fastest in processing speed, its accuracy is higher and it is more stable than other algorithms in fitting the axis in the screw thread point cloud.
Fourth, although other metaheuristic algorithms can get smaller variance, their stability is not as good as the proposed IPSO, which also indicates that the accuracy of the proposed IPSO can continue to improve. And we argued that the reason why we got the smaller variance is because the particle took longer to search. In subsequent experiments, the researcher can apply other metaheuristic algorithms to the study of fitting the high-precision screw thread central axis. In practical applications, the researcher can improve the processor to add the operation speed of the heuristic algorithm.
Due to the proposed IPSO's algorithm designed for the general purpose metric screw thread, this algorithm has limitations in other screw thread central axis problems. But the proposed IPSO algorithm solves the problem of 3D measurement and has a high calculation speed. The highprecision screw thread measurement results have practical and experimental reference value.
BO ZHANG was born in 1983. He is currently a Senior Engineer in Dongyang, Zhejiang. He has been in charge of or undertaken many national quality foundation major projects, national major instrument development special projects, and other national projects. His main research interest includes precision measurement and standardization. He won the Gold Award of Excellent Invention once and the Second Prize of Scientific and Technological Progress once.
YUNXIA FU was born in Henan. She is currently a Senior Engineer and a Metrological Testing Expert with the Shanghai Institute of Measurement and testing Technology. She is also a member of the National Geometric Length Measurement Technical Committee and the Optical Testing Professional Committee of the Chinese Optical Society, and the Vice Chairman of the Working Group of Nanometer Testing Technology Standardization of the National Technical Committee for Nanotechnology Standardization. She is a Provincial Evaluation Member of National Legal Metrological Verification Institution, a Second-Level Evaluation Member of National Metrological Standards, a National Metrological Permit Evaluation Member, an Expert of Shanghai Municipal Government procurement review and evaluation, and an Expert of Shanghai Municipal Engineering Equipment Supervision Bidding and tendering expert database. She has been responsible for or participated in a number of scientific research projects, two of which won the Second Prize of Shanghai Science and Technology Progress Award. As an Editorial Board Member, she has participated in the compilation of the national length metrology personnel training materials, and has published about 15 articles in both Chinese and English in professional journals at home and abroad.