Dynamic Numerical Simulation of Curved Surface Coating Trajectory Based on STL Slicing Algorithm

: The thickness of the coating on the surface of a workpiece is an important factor in determining the quality of spraying. However, it is challenging to estimate the distribution of film thickness accurately before the actual spraying process. This lack of estimation hinders the optimization of spraying process parameters and trajectory. To overcome this, a numerical simulation of surface spray coating thickness was conducted to provide guidance for the actual coating process. The research consists of three main parts. Firstly, the spray trajectory of the spray gun is determined using the proposed Stereo Lithography (STL) model slicing algorithm. Secondly, a two-phase flow spray model and collision adhesion model are established to construct the spray film model. The surface mesh is determined, and the spraying process parameters are set. Finally, numerical simulation is conducted to analyze the dynamic spraying trajectory and the distribution of coating thickness. The results show that the coating thickness distribution on an arc surface is thicker in the middle and thinner on the edges. The distribution is symmetric with respect to both the transverse and longitudinal directions of the arc surface. The coating thickness distribution at both ends is not as uniform as in the middle section. The concave part of the free surface has the largest coating thickness, while the coating thickness distribution on the convex part is not as uniform as on the relatively flat part. This method of simulating the coating thickness distribution on complex surfaces provides a solid foundation for further optimization of spraying process parameters and trajectory, ultimately improving the qualification rate of workpiece spraying processing.


Introduction
As an advanced spraying equipment, the spraying robot has been widely used in various fields, including automobile, aerospace, and ships, due to its ability to handle complex curved surfaces [1].The spraying robot offers numerous advantages, such as improving the working environment, enhancing spraying efficiency, and overall spray quality.Currently, much of the research focuses on trajectory planning for the spraying robot.In these studies, the film-forming model of the spray gun is established by simplifying or disregarding certain spraying process parameters.The optimization of spray film thickness uniformity is achieved by adjusting process parameters like spraying speed [2] and trajectory spacing [3].However, even with the optimized spraying process parameters and track, there may still be areas on the workpiece where the film thickness does not meet the required standards due to model errors introduced by simplification.Therefore, it is necessary to conduct numerical simulations of spraying before the actual spraying process to evaluate the coating quality.
The research on numerical simulation of the spraying process has yielded several results.Chen et al. [4] utilized the Euler-Euler approach to establish a spraying film-forming model for a spray gun.They conducted spray simulations on both concave and convex surfaces, including plane and arc shapes.Jae et al. [5] employed computational fluid dynamics (CFD) to simulate the spray characteristics of closed and open swirl injectors numerically.They also examined different turbulence models and analyzed their impact on the simulation results.Xie et al. [6] investigated the influence of spraying parameters on the spray flow field and coating thickness distribution via numerical simulation.As shown in Figure 1, the Z-axis is the long axis of the spray cone, and the X-axis is the short axis of the spray cone.They found that the coating becomes more concentrated as the pressure decreases.Additionally, as the air pressure increases, the film length on the Zaxis increases while the film length on the X-axis decreases.Ye et al. [7] performed CFD spraying numerical simulations on three different sprayers.The results revealed distinct droplet characteristics among the three types of nebulizers, which significantly affected the film formation.Huo et al. [8] focused on addressing the issue of uneven pesticide spraying on apple fruit trees.They optimized the parameters of the sprayer model and conducted numerical simulations for each parameter using FLUENT 18.0 software.Chen et al. [9] conducted numerical simulations of spraying on flat surfaces, as well as inner and outer cylinder surfaces.Their study discovered variations in the thickness between the three points.Muddapur et al. [10] conducted a simulation on the transient characteristics of pulsating isooctane spray in a pressure swirl atomizer.The simulation results indicate that as the ambient pressure increases, the spray layer becomes narrower, and the penetration decreases.Du et al. [11] proposed an improved air-assisted spray simulation method based on ANSYS FLUENT, which resulted in a 13.5% reduction in mean errors for spray volume and a 10.2% reduction in mean errors for penetration.Yang et al. [12] utilized the Euler-Lagrange theorem to simulate the particle size distribution of high-pressure spray using FLUENT.The results demonstrated a 90% dust removal effect under a pressure of 8 MPa.Xia et al. [13] employed the curvature circle method to develop a spray model for a free surface.The experimental results of the film thickness on the cylinder surface aligned well with the theoretical results.Wang et al. [14] investigated a novel twinnozzle air spray gun configuration and observed that an inadequate distance between the two nozzles resulted in suboptimal spraying effects.Ye et al. [15] examined the airless and air-assisted spraying processes via experiments and simulations.Chen et al. [16][17][18][19][20] studied the influence of different spraying parameters on film thickness uniformity.Liu et al. [21] employed simulation methods to study the flow of gas and coarse powder in the electrostatic process.Chen et al. [9] focused on the plane spray process and identified the significant impact of spraying height and angle on film thickness uniformity.Ye et al. [22] discovered a correlation between droplet particle size distribution and atomization air volume as well as forming air volume.Chen et al. [23] investigated the distribution of Vshaped surface coatings and observed a bimodal distribution in coating thickness.Chen et al. [24] conducted research indicating that the coating thickness of the arc section is greater than that of the plane section.The literature mentioned above only focuses on the numerical simulation of static and dynamic spraying on plane and arc surfaces.However, there is a research gap in the area of dynamic spraying numerical simulation for the combination of spray gun trajectory and spray gun film-forming flow field on complex surfaces.This paper introduces the use of the STL slicing algorithm to generate key trajectory points of the surface.The positions and attitudes of the spray gun with respect to time are fitted using appropriate expressions.The gun motion trajectory is determined using the first derivative of the gun positions and attitudes, which are defined by the UDF script as velocity and angular velocity.Additionally, a two-phase spray model and a collision adhesion model are established to construct the spray field.The curved surface spraying trajectory expression is set by writing a UDF script.Finally, numerical simulation and analysis are conducted to determine the coating thickness distribution of the curved surface.

Basic Ideas of the Algorithm
Firstly, 3D modeling software is used to create a model of the workpiece.The accuracy is adjusted by modifying the chord height and step size of the workpiece.The model is then exported and saved as an STL file in ASCII format.
The 3D model in STL format represents the geometric shape of an object's surface using multiple triangular faces.The accuracy of the surface of the 3D object is primarily determined using the chord height and step length.Each triangular surface records the coordinate information of the three vertices and the normal vector of the triangular surface.Its data format is stored as follows: facet normal nx ny nz outer loop vertex x1 y1 z1 vertex x2 y2 z2 vertex x3 y3 z3 endloop endfacet Among them, the first line is the normal vector data of the triangle piece pointing to the outside of the entity, the third to fifth lines are three vertex coordinate information, and the three vertices are sorted along the right-hand spiral direction of the triangle piece normal vector.
Next, the STL file is read into a matrix.After organizing and filtering the data, multiple tangent planes are established using layered planes.The intersection points of the triangular faces are determined for each layered plane.These intersection points are then translated by a distance equal to one spraying distance along the normal vector of each triangular face, and they serve as the key nodes for the trajectory of the spraying gun.The Z-axis is inverted from the normal vector of the corresponding triangular plane for each intersection point, while the X-axis is parallel to the tangent vector of the trajectory.The Y-axis is obtained by taking the cross product of the Z-axis unit vector and the X-axis unit vector.The positions and orientations of the key nodes in the spray gun trajectory are combined into a homogeneous coordinate transformation matrix.The spray gun angle is determined using a fixed angle coordinate system X-Y-Z.Finally, the position and orientation of the spray gun over time are expressed using polynomial fitting.

Implementation Process of the Algorithm
(1) Data reading and integration To ensure higher readability, the research focuses on using the object surface shape of STL files in ASCII format to generate spray gun trajectories.The coordinate information of the three components and three vertices of the normal vector for each facet is defined in the STL file in ASCII format, following the right-hand rule.
To follow this rule and read each of the triangles, we need to convert them into an nby-12 matrix.In this matrix, the first nine columns represent the X, Y, and Z coordinates of the three vertices of each triangle.The last three columns represent the three components of the normal vector of the plane.The representation is as follows: In this way, a triangular sheet is read.Repeat this step one by one so that all the triangles are extracted.
(2) Data screening For complex curved surfaces, the fluctuation range of film thickness is limited, which necessitates the spray trajectory to closely match the free surface profile.As a result, the accuracy of chord length and step size when saving as an STL file becomes crucial.It would be inefficient and wasteful of computational resources to iterate through all triangles.Therefore, a screening process for triangular facets is necessary.
There are three positional relationships between the slice plane and triangular plane: phase separation, tangent, and intersection.When the tangent plane is separated from the triangular plane, there is no intersection between the slice plane and the triangular plane.In such cases, it is important to remove the information about the separated triangles from the numerous triangles.The specific steps for this process are as follows: 1. Enter the height ℎ  of each slice plane; 2. The minimum value   and maximum value   in the third, sixth, and ninth columns of each row were obtained from matrix A; 3. If  min ≤ ℎ i ≤  max , all data in this row will be saved in another matrix B j .Otherwise, the row is discarded; 4. Repeat steps (a) to (c) successively until all section plane calculations are completed.
(3) Solve for the coordinate values of key intersecting nodes Through step (b), the triangular faces that intersect the slice plane have been eliminated.This step calculates the intersection of all important nodes and the slice plane.Figure 2   In general, the tangent plane intersects two sides of each triangular face.To start, we select an arbitrary triangular face from the set and assign it the label 1.We then locate the vertices  min and  max of this triangle.Next, we calculate the intersection between the edge of the triangle where these two vertices are located and the tangent plane.This intersection information is stored in a matrix C. Furthermore, we save the normal vector information of the triangular face, forming a n-by-6 matrix.Once the information on these two vertices is saved, we remove all the information related to this triangle.Moving on, we search for a triangular face in the remaining set that shares the same two saved vertices and label it as 2. We determine the vertices of the two triangles where  min and  max are located in triangle 2 and compute their intersection with the tangent plane.
Two special cases are worth mentioning there.The first case: as shown in Figure 3  In the second case, when an edge is tangent to the tangent plane (as shown in Figure 4), there are an infinite number of intersections.However, this scenario is not considered.On the other hand, when a vertex belongs to the tangent plane, there is only one intersection.In this case, the position information of the intersection point and the normal vector information of the triangle surface are retained.This method is then extended successively to the number 3 triangular surface.The calculation continues until the set of all triangular surfaces in the tangent plane is empty.(4) The generation of spray gun spraying track The intersection points of all tangent planes and triangular surfaces have been calculated in step (c).These intersection points, along with their respective normal vectors, are stored in the C matrix.Moving forward, we will calculate the positions and attitudes information of the spray gun.The time expression of the spray gun positions and attitudes is obtained via interpolation using a quintic polynomial.
The matrix C contains the coordinates and normal vector of the intersection point between the tangent plane and the triangular surface.To ensure that the spray gun maintains a constant height from the complex surface during spraying, all intersection points in matrix C are adjusted by a height H (as is shown in Figure 5) along the direction of the normal vector.The updated position and normal vector are then stored in a new matrix D, completing the calculation of the spray gun's position.For the positions and attitudes of the spray gun, it is important to ensure that the spray gun is always parallel to the normal vector of the complex surface during the spraying process.The paint mist sprayed by the spray gun generally takes on an elliptical shape, with the long axis of the ellipse always being vertical to the tangent direction of the complex surface.Therefore, the calculation steps for determining the spray gun positions and attitudes are as follows: Assume that  1 ,  2 are two consecutive intersection coordinates in matrix D, the current path intersection is  1 , the next critical path intersection is  2 , and: (1) The inversed normal vector [−  1 − 1 − 1] is taken as the Z-axis direction vector of the spray gun.
( The spray gun's positions and attitudes at key intersections are calculated using the above method.The homogeneous transformation matrix of the spray gun is obtained by integrating its positions and attitudes.
In this paper, the attitude angle of the robot is defined as the rotation mode of the X-Y-Z coordinate system with a fixed angle.The obtained parameters of the homogeneous coordinate matrix are used in the calculation formula for the X-Y-Z rotation mode.This allows us to determine the relative rotation angle of the spray gun's positions and attitudes at the intersection point with respect to X, Y, and Z. Finally, the spray gun's positions and attitudes are interpolated, and a quintic polynomial expression of its pose with respect to time is synthesized.Figure 6 illustrates the flow chart of the STL slicing algorithm used to generate the spray trajectory of the spray gun.

Spraying Film Model and Parameter Setting
The film-forming process can be described as follows: (1) The spray gun ejects a mixture of paint and high-pressure air.(2) The mixture reaches the surface of a free surface after atomization diffusion.(3) The energy converts after the collision and adhesion between the paint mist and the free surface.(4) A paint film forms on the free surface.Two models are involved in describing this process, namely the spray flow field model and the collision adhesion model.The dynamic grid in Fluent and the movement positions and attitudes of the spray gun use UDF script as the driving source.In this way, the numerical simulation of film formation based on the STL algorithm is completed.

Spray Flow Field Model
Fundamental equations for two-phase flow.Considering that airflow and paint fluid flow both exist in the spraying process, this paper adopts the two-phase paint mist flow field model, which meets the continuum model of fluid mechanics.The momentum conservation equation and continuity equation are established for each phase in the flow field [25].
1.The momentum conservation equation is: where   is the volume fraction.  is the material density.  is the speed. is the common pressure.  is the viscous stress. is the acceleration due to gravity.  is the turbulent dispersion force. 1 is the force between the two phases. is the gas phase or the liquid phase.

Collision Adhesion Model
With the effects of the air gas pressure flow field, the atomized paint is sprayed onto the complex surface and forms film thickness after the collision and adhesion.The atomized paint continuously collides and adheres during the film-forming process.The mass and momentum of the liquid phase are removed from the two-phase flow in the spray flow field and added as source terms to the mass and momentum conservation equations of the liquid film.Thus, the film thickness is formed on the free surface [16].In this process, the mass and momentum conservation equations can be used to calculate the film thickness.
1.The mass conservation equation is: where  is the density.ℎ is film thickness. is the average velocity of film flow.  is the mass source.2. Momentum conservation equation is: where the left part of the equation represents the instantaneous term and the convection term, respectively.The right part shows the pressure of the gas phase, the normal component, the resultant force of the surface tension of the paint film, the tangential component, the viscous shear stress at the interface between the gas phase and the liquid phase, and the viscous stress of the paint film, respectively.

Meshing
This paper primarily investigates the dynamic spraying of arc surface (as shown in Figure 7) and free surface (as shown in Figure 8).The meshing of the arc surface and free surface model is carried out.In order to improve the quality of mesh and spraying, the mesh of the density spray gun, arc surface, and free surface is increased accordingly.The dynamic spray control domain for arc surfaces and free surfaces is divided into moving areas and stationary areas.The spray gun moves while the arc surface and the free surface remain stationary.The gun sprays coats along a specific trajectory and the spray gun is positioned vertically to the surface.Figure 9 shows the mesh division of the arc surface and the free surface model.

Setting Spraying Parameters
The study focuses on air-assisted spraying.Therefore, the definition of a spray flow field mainly involves two phases, namely, the gas phase and the liquid phase.The first one is compressed air; the second is two-component paint.
The main parameters are spraying environment parameters, spraying process parameters, and coating property parameters, and the main spray parameters are shown in Table 1.

Free surface
The spray gun positions and attitudes are mainly obtained using STL algorithm and input as the power source of the spray gun by writing the UDF script.The time step when the dynamic spraying of the spray gun starts to be calculated is set as ∆ = 0.001.
The arc surface and free surface models are divided into meshes and imported into Fluent to configure related models and parameters.The finite volume method is used to solve the dynamic spray paint film model.The second-order upwind scheme is used to calculate the film thickness of the model [26].

Calculation and Setting of Spray Gun Positions and Attitudes
The proposed STL slicing algorithm is utilized to address the positions and attitudes of the spray gun.The intersections of the key points of the arc/free surface with the tangent plane.The intersections are shifted by a certain spraying height along the normal vector of the surface.The key points of the spray trajectory of the spray gun on the arc or free surface are obtained.The spray gun's positions and attitudes are then calculated using the method proposed in this paper.Finally, the polynomial regression algorithm in MATLAB is used to interpolate and fit the position and attitude of the spray gun, and the discrete points of the position and attitude of the spray gun obtained using the slicing algorithm are fitted to a fifth-order polynomial with respect to time.The formula is imported into Fluent by creating a UDF script, which serves as the power source for the spray gun, controlling its predetermined position and orientation during spraying.By utilizing the STL slicing algorithm presented in this paper, we can obtain the spray trajectories of the arc or free surface.In order to reduce the simulation load, this paper proposes using the intersection of the tangent surface at Z = 0 and the surface as the trajectory for the spray.Figure 10 shows the spray pattern created by the arc surface spray gun.As shown in Figure 11, the spray gun's position during spraying is determined using polynomial fitting.Figure 11a shows the change curve when spraying on the arc surface.Figure 11b shows the change curve when spraying on the free surface.Formula (7) represents the trajectory of the spray gun's motion, which is modeled using a quintic polynomial based on the key nodes.Figure 12 shows the spray pattern of a free surface spray gun. Figure 13 shows the changes in positions and attitudes of the spray gun when spraying on a free surface.Figure 13a depicts the position change curve, while Figure 13b shows the attitude change curve.Formula (8) describes the trajectory of the spray gun, which is fitted using a quintic polynomial from the key nodes.The positions and attitudes of the spray gun with respect to time are determined on the arc and free surfaces.After calculating the first derivative of time, the user-defined function (UDF) script was written and imported into Fluent for compilation.Therefore, the spraying trajectory generated using the STL slicing algorithm was established as the input condition for the movement of the spray gun.

Simulation Results
In this paper, numerical simulations are conducted to validate the accuracy of the algorithm for the spraying and film-forming processes of arc/free surfaces.Figure 14

Analysis of Coating Thickness Distribution
Figures 14 and 16 illustrate the thickness distribution of the coating on the arc surface and the free surface, respectively.It can be seen from the figure that there are certain differences in the paint film thickness at different locations on the arc surface and the free surface.As shown in Figure 15, the coating thickness distribution on the arc surface shows a pattern of being thicker in the central area and thinner on the edges.The pattern exhibits symmetry along both the horizontal and vertical directions of the arc surface.The maximum coating thickness on the arc face wall is 67 µm.The coating thickness at both ends of the spray track is thinner.The uniformity of the coating thickness distribution is noticeably worse than that in the central area.The primary reason for this observation is likely the instability of the flow field at the beginning of spraying.Due to gravity and the significant curvature on both sides of the arc surface, the wet paint sprayed on the arc surface is subjected to some influential factors, such as flow and sliding.Figure 16 shows the coating thickness distribution of the free surface.The concave areas have the thickest coating, measuring 73µm.The uniformity of coating thickness distribution in the convex region is not as good as that in the relatively gentle region.Some of the thickest coatings in the concave area may be influenced by gravity.The wet paint flows and accumulates in the lower areas during the spraying process.

Spraying Experiment Platform and Equipment
In this paper, the truss-type painting robot is utilized as the spraying equipment.The robot has a truss-type crane structure that allows movement in the X, Y, and Z directions.Additionally, a Staubli TX60 robotic arm (Hangzhou, China) is mounted upside down at the end of the Z-axis.The structure allows the truss crane section to move the robotic arm quickly and significantly to a specified position.The robotic arm can complete the intricate painting of complex and narrow areas, as illustrated in Figure 18a.The spraying surface shown in Figure 18b

Spraying Experiment
The numerical simulation provides the wet film coating thickness, denoted as H1.This value is then converted to the dry film thickness, denoted as H2, based on the volume solid fraction of the sprayed paint.The dry films resulting from dynamic spraying experiments were compared with these converted values.
Spraying experiments are conducted for both the arc surface and the free surface in order to validate the simulation results.Let us take arc surface spraying as an example.Firstly, the planned spray trajectory pose is imported into the offline programming software, as shown in Figure 19.Next, the post-processed file is imported into the controller for execution.Finally, the motion parameters and spraying parameters of the spraying robot were set to be consistent with the simulation parameters.After spraying, the surface should be allowed to dry naturally until the paint is fully cured.The coating thickness was measured using a coating thickness meter, and the overall impact after spraying was analyzed.

Comparative Analysis of Experiment and Simulation
The dry surface to be sprayed was measured using a coating thickness gauge.The measurement process is as follows: (1) Use a marker to draw a line on the center of symmetry of the arc or free surface.(2) Sample 20 points evenly along the center line of symmetry.Mark each measurement point with a marker.(3) Utilize the coating thickness gauge to measure the thickness of the coating.Each point was measured five times.Consider the average value as the coating thickness at this point.
The simulation results for the surface and free surface were compared with the experimental results, as depicted in Figures 21 and 22.As can be seen from the figure, the arc surface at both ends of the film has the thinnest coating thickness.The most concave part of the complex free surface has the thickest coating.The simulated coating thickness closely matches the experimental thickness.Using calculation and measurement, the standard deviation from the theoretical value is 0.25, and the relative difference is 3%.The simulation results and experimental errors can meet the actual operating requirements.

Conclusions
This article proposes an STL slicing algorithm for generating spray gun spray trajectories on arcs and free-form surfaces.The generated trajectories are imported into the software for simulation, and the following conclusions are drawn: (1) By analyzing the simulation results of arc/free-form surfaces, we observed that the distribution of spray layers on arc/free-form surfaces has different rules.The maximum coating thickness on the curved surface is 67 µm, and the maximum coating thickness on the free surface is 73 µm.(2) The coating thickness distribution on the arc surface is thicker in the central area and thinner in the surrounding area and is symmetrical with respect to the transverse and longitudinal directions of the arc surface.
illustrates the schematic diagram of the intersection between the slice plane and the triangular plane.

Figure 2 .
Figure 2. Schematic diagram of the intersection of slice plane and triangular plane.A, B, C, D, E and F are the triangle vertex numbers; 1, 2, 3 and 4 are the triangle numbers.
, when the cutting side is parallel to one side of the triangle,   or   is the same vertex.The intersection solved by triangle No. 2 is the same as the intersection solved by triangle No. 1.It clearly does not meet the requirements.At this time, whether the intersection points with the plane of triangle No. 1 and 2 are the same point should be determined.If it is, find another   or   .Then, we find the intersection point of the edge CD of triangle No. 2 with the tangent plane.The obtained intersection point and the normal vector of the triangular surface are saved.

Figure 3 .
Figure 3. Schematic diagram of the case where the slice plane is parallel to one side of the triangle plane.A, B, C, D and E are the triangle vertex numbers; 1, 2 and 3 are the triangle numbers.

Figure 4 .
Figure 4. Schematic diagram of tangent between the slice plane and the triangular plane.A, B, C and D are the triangle vertex numbers; 1 and 2 are the triangle numbers.

Figure 5 .
Figure 5. Schematic diagram of spray gun coordinate system.The blue line represents the spraying point of the spray gun, the black line represents the intersection position and attitude calculated by the slicing algorithm, and H is the spraying height of the spray gun.

Figure 6 .
Figure 6.Flow chart of spray trajectory generated using slicing algorithm.

7 )Figure 10 .Figure 11 .
Figure 10.Arc surface spraying track.The red line represents the spray gun spraying point, and the blue object represents the arc surface.

8 )Figure 12 .Figure 13 .
Figure 12.Spray track of the free surface.The red line represents the spray gun spraying point, and the green object represents free surface.

Figure 14 .Figure 15 .Figure 16 .
Figure 14.Arc surface spray gun spraying track process: (a) one position of the spray gun during the spraying process; (b) another position of the spray gun during the spraying process.

Figure 17 .
Figure 17.Distribution cloud of coating thickness on a free surface.

Figure 19 .
Figure 19.Arc surface offline programming trajectory import.The red line is the trajectory of leaving and returning to the initial point.As shown in Figure20, the spraying experiment is obtained after spraying and allowing the sprayed surface to air dry naturally.

Figure 21 .
Figure 21.Simulation and experimental results of arc surface.

Figure 22 .
Figure 22.Simulation and experimental results of free surfaces.