I have one million points that are distributed randomly across the plane (see diagram below).
I want to move the million points, so they form a 1000×1000 grid, while moving them as little as possible. What mathematical methods can I use to achieve this?
I want to get a grid with distances $h_x$ and $h_y$ as shown here:


Here is a greedy approach I just thought up. It may work reasonably. This feels to me like on of the NP problems that finding the optimum solution is hard but finding a pretty good one is easy.
Run the leftmost part of your grid through the $500^{th}$ leftmost point and the rightmost part of your grid through the $500^{th}$ rightmost point. Similarly for the top an bottom. That gives you (maybe a trial) $h_x,h_y$ and locates each grid point. Now start from the corners and assign each grid point the closest point not yet used. Work your way into the center. Having made the assignments you can perturb $h_x,h_y$ and the lower left corner of the grid slightly to see if you can make an improvement in the sum of the distances.
You could also try some annealing. Find two points that are assigned to nearby grid points. See if flipping their assignments improves things.