简体   繁体   English

指定为XY坐标的点之间的最短路径距离

[英]Shortest Path distance between points given as X-Y coordinates

I am currently working on a project that has a vector containing X and Y coordinates for approximately 800 points. 我目前正在从事一个项目,该项目的向量包含大约800点的X和Y坐标。 These points represent an electric network of lines. 这些点代表线的电网。 My goal is to compute the shortest distance Path between a Point A and Point B that can be or can not be located along the path given by the vectors containing the XY coordinates of the electric lines. 我的目标是计算沿着包含电线的XY坐标的向量所给出的路径可以定位或不能定位的点A和点B之间的最短距离路径。

I have read about the Dijkstra Algorithm but since i am not that much familiar with it, I am not sure if I should go in that direction. 我已经读过有关Dijkstra算法的信息,但是由于我对它不甚了解,因此我不确定是否应该朝这个方向发展。 I will be very thankful if I can get any feedback or comments from you that can direct me to solve this matter. 如果能收到您的任何反馈或意见以指导我解决此问题,我将非常感谢。

Any pathfinding algorithm depends on paths, points are just meaningless. 任何寻路算法都取决于路径,点毫无意义。 What you have now is a list of "waypoints". 您现在拥有的是“航路点”列表。 However you have not explained how those points connect. 但是,您还没有解释这些点如何连接。 For example if any and every point is connected to each other point the shortest distance would simply be the pythagoral distance between A & B. - I'm also unsure what you mean by XY coordinates of electric lines, such a "line" would always have a start & end position? 例如,如果任何一个点都彼此连接,则最短的距离就是A和B之间的方位角距离。-我也不确定电气XY坐标的含义,这样的“线”总是有开始和结束位置?

So the first step is to add to each point not only the x,y coordinates, but also a list of connectable points. 因此,第一步是不仅要向每个点添加x,y坐标,而且还要添加可连接点的列表。

Once you did this you can start using a pathfinding algorithm (In this case A* would seem better than Dijkstra's though). 完成此操作后,您就可以开始使用寻路算法了(在这种情况下,A *似乎比Dijkstra更好)。 It would simply be a standard implementation with each "cost" the actual distance between a point. 这将仅仅是一个标准实现,每个“花费”一个点之间的实际距离。 (And for A* the heuristic would be the pythagoral distance to the end point). (对于A *,启发式将是到终点的pythagoral距离)。

For a good tutorial about A* (and other algorithms) you should check Amit's pages 要获得有关A *(和其他算法)的良好教程,请查看Amit的页面

EDIT, in reply to the comments. 编辑,以回复评论。

It seems the first step is to convert a set of line segments to "points". 似乎第一步是将一组线段转换为“点”。 The way I would go through this is: 我要经历的方式是:

collection AllPoints {containing Location & LinksToOtherPoints}
for each Segment
    get start/end Point of Segment
    if Point.Location is not in allPoints
        add Point to AllPoints
    add the other Point of Segment to LinksToOtherPoints

You then have simply a list with all points & the connections between them. 然后,您只需要列出所有点及其之间的连接的列表。 As you have to constantly search the allPoints collection I suggest storing that in a binary tree structure (sets?). 由于您必须不断搜索allPoints集合,因此建议将其存储在二叉树结构(集合?)中。

For computing the shortest path Dijakstra would be fine. 为了计算最短路径,Dijakstra会很好。

You may get faster results from using A* , which uses a best guess of the distance in order to focus its search in the right direction, thereby getting there quicker. 使用A *可能会得到更快的结果,该方法会最佳估计距离,以便将搜索集中在正确的方向上,从而更快地到达目的地。

If you are repeatedly querying the same data set, then memoization is fine. 如果您反复查询相同的数据集,则可以使用备忘录

Those people who recommend a brute-force algorithm are fools - it's worth taking a little time to learn how to program an efficient solution. 那些推荐蛮力算法的人是傻瓜-值得花一点时间来学习如何编写有效的解决方案。 But you could calculate the shortest path between all points using the Floyd-Warshall algorithm . 但是您可以使用Floyd-Warshall算法计算所有点之间的最短路径。 Unfortunately, this won't tell you what the shortest path is just how long it is. 不幸的是,这不会告诉您最短的路径 多长时间

Just calculate the distance for all possible paths and pick the shortest one. 只需计算所有可能路径的距离并选择最短的路径即可。 800 paths is nothing for modern PC. 800条路径对于现代PC而言一无是处。 You will not even notice it. 您甚至不会注意到它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 找到(x,y)坐标之间的最大距离 - Finding maximum distance between (x,y) coordinates 光电鼠标和xy坐标 - Optical mouse and x-y coordinates 使用提示用户输入笛卡尔平面中某些点的 xy 坐标(浮点类型)的函数 - Use function that prompts he user to input x-y coordinates (float types) of some points in a Cartesian plane 尝试在 C++ 中的 (x,y) 坐标系中找到两点之间的最短路径。 得到 11db 错误 - try to find the shortest path between two points in a (x,y) coordinate system in C++. Got 11db erro 如何将 x 和 y 坐标的结果组织为 ASCII XY 图? - how to organize the result of x and y coordinates as an ASCII X-Y plot? 将鼠标悬停在图片框上时,如何显示带有xy坐标的十字光标? - How could I display a crosshair cursor with x-y coordinates when hovering over a picturebox? 给定两个点(x1,y1)(x2,y2),我该如何平均计算给定点之间的直线上的N个不同点 - Given two points (x1,y1) (x2,y2), how can I compute N different points evenly lying on the line between the given points 在OpenCV中获取具有X,Y和到对象的距离的3D坐标 - Get 3D coordinates in OpenCV having X,Y and distance to object 如何检查xy轴上的碰撞 - How to check collisions on x-y axis 两点之间网格中的最短路径。抓住了 - Shortest path in a grid between two points. With a catch
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM