So, I have a point in an unknown location, which I need to programmaticaly find. The only way we can try to find it’s location is is by calling a special isThePointWithin500MetersOfLocation(x, y)
function, which will return true if the point is within 500 meters of the passed location. I need to find out where the point is, or at least as close to it as possible. What algorithms could be used for this?
The isThePointWithin500MetersOfLocation
function takes ~30 seconds to execute, so the less calls to it there are – the better.
2
Answers
Here is testing for a point within a radius of another point.
Let’s skip over how you’re going to find the first result for
isThePointWithin500MetersOfLocation
, because this sounds a little too much of a toy problem to fully solve, but once you have your first, start binary searching. Or since we’re dealing with circles, and initial trinary searching: any circle of radius r can be fully covered by three circles with the same radius, with their centers on the original circle, and their centers each 120 degrees apart.So let’s do that:
This is, of course, only the first iteration: once we have a two-circle overlap, we now get to figure out where to place two new circles that we can use to bisect the area of overlap. The trigonometry required to find the two centers of those circles, I will leave up to you.
Evaluating each of these two circles will either result in "point is in 1 of them", which will yield a "triangle-ish" shape, or "point is in both of them", in which case we have the exact same situation we were just in, just with a much smaller shape.
We can trisect and bisect those shapes, respectively, and thus we can get closer and closer and closer to the "true" location of our point. The implementation of which is an exercise for the
readerposter =)