samedi 24 janvier 2015

Closest Point to Moving Target


I have a target which is constantly moving, and only its current position is ever known. I have about one hundred objects surrounding it, also only who's current positions are ever known.


I am trying to find a more efficient way to find the closest object to my target at any given moment in time. I have looked at a bunch of algorithms, but none of them seem to fit this (nearest neighbor, closest pair of points, etc.).


My objects are unsorted. It does not need to be exact. The closest I have been able to think of is the brute force algorithm:



Objects objects = MyListOfUnsortedObjects();
Object closestObj = objects[0];
for each (Object obj in objects){
if(obj is closer than closestObj){
closestObj = obj;
}
}
return closestObj;


Obviously, this is terribly inefficient. Am I better off to sort it and then divide and conquer? Or am I way off base?


Any suggestions?





Aucun commentaire:

Enregistrer un commentaire