views:

75

answers:

3

Hi, for a geo-based online game I'm looking for an algorithm which finds the shortest distance between a specified point and a known path connected by x/y-coordinates, so that I can kill all redundant points/nodes. A link or keyword for this algorithm would help me a lot! thanks for reading

For better understanding: alt text

A: 

I suggest the best link is probably:

http://www.google.com/search?q=point+line+distance

The best answer will depend on how you represent your data and whether you need planar distance or geographic distance.

Other useful starting points might include:

http://www.google.com/search?q=spatial+index

http://www.google.com/search?q=surface+render+optimization

http://www.google.com/search?q=collision+detection

http://www.google.com/search?q=delaunay+triangulation

bbadour
OK, I said distance between "point and path" not "point and line" because I don't think that I have to check line by line of the path by brute force, to find the shortest don't I?
Flexx
There are ways to limit the search space. I edited my answer with some additional links.
bbadour
A: 

This is a point-to-point path-finding algorithm that is commonly used in games:

A* search algorithm

You might need to apply it a number of times between your point and path, but it is generally very fast. The algorithm has some optimizations for map grids (where the distances between squares are integers). There's a description of this in: Real-Time Strategy Game Programming using MS DirectX 6.0 by Mickey Kawick.

Djikstra's algorithm is a good general purpose path-finding algorithm from a single source node to all other nodes in the graph. You can stop the algorithm when you've found what you need - which in your case would be when the algorithm had found the shortest path to every node on the path.

I don't know of a specific "shortest path from node to path" algorithm.

richj
So if I unterstand the A* algorithm right, it finds the shortest way to another node. I intend to find the shortest distance even to the line between two nodes. For better unterstanding I added an image. Please correct me if I understand wrong.
Flexx
Yes - A* finds the shortest way to another node. For geometric distance the answer by bbadour is correct.
richj
The specified problem seems to be a mix of network path finding and geometric distance. However "so that I can kill all redundant points/nodes" implies that this is only part of a wider path-finding problem - possibly an optimization to the wider problem?
richj
+1  A: 

Are you wanting to calculate this in order to say something like "if the point-to-path distance is zero, then remove the point"? If so, then there is probably an easier way to remove redundant nodes. Take the points three at a time (call them A, B, and C). Calculate the angle between A and B, as well as the angle between B and C. If the two angles are the same, then point B lies in the path between A and C and is redundant. You can use the 'atan2' function (or your language's equivalent) to do the angle calculations.

bta