How do you implement a program to find the shortest path in a 2d plane?

假如想象 提交于 2019-12-06 00:52:01

Is it possible that you use polygonal (i.e. straight line segment) approximations for all shapes? This would simplify the implementation of the algorithm a lot.

Assuming that this is indeed possible: If you want to use A* then you'll need a graph representation of the possible paths that you can take. The nodes of this graph are the combination of:

  • all the vertices of all shapes[1], and
  • the start and end points
  • all intersection points between {the straight line segment between the start and end point} and all shapes.

The edges in this graph, then, are between each pair of nodes only if

  • there exists a straight line between their corresponding two vertices
  • that doesn't intersect any of the shapes[2].

The length of each edge in the graph is then simply the (euclidean) distance between the two vertices it represents, and the shortest path is always a subset of these edges (I think), which you can find by applying A* to this graph.

[1] - To reduce the number of vertices, you can make all concave shapes convex (unless this causes the start or end point to lie inside such a shape, then it should be kept concave).

[2] - You can use a variety of data structures to speed up these queries, such as kD or quad trees, or maybe use a sweep line algorithm (such as http://en.wikipedia.org/wiki/Bentley%E2%80%93Ottmann_algorithm) in combination with a doubly-connected edge list.

Well i am not pretty sure if this might help but anyways every irregular object can be split into a combination of regular objects like a circle just that the radius of the curve keeps changing.So you can consider it to be a combination of arcs corresponding to different radii.

For the second point if have the points (l,k). Consider two points located on the line(x1,y1),(x2,y2) which are equidistant from(l,k). So the perpendicular will be the combination of all points which are equidistant from (x1,y1)and (x2,y2).

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!