Monday, 12 November 2012

Am I closer to that one, or that one?

In a map full of way-points, it's pretty easy to find which one you're closest to. All you need to do is look at each node one by one and keep track of which one's closest. With circles it's a bit less obvious; consider the following scenario:

Which circle is Bob closer to? As the crow flies he's closer to the centre of B, but it would make more sense to say A is the closer circle. The solution to this is rather trivial, we need to search for the smallest distance relative to each circles radius, i.e. Distance/Radius instead of just Distance.

Here's another issue that can pop up, consider the following:
Notice that Bob first goes back to the starting Circle despite having clear line of sight on the second? This can be fixed. When receiving the path simply compare the distance from Bob to the second Circle with the distance between the first and second. If Bob is closer then remove the first circle.
This also auto magically fixes another issue involving the target destination being between the same two circles as Bob.

No comments:

Post a Comment