This question is motivated by the Euclidean Traveling Salesman Problem, i.e. finding the shortest Hamiltonian path of a complete graph of N randomly placed vertices. To eliminate boundary effects I consider the problem on the unit square with periodic boundary conditions. The idea is to find a "direction" and connect points in an ordered manner along this direction to find a short path (Wheeler, J.A., On recognizing law without law, Am. J. Phys, 51(5), pp. 398, 1983). The question is: Given N points on the unit square, is there a neat way to find the least-square fit line y=(r*x+b) mod 1, where r is rational (if r is irrational then the question does not make much sense)? By "neat" I mean something like the regular least-square line fit solution (http://mathworld.wolfram.com/LeastSquaresFitting.html).