I am building a mySQL table listing points in n-dimensions, each dimension being indexed. Given any point in the n-dimensional system, I would like to be able to output all of the other points in order of their distance from the chosen point.
A simple solution would be to calculate distances from each point using the pythagorean theorem… sqrt(x^2+y^2)=z. I have been seeking a more efficient method. Only an approximate order is needed, so i’m very open minded.
Thanks.
-diddle
Along with what’s been given, you could also consider “binning” your points — i.e. (at least mentally) draw a grid over your “map”, and track points based on which square they fall into. Basically, you start with the points in the same square, then the ones in a “ring” surrounding the chosen point’s square, then the next ring outward, and so on. Depending on the size of grid you use, you can make this about as precise or approximate as you like. Of course, a 2D grid is for 2D points — if have more dimensions, you’ll have to increase the dimensionality of the grid to match.