SOLUTION: I'm sorry if this is not the right category but I'm not sure where to put this. I need to use this for an AI I'm currently programming and I can't find the right algoritm for this

Algebra ->  Points-lines-and-rays -> SOLUTION: I'm sorry if this is not the right category but I'm not sure where to put this. I need to use this for an AI I'm currently programming and I can't find the right algoritm for this      Log On


   



Question 880765: I'm sorry if this is not the right category but I'm not sure where to put this.
I need to use this for an AI I'm currently programming and I can't find the right algoritm for this.
The situation:
I got a collection of points in a coordinate system.
The size of the collection is unknown , but usually between 1 and 20.
The location of the points is completely random.
The desired outcome:
place a new point X so that as many points of the collection as possible are in a given radius of X
I'd like to give some images to explain it further but I don't know how on this website.
I hope I was clear and I'd be really happy if someone could help me.


Answer by rothauserc(4718) About Me  (Show Source):
You can put this solution on YOUR website!
If your coordinate system is the Cartesian coordinate system, then you can calculate the euclidean distance from X to each point(p), namely
d = square root ((x1 -px1)^2 + (y1 -py1)^2) where X = (x1, y1) and any point in the set of 20 elements is (px1, py1)
first sort the points on their x coordinates, then subtract the highest x value from the lowest x value and divide by 2, this gives you the x1 value, do the same for the y values so you get the y1 value
estimate the radius by adding x1 and y1 and divide by 2
then check that the distance is < or = the estimated radius for each point
accept if it is and reject if it is not