My pathfinding code again!!!
Thanks for all the help so far.
Ok, after realising that my old code was un-object-orientated and messy, I deleted every last bit, and have done it all again. What I have done now in my program is:
A connectivity map is created, with each polygon ''knowing'' which polygons it borders. Now, I want to implement the Distance Transform Algorithm. Thing is, I''m not sure how I''m going to do it; I know what to do, but not how to implement it. I could use a recursive method, but they confuse the hell out of me, and it''d never work. I could use some strange while(true) looping until everything''s done, but that''d take ages. Any suggestions?
Thanks
Stu
And a woman needs a man... like a fish needs a bicycle...[U2 - Tryin' to throw your arms around the world]
The implementation is not necessarily obvious, but thankfully quite easy, so you shouldn''t have too much trouble with it. Here''s some psuedo-code for the Distance Transform algorithm and for the Path Planning algorithm that goes with it.
Notes:
The act of ''labelling'' a poly is assigning a cost to it
A node is just another name for a polygon
Using this algorithm, every polygon that can be reached from the goal node is labelled with a cost (number of polys that must be traversed to get to goal). If the root poly (the starting point) is not labelled then there is no path to the goal from the root poly.
The path to the goal is found in the following manner.
Good luck with it and let me know how it goes!
Cheers,
Timkin
Notes:
The act of ''labelling'' a poly is assigning a cost to it
A node is just another name for a polygon
Function: Distance TransformInputs: Connectivity map, goal_poly_IDOutputs: Connectivity map updated with costs{ Create empty queue Add goal poly to queue Mark the goal poly with a cost of zero while (queue not empty) { Remove head of queue and make it current node in search Copy all unlabelled neighbour polys of the current node onto the tail of the queue Mark all unlabelled neighbour polys of the current node with a cost of one greater than the current node } return}
Using this algorithm, every polygon that can be reached from the goal node is labelled with a cost (number of polys that must be traversed to get to goal). If the root poly (the starting point) is not labelled then there is no path to the goal from the root poly.
The path to the goal is found in the following manner.
Function: Path PlannerInputs: Connectivity map with costs, start_poly_IDOutputs: list of polygons{ Create empty list Set current node to start_poly Add current node to list while (current node is not goal node) { Set next_node to first neighbour of current node For each additional neighbour of current node { If neighbour cost less than next_node cost { set next_node to current neighbour } } Set current node to next_node Add current node to list } Return list}
Good luck with it and let me know how it goes!
Cheers,
Timkin
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement