Skip to content Skip to sidebar Skip to footer

Finding The Closest Points In An Array

I am trying to find not just the closest point, but the 3 closest points in an array of 5 object points. I have tried several experiments using just a distance(d) variable for each

Solution 1:

If I understand correctly, this is similar to the closest pair of points problem. One (intuitive, but perhaps inefficient) approach is to simply brute force the items in the collection. That is, for two points, you use two for loops. For three points, then, you could use three nested loops. Then, you'd find the maximum "closeness." I'm not sure how you want to define closeness, but I figure the sum of the distances from A to B, B to C, and C to A would work well. Testing every enumeration of the point groupings for minimum "distance" would result in the closest pairing.

So, I'm not sure where your other functions would come into play. The larger problem is finding how to determine "closest," so calling a function to do a subproblem that is the bigger problem doesn't check out.

If you somehow want the three closest groups of points, then you would need to keep track of each pairing's distance and determine how your want to keep them distinct from each other. I.e., do you want to allow the same point to be in another group of points?

Post a Comment for "Finding The Closest Points In An Array"