1. A method for generating a trajectory based on an input trajectory formed by points representing spatial coordinates for a numerically controlled (NC) process, comprising: determining a plurality of sequences of the points, wherein each sequence is formed by removing a unique combination of points from the input trajectory; determining, for each sequence, local costs of each point in the input trajectory, wherein the local cost of a point for a sequence is based on a spatial arrangement of the point with respect to at least some of points in the sequence; determining, for each sequence, a sum of corresponding local costs of each point in the input trajectory; determining the trajectory based on an optimal sequence with an optimal value of the sum of the local costs, wherein the optimal value is a minimum or a maximum of the sums of the local costs; labeling points in a sequence as one or combination of preserved, corner, noise, or redundant points; and fitting splines into the points of the sequence using the labeling, and wherein steps of the method are performed by a processor.