Consiglierei un approccio alternativo: l'albero che esplora rapidamente (RRT) . Una cosa interessante è che puoi farla girare negli angoli o esplodere in tutte le direzioni.
L'algoritmo è davvero di base:
// Returns a random tree containing the start and the goal.
// Grows the tree for a maximum number of iterations.
Tree RRT(Node start, Node goal, int maxIters)
{
// Initialize a tree with a root as the start node.
Tree t = new Tree();
t.Root = start;
bool reachedGoal = false;
int iter = 0;
// Keep growing the tree until it contains the goal and we've
// grown for the required number of iterations.
while (!reachedGoal || iter < maxIters)
{
// Get a random node somewhere near the goal
Node random = RandomSample(goal);
// Get the closest node in the tree to the sample.
Node closest = t.GetClosestNode(random);
// Create a new node between the closest node and the sample.
Node extension = ExtendToward(closest, random);
// If we managed to create a new node, add it to the tree.
if (extension)
{
closest.AddChild(extension);
// If we haven't yet reached the goal, and the new node
// is very near the goal, add the goal to the tree.
if(!reachedGoal && extension.IsNear(goal))
{
extension.AddChild(goal);
reachedGoal = true;
}
}
iter++;
}
return t;
}
Modificando le funzioni RandomSamplee ExtendToward, è possibile ottenere alberi molto diversi. Se RandomSamplecampiona uniformemente ovunque, l'albero crescerà uniformemente in tutte le direzioni. Se è di parte verso l'obiettivo, l'albero tenderà a crescere verso l'obiettivo. Se campiona sempre l'obiettivo, l'albero sarà una linea retta dall'inizio alla meta.
ExtendTowardpuò permetterti di fare cose interessanti anche sull'albero. Per prima cosa, se hai ostacoli (come i muri), puoi far sì che l'albero cresca attorno a loro semplicemente rifiutando le estensioni che si scontrano con i muri.
Questo è come appare quando non distorci il campionamento verso l'obiettivo:

(fonte: uiuc.edu )
Ed ecco come appare con i muri
Alcune fantastiche proprietà dell'RRT al termine:
- La RRT non si attraverserà mai da sola
- L'RRT coprirà infine l'intero spazio con rami sempre più piccoli
- Il percorso dall'inizio alla meta può essere completamente casuale e strano.