## 2 Method
### Contour Offset  
After obtaining the contour, additional processing is required before generating the path to conform to the expectations of the boundary-shaping dimensions. Contour offsets are commonly found in planar surfaces and need to deal with the complexity of holes when used as filling paths [19]. Computational accuracy is lost and offset errors exist when the coordinates of the plane are applied directly to the surface through mapping transformations. To ensure that the curve representing the contour always fits the given surface when moving, a new algorithm for contour offset is proposed in this paper, but it is only applicable to surfaces that are fitted using triangle meshes. The constraints are obtained by using the intersection of the plane and the mesh as shown in Figure 6.  
Here, each point can obtain the tangent vector of the contour at its location. Since the contour is ordered, each point only needs to form two vectors with two neighboring points, and their average sum is the tangent vector for that point. Then, based on the coordinates and tangent vectors of the current point, a plane that intersects the surface can be constructed so that each point has one such line of intersection, and this line of intersection subsequently restricts its movement on the surface. When a tangent plane intersects a surface, it is essentially the intersection of the plane and the edges of the triangular facets. When the triangular facet is determined to transverse the plane based on the coordinates of the vertices, the problem is simplified to a directed line segment intersecting the plane. The method of finding the intersection of a plane with a line is shown in Figure 7.  
Considering that the point of intersection is on both the line and the plane, it is reasonable to assume that the point of reference of the origin on the line is the point of intersection if it is moved a distance along that line. Knowing the distance \(D\) from the plane to the origin \(o\) and its normal vector \(\overrightarrow{n_{p}}\), as well as the direction of the line \(\overrightarrow{n_{l}}\), the distance \(t\) can be found according to Equations (1) and (2). \[o^{\prime}=o+o\cdot\overrightarrow{n_{l}} \tag{1}\] \[t=\left|D-oo^{\prime\prime}\right|/\left(\overrightarrow{n_{l}} \cdot\overrightarrow{n_{p}}\right) \tag{2}\]  
Figure 6: Constraint construction. A curve is obtained through the tangent plane and the surface, which is used to constrain the movement of the point. Figure 7a shows the intersection of the plane and one edge of the triangular facets, assuming that the side view of the plane is in the direction of the \(Y\)-axis, which is then converted to the case of Figure 7b. The origin \(o\) is projected onto the direction vector \(\overrightarrow{n_{l}}\) of the line to obtain the point \(o^{\prime}\); then, the reference point \(o^{\prime}\) is projected onto the normal vector \(\overrightarrow{n_{p}}\) of the plane to obtain the point \(o^{\prime\prime}\). The dot product of \(\overrightarrow{n_{l}}\) and \(\overrightarrow{n_{p}}\) yields \(\cos\alpha\), while the difference between the distance of the point \(o^{\prime\prime}\) to the origin and \(D\) and t is proportional to \(\cos\alpha\). And so on, finding more intersections to form a curve. The line segments on the curve are ordered concerning the non-planar slicing, and the direction of the curve is arranged to be counterclockwise. Then, both contraction and expansion need to be discussed. The states at different positions and in different cases are shown in Figure 8.  
An auxiliary vector is obtained by cross-multiplying the tangent vector of the contour at the point and the normal vector of the triangular facets where the point is located. This vector is used as the new value of the point's normal vector, thus replacing the previous setting. The new normal vector of the point is used as the starting vector to determine whether the point needs to move forward or backward along the constraint curve.