octrees icon indicating copy to clipboard operation
octrees copied to clipboard

Sort a set of 3D points

Open Rasoul77 opened this issue 2 years ago • 4 comments

Is that possible to add an example code to show how one can use this octree package in order to sort a set of 3D points based on, for example Ecuadorian distance metric?

Rasoul77 avatar Oct 31 '23 14:10 Rasoul77

I'm not sure I completely understand the question. Let me guess what you mean.

You've got a set of points x_1, ..., x_n in 3D, constrained to lie on a sphere. You also have another point y, and you want to sort the points x_1, ..., x_n based on how far they are, in great circle distance, from y.

But, on a sphere, while Euclidean distance is not the same as great circle distance, they're directly related: you can just sort them in order of how close they are in Euclidean distance from y and get the same answers.

jcranch avatar Oct 31 '23 14:10 jcranch

Thanks for the quick reply! :) Let me explain my problem: I have a set of 3D points, SET = {(x0, y0, z0), ..., (x_n, y_n, z_n)}, I want to sort them like this:

  1. Select a random point from SET, let's name it Query, and remove Query from SET,
  2. Create another empty set, let's name it SORTED,
  3. Add Query to SORTED, so SORTED = {Query},
  4. Find the closest point in SET to Query, if success, then let's name it CLOSEST, if not, go to 9
  5. Add CLOSEST to SORTED,
  6. Remove CLOSEST from SET,
  7. Query <- CLOSEST,
  8. Go to 4
  9. Done

Rasoul77 avatar Oct 31 '23 14:10 Rasoul77

It would be possible to add advice on doing that, but I haven't yet seen why that's a natural thing to do.

You should be able to implement the algorithm you describe (using the nearest_to_point method in Octree to find the nearest point).

jcranch avatar Oct 31 '23 14:10 jcranch

What you're trying to do is the so-called "nearest neighbour algorithm", right? The greedy approximation for the travelling salesman problem?

jcranch avatar Oct 31 '23 20:10 jcranch