Given a list of the 2D coordinates of all the Pokestops in my city, how do I find a circle with radius 'r' with the most Pokestops in it?

129 Views Asked by At

Given a list of coordinates and a circle of radius 'r', how would I go about finding the center of the circle C in which the most points lie?

My brute force solution: I have a list of coordinates (Pokestops) that I will iterate through. For each coordinate X in the list, there will be a circle C with center X. There will be ~10 other circles C1-10 centered around a point on the circumference of circle C, where each of those points are coordinates evenly separated throughout the circumference of C. I will check how many other Pokestops are within those 10 circles individually and track the circle with the highest total number of Pokestops.

However, I realize that the most optimal circle might not be one where a Pokestop lies on the circumference of the circle. The most optimal circle would actually likely be one in which no Pokestops touch the outer edge of the circle.

How do I account for this? My brute force solution will only track circles with Pokestops on the outer edge.

For what it's worth, I'm asking because I have a list of all Pokestops in my city and want to iterate through all of them to find the best/most optimal areas I can sit in that will have the highest number of stops.

1

There are 1 best solutions below

0
On

Given any pair of points less than $2r$ apart, there are two circles of radius $r$ that pass through those two points. For each such circle you can count how many points are within them.

Alternatively, and this personally seems a little overkill, you can do a thing where you repeatedly add new points and the circle around them, and use the circles to cut space into regions; the region that has the most points near it will win, and any point inside that region will give the largest number of points.