## 2 Method
### Non-Planar Slicing  
Non-planar slicing is different from planar slicing in that the heights involved within the same layer of the former are variable, and the dimensionality of the operation cannot be reduced as in the latter. It can be seen that non-planar slices are more complex and need to involve more triangular facets to fit the surface. When forming cross sections, the parameters required for each layer are not just a height constant and a fixed \(Z\)-axis but a large number of mesh vertices and corresponding normal vectors. The variable-curvature base surface is offset as shown in Figure 3.  
The triangular mesh of a fitted surface consists of vertices with topological relationships. Therefore, the effect of offseting the surface can be achieved by moving the vertices. The direction of the vertex offset comes from the average sum of the normal vectors of the triangular faces in the neighborhood. Then, by inheriting the previous topology, this set of vertices forms a new triangular mesh for intersecting the part model. As shown in Figure 4, the essence of intersecting two meshes is the intersection computation between the triangular facets that belong to them. Triangular pairs can obtain a line segment in case of intersection; then, the line segments obtained between multiple triangular facets can form an open fold or a closed contour. Figure 3: Surface offset. A surface is offset by moving vertices on the triangle mesh. The direction of each vertex offset comes from nearby triangular facets. Figure 2: Flowchart of the methodology. On the left is a method flowchart, and on the right is an illustration of what is marked by the red boxes. Since the triangular facets provided by the STL are unordered, it is also necessary to order the line segments on the contour to form an oriented contour. Based on the feature that neighboring line segments share common endpoints, a dictionary storing endpoints and line segments is created. As shown in Figure 5, the endpoint of a line segment is used as a keyword and the corresponding value stores the two line segments that contain it. Finally, a search is performed in the dictionary. For example, after reading the point \(v0\), find its associated line segment \(e0\) and compare it with its endpoint. If it is the same as its starting point, then the next point is the end point of \(e0\); otherwise, the next point is the starting point. So, find the point \(v3\) as the next point and take out the line segment that was stored when it was used as a keyword. Since \(e0\) has already been processed, the edge \(e3\) is used, and so on, repeating the above steps until all the edges have been used, and at this point, all the points have been read in an orderly sequence and form an oriented contour. But just because there is a directional contour that does not mean that each layer is oriented in the same direction. The direction may be clockwise or counterclockwise. At the stage of intersection, the triangular facets of the model surface involved in each edge can be recorded. Each edge is shared by two triangular facets; then, their normal vectors are used as the normal vectors of the points. Thus, the result of the cross product of the tangent vector of the contour and the normal vector of the point is used to determine the direction of the contour. The normal vectors of the triangular facets that fit the surface of the model all face outward, and the normal vectors of the points at this stage also face outward. Then, the normal vectors of the points have the opposite result of the operation on the counterclockwise contour and the clockwise contour. For subsequent planning, the contours of each layer are standardized to be counterclockwise. Figure 4: Surface intersection. The intersection of the blue mesh and the orange mesh is the intersection of the triangular facets, and the red line segments form the complete intersection. Figure 5: Point ordering.