#### Abstract

Nowadays, laser processing technology is being used more and more in various fields, and the requirements for laser control procedures are getting higher and higher. This paper aims to study the path generation problem of laser marking technology in order to improve the efficiency of laser marking as well as the protection of the marking material. Therefore, we creatively propose two-path generation methods, namely, sawtooth parallel and contour parallel, and design the boundary curve offset algorithm and domain partition intersection algorithm for the computer simulation of the two marking paths, respectively. Through the simulation, we discussed the efficiency and marking quality of the two path generation methods and gave the conclusion that the efficiency of the sawtooth parallel path generation method is greater than that of the contour parallel path generation method under specific parameters.

#### 1. Introduction

The laser [1] is an important invention of the 20th century and has been called “the sharpest knife,” “the most accurate ruler,” and “the most unusual light.” Lasers have been increasingly used in industrial processes for a variety of machining operations such as marking, welding, drilling, cutting, heat treating, and painting. Laser marking [2] is the marking of logos, characters, symbols, and images with a laser on the product surface. It is a widely used processing method with the advantages of high processing efficiency, noncontact operation, no consumables, and low impact on product surface deformation [3] and solid marking content. The hatch tool of a laser marking machine can be used for hatch-specified 2D composite profile [4], but the setting of different hatch parameters has a great impact on the processing effect of different materials. Zigzag parallel [5] hatching and profile parallel [6] hatching are the two basic ways of marking road dynamics generation. And the design of different process processing and hatching algorithms has substantial significance on whether the operation efficiency and accuracy of laser marking machine [7] can be improved.

Nowadays, in the field of laser marking, more research lies in the combination selection and optimization of process parameters [8]. Shivakoti [9] et al. investigated the selection of optimal laser beam micromarking process parameters using the fuzzy TOPSIS [10] method in the GaN laser beam [11] marking process and concluded that small pulse frequency [12], high current, and scanning speed lead to increased mark intensity. Some people have explored this area through Bessel curves [13]. And a connected Fermat spiral area filling algorithm (CFS) [14] has also been proposed, but its study has not been deeply applied to laser marking technology and cannot be applied for complex graphics [15]. Our research aims to fill this gap in the laser marking path generation algorithm.

To fill this gap, in order to fill this gap, we explore the laser marking path generation algorithm from the perspective of improving the efficiency of laser marking path generation, combining computer graphics [16] principles with the length of the laser marking path and the time of the generation algorithm as the main factors. Firstly, we propose two-path generation methods, namely direction-parallel hatching and contour-parallel hatching. Parallel directional shaded lines, also called “zigzag” shaded lines, have paths that move along line segments parallel to the initially selected reference direction. The two marking path forms are shown in Figure 1. Based on this strategy, connected paths are obtained by connecting these parallel line segments so that they either all cross from right to left (or left to right) or alternate between left to right and right to left. In contrast, contour-parallel shading uses offset line [17, 18] segments based on boundary curves as smooth shading paths similar to boundary curves. Thus, contour-parallel shadows can be generated in a spiral fashion along a curve at a constant distance from the curve boundary. Later, the domain partition intersection algorithm and boundary curve offset algorithm are proposed for both methods and verified the feasibility and generation efficiency of both algorithms by computer simulation [19].

#### 2. Method

In exploring the problem of laser marking path generation, we proposed the zigzag parallel and contour parallel [20] filling path approaches and used interpolation methods [21] to fit the original pattern at a high level to enhance the marking pattern.

Usually, the first function in an M-file is the main function, which can be followed by any number of subfunctions. The main function can be called by other functions outside that file, and the main function is called by the filename of the *M* file where the function is stored.

M files can include multiple functions, and functions other than the main function are called subfunctions. Subfunctions can only be called by the main function or by other subfunctions within that file. Each subfunction begins with a function definition statement and continues until the definition of the next function or the end of the file. The subfunctions appear in any order, but the main function must appear first.

##### 2.1. Original Graph Curve Fitting

###### 2.1.1. Definition of Curve Fitting

The spline curve [22] *S*(*x*) is a segmentally defined equation. Given (*n* + 1) data points and a total of *n* intervals, the cubic spline equation satisfies the following conditions:(A)In each segment interval [*xi*, *xi* + 1] (*i* = 0, 1, …, *n* − 1, *x* increasing), *S*_{(x)} = *S*_{i(x)} is a cubic polynomial(B)The following relationship is satisfied:(C)*S*(*x*), the derivative , and the second-order derivative are all continuous in the interval [*a*, *b*], that is, the *S*(*x*) curve is smooth. So *n* cubic polynomial segments can be written aswhere *i* = 0, 1, …, *n*−1, and *a*_{i}, *b*_{i}, *c*_{i}, *d*_{i} represent the 4*n* unknown coefficients.

###### 2.1.2. Request a Solution

Interpolation and continuity:where *i* = 0, 1, …, *n* − 1.

Differential continuity:where *i* = 0, 1, …, *n* − 2.

Differential equation of a spline curve:

Bring the following step size *h* into the conditions of the spline curve:

Thus, we can deduce

We assume that

Thus, we can deduce the following result:

It is equivalent to the following equation.

Thus, the following formula is derived as

We substitute *c*_{i}, *d*_{i} intowe can derive the formula:

From the range of values of *i*, there are (*n* − 1) equations but (*n* + 1) unknowns *m*. To solve the system of equations, two additional equations are required. So some restrictions need to be placed on the differentiation of the two endpoints *x*_{0} and *x*_{n}. Here, we use not-a-knot [23] to solve the problem.

Specify the cubic differential matching of the spline curve.

After that we can derive the following conclusions:

The new coefficient matrix of the system of equations can be written as

##### 2.2. Introduction to Matlab Functions

The polyshape function [24] creates a polygon defined by two-dimensional vertices and returns an object with attributes describing its vertices, solid regions, and holes.

The polybuffer function implements the creation of a buffer around a point, line, or polyshape object. Its boundary will be input to the polyshape object buffer polyin a distance *d*. For positive values of *d*, the solid area boundary polyin expands by unit *d* and the hole boundary shrinks by unit *d*. The negative values of *d* shrink the solid boundary and expand the hole boundary.

The Intersect function is the intersection of a polyshape object. It can return the intersection of a closed curve and a line, and determine which parts of the line are inside and outside the closed curve.

##### 2.3. Boundary Curve Offset Based on Contour Parallel Path

Decompose the original figure into *n* simple figures, denote the centroid [25] of each simple figure, GI represents the center point of each simple graph and the *S*_{i} represents the area of each simple figure, yielding the central point coordinates of the original graph as

Thus, the maximum distance from any point (*X*, *Y*) on the road strength to the center of the path is obtained as:

For the contour parallel line hatching problem, we use the buffer function polybuffer for computer simulation.

Returns a polyshape object with a boundary that creates a buffer at distance *d* based on the input polyshape object polyin. For positive values of *d*, the solid area boundary of polyin is expanded by *d* units and the hole boundary is shrunk by *d* units. Negative values of *d* shrink the solid boundary and expand the hole boundary.

##### 2.4. Domain-Distinct Intersection Algorithm for Self-Intersecting Graphs Based on Zigzag Parallel Paths

For the serrated parallel path, we propose a regionalized closed curve [26] and a straight-line intersection algorithm. Firstly the original graph is regionalized according to the concave and convex points. The original graphics and the zoning graphics are shown in Figures 2 and 3 respectively. Afterwards, using a straight line *y* = *a* from the top of the closed graph to the bottom in 1 mm steps in order to scan [27], using the intersect function to find the coordinates of the entry, and then according to the previous cycle can always find the coordinates of the intersection point of the line with the original graph each time *y* = *a*.

According to the above division, the region will be divided into many small blocks of all data points, each small block with an array to store the first (from left to right) of the intersection of the line, and then an array to store the second, because it is a sawtooth arrangement, so it must be the first from a small block to point to the second, and so on, the intersection of each small block will be the first from the small block of coordinates to point to the second coordinates.

The *X* and *Y* values of the coordinates of the intersection point, the next in each array position relationship will be the *X* and *Y* values of the coordinates of the intersection point of the next line and the intersection point of the line at the coordinates of the intersection point of that previous line and the graph. The scan intersection is shown in Figure 4.

#### 3. Results

We conducted two simulation experiments on the designed contour parallel path boundary offset algorithm using Matlab software. The first simulation experiment was set to the inner shrinkage boundary distance of 1 mm and the hatch line spacing of 1 mm, and the second simulation experiment was set to the inner shrinkage boundary [28] distance of 0.1 mm and the hatch line spacing of 0.1 mm. Under these two sets of parameters, the total length of the hatching lines of the serrated parallel and contour parallel hatching curves were calculated, and the number of horizontal lines of the serrated parallel hatching and the number of circles of the contour parallel hatching were also calculated. The average running time (in ms) was calculated based on multiple runs of the hatching program, and the running time ratio of the program runs under different conditions was also calculated. The simulation results for the two parameters are shown in Figures 4 and 5, respectively.

##### 3.1. Simulation of Boundary Curve Offset Algorithm Based on Contour Parallel Path

###### 3.1.1. Algorithm Analysis Results

We have performed an accurate analysis of the running time [29] of this algorithm and have derived the number of function calls and the time during the operation of the algorithm by running it several times. The results are shown in Tables 1 and 2.

###### 3.1.2. Analysis Results

According to the simulation experiment results, we counted the running time, the number of laps of the path, and the total length of the path for each simulation experiment, respectively. The results are shown in Table 3.

##### 3.2. Simulation Results of Domain Partitioning Algorithm Based on Sawtooth Parallel Paths without Self-Intersecting Graphs

###### 3.2.1. Simulation Results

We generate the marking path according to the area division as follows. Figures 6 to 11 show each of the five areas of the division. The final results are shown in Figures 12 and 13, respectively.

###### 3.2.2. Analysis of Domain Partitioning Intersection Algorithm Based on Sawtooth Parallel Paths

For this algorithm, we conducted two sets of simulation experiments with different parameters and performed statistical analysis on the number of calls and time of each function in the operation of the algorithm, and the following results are obtained in Tables 4 and 5, respectively.

###### 3.2.3. Zigzag Parallel Path Analysis

We statistically analyze the average running time, path length, and number of path entries of the zigzag parallel path algorithm, and the following results are obtained in Tables 6.

#### 4. Discussion and Conclusion

Through the simulation solution, we can know that the average operation time of the zigzag parallel pattern filling and contour parallel pattern filling algorithms is 1 mm and 0.1 mm. After the fitting algorithm in this paper, we can get a nearly parallel straight line, while the contour pattern can be filled in parallel. The K value of the fitting function of the algorithm is close to 10, that is, under the same magnification, the zigzag algorithm can approach the previous value in time.

The algorithm in this paper can establish the length of two paths, that is, the distance that the laser sweeps through the whole closed figure, and the two paths are not very different [30].

However, the results of the simulation marking pattern can be seen, the simulation pattern based on the marking algorithm of the contour parallel path is more accurate, and the simulation pattern obtained by the marking algorithm of the sawtooth parallel path algorithm is relatively rough. Of course, this is also related to the design of our algorithm, and we believe that the accuracy of the serrated parallel path marking will be improved after the algorithm is continuously iterated and optimized.

#### Data Availability

The datasets for this study can be found in the (official website of APMCM) (https://www.apmcm.org/detail/2403).

#### Conflicts of Interest

The authors declare that there are no conflicts of interest.

#### Authors’ Contributions

G. L. and Y. L. contributed to the conceptualization of the study; G. L., Y. L., and X. Y. contributed to the methodology; G. L. created the software; Y. L. and X. Y. validated the software; X. Y., C. J., and J. Y. contributed to formal analysis; G. L. contributed to the investigation; Y. L. helped to collect the resources; X. Y. contributed to data curation; G. L. prepared the draft for writing—original the study; G. L. and J. Y. contributed to writing—review and editing the study; Y. L. contributed to visualization; J. Y. contributed to supervision; Y. L. and C. J. contributed to project administration; Y. L contributed to funding acquisition. All authors have read and agreed to the published version of the manuscript.

#### Acknowledgments

The authors sincerely thank the editors and reviewers for their efforts. The authors sincerely thank Geng Xiaoyang for laying the foundation for our achievement. The authors are grateful to Yifan Liu for his help in making it possible for me to submit this paper.