## 2 Literature Review
### Non-Planar Path Planning for 3D Printing
The review of the related literature reveals that the work where an analytical representation is obtained from points of a curved surface, also leads to the loss of key features or resolution when fitting [36]. In this way, a double source of error exists when, for instance, vertices contained in the STL file are used for calculating an analytical approximation: the intrinsic error of tessellated CAD approximation (STL file) and the error when fitting to analytical representation. In addition, the printing trajectories are limited when these must follow the points contained in the G-code/M-code generated by CAD software, or by using only the edges or vertices found in the STL file. Motivated by these limitations found in the literature, this paper is focused on the projection of complex trajectories, such as those encountered in lattices or patterns, to a tessellated surface and the corresponding G-code generation to achieve a curved architecture structure manufactured, achieving the continuous deposition of material using non-planar printing trajectories. To highlight this work contribution, Table 1 shows the important aspects of different works reviewed. This works fills the gap that was identified by the achievement of conformal printing of any lattice or pattern on any non-planar complex surface, via its tessellation, avoiding the need for the previous parametrization of the target surface. A general block diagram of the algorithm is presented in Figure 2, where three parameters are received as input:  
1. The coordinates \((x,y,z)\) of sequential and ordered points of the trajectory (usually lying on two-dimensional but not mandatory) are generated by parametric equations, recursive functions, or infill patterns. 2. The STL file of the non-planar target surface. 3. The vector of projection (direction) of the trajectory. Before projection, the algorithm verifies whether the distance between each pair of consecutive points is correct for proper printing, avoiding collision with the surface when the extruder moves linearly from point to point, and if needed, the algorithm generates parametrical extra points. Then, the algorithm projects each point on the top surface and gives as output the following:  
1. The new position \((x,y,z)\) of every point of the path that was able to intersect the body in the given direction. The points' sequence is maintained as it was before the projection, and those points that did not cross the body because they never found a surface are discarded. 2. The normal vector for each projected point is calculated for the orientation of the extruder in the case of using a multi-axis system. 3. From the new positions \((x,y,z)\), the G-code is generated for direct 3D printing. The algorithm is detailed in the upcoming subsections (steps and definitions) and is summarized in Figure 3.  
Figure 3: Flow diagram of the algorithm presented here for conformal 3D printing. Figure 2: Block diagram of the algorithm presented in this work. Step 1. Reading inputs:  
The algorithm needs three inputs: \((1)\) a matrix containing ordered points of the trajectory, (2) an STL binary file of geometry on which the points will be mapped, and (3) a vector of projection. When reading the STL file, data are stored in a matrix _faces, vertices, normal_ representing the triangular facets described by the \((x,y,z)\) coordinates of the three vertices and a normal unit vector. The STL file has two formats, the (i) ASCII, which is human readable, but larger (in memory) than the (ii) binary format. The normal vector is calculated using the right-hand rule (see Definition A1 in Appendix A). Step 2. Generating extra points for smoothing the path:  
The algorithm projects the points of a trajectory printing on a non-planar surface, and from these points \((x,y,z)\), the corresponding G-code is generated, which make the extruder travel in a linear fashion from point \(P_{i}\) to \(P_{i+1}\).