Algorithm to find neighbours of point by distance with no repeats

60 views Asked by At

I have an array of points formatted like this: [point(0,0), point(0,0), point(0,0)], where 0,0 is replaced with the location of the point. I would like to interconnect them all by distance, for example: connecting.png.
This would be done by looping over each point (loop 1), and then nesting another loop of all the points except for the current one (loop 2), then calculating the distance between the value from loop 1 and loop 2, then if it is less than the threshold, that is a neighbour and return in in an array.

The problem happens when I get doubled up values, for example it has found that point 1 is a neighbour of point 2, but also that point 2 is a neighbour of point 1, so when I connect them, they will be doubled up. I know of the nearest neighbour algorithm, but that only selects the closest, and won't it also just do the duplicate thing again??

0

There are 0 answers