2

I have a (geographic) map built up of polygons depicting land and a boat trying to get from A to B without hitting any of the land. Preferably, it should follow the shortest available path.

I have an algorithm that works most of the time, but it is rather clumsy and inefficient. Any hints or references to algorithms that I could use are greatly appreciated.

Jaap Versteegh
  • 761
  • 7
  • 15
  • Perhaps bind a node grid to the map of passable and impassible nodes and use something like A*? – Ant P Jun 26 '12 at 22:53
  • Dijkstra was a genius, use his: http://en.wikipedia.org/wiki/Dijkstra%27s_algorithm – Alex W Jun 26 '12 at 22:54
  • I have thought about discretizing the space, but the trouble with that is that a passage between islands or the width of a piece of land may be as narrow as a 50m, while the whole map can be 10000km each side, which would require a very fine maze and make it a really big problem. – Jaap Versteegh Jun 26 '12 at 23:01
  • @slashV although you just need to store if it is land or not (boolean) => 50m resolution => 10000 * 20 * 10000 * 20 / 8.0 => only 160MB ;) ... but a polygon approach which saves only the islands is better and faster for lots of water – Karussell Aug 10 '12 at 11:01

1 Answers1

8

Create a graph:

  • Create one node for each vertex of each polygon, the start point and the end point.
  • Create an edge between two nodes if there is a straight line going from one to the other, not passing through any obstacle.

Use an A* algorithm (http://en.wikipedia.org/wiki/A_star) to find the shortest path in the resulting graph. Estimate the distance as the straight line distance.

You can use any sort of obstacles, as long as you are able to determine the set of 'interesting' points: they are the contact points of all tangents for each pair of obstacles (nearly all vertices of a convex polygon are 'interesting'. ) and of all lines that touch the same (non-convex) obstacle twice.

John Dvorak
  • 26,799
  • 13
  • 69
  • 83
  • Supposing you use A* over a graph whose nodes are the vertices of the set of polygons, what's the best way of determining when a polygon doesn't need to be passed, i.e. the destination is some arbitrary point in the ungraphed space between two polygons? Would you just place an additional vertex at the destination? – Ant P Jun 26 '12 at 23:26
  • Yeah, you'd add one vertex for your start and end positions (assuming they aren't part of an existing polygon). – Running Wild Jun 26 '12 at 23:57
  • @Jan Dvorak Thank you for your answer. I had thought of this idea for a bit before. A typical map easily contains 10k points and for maps with large 'open' areas you would get the same order of connectivities per point. I believe this would make make the problem intractable fairly quickly. In other words, I don't think O(n^2) operations are an option, but I'll have a look at it. I'll accept your answer for now. – Jaap Versteegh Jun 27 '12 at 00:52
  • @SlashV An option would be to do a "zoomed out" version which is much less accurate, save entry and exit points per these high level nodes, and inside each of these box-nodes run the algorithm at full scale. – jett Sep 14 '12 at 06:46