The advancement of 3D printing technology has enabled the fabrication of intricate structures, yet the complexity of the print head’s motion path significantly hampers production efficiency. Addressing the challenges posed by the dataset of section points in 3D-printed workpieces, this study introduces an innovative ant colony optimization algorithm tailored to enhance the print head’s trajectory. By framing the optimization of the motion path as a Traveling Salesman Problem (TSP), the research employs a custom-designed K-means clustering algorithm to categorize the dataset into distinct clusters. This clustering algorithm partitions each printing point into different subsets based on density, optimizes these subsets through improved K-means clustering computations, and then aggregates the results to classify the entire dataset. Subsequently, the ant colony algorithm arranges the printing sequence of these clusters based on the cluster centers, followed by computing the shortest path within each cluster. To form a cohesive motion trajectory, the nearest nodes between adjacent clusters are linked, culminating in a globally optimal solution. Comparative experiments repeatedly demonstrate significant enhancements in the print head’s motion path, leading to marked improvements in printing efficiency.