使用坐标建立距离矩阵
嘿,我遇到了一个问题,我基本上得到了一张任意大小的网格纸,并且必须仅使用页面上每个网格点的坐标来开发距离矩阵。
我认为最好的方法是最短路径对的 Floyd-Warshall 或 Djikstra 算法,但不知道如何使其适应坐标距离,因为所有文档都使用预先确定的距离矩阵。所以任何帮助都会很大
hey, I have been given a problem, I basically have been given a piece of grid paper of arbitary size and have to develop a distance matrix using only the coordinates for each of the grid points on the page.
I'm thinking the best approach would be something like the Floyd-Warshall or Djikstra algorithms for shortest path pair, but don't know how to adapt it to coordinate distances, as all the documentation uses a pre-determined distance matrix. so any help would be grand
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
距离矩阵仅包含到所有其他点的距离。
基本上,您只需使用适当的度量来计算距离即可。如果您想要“正常”距离,则为 sqrt((x1-x2)^2+(y1-y2)^2),其中 (x/y) 是以毫米/英寸为单位的点的坐标。如果您希望纸上的距离紧随线条 |x1-x2|+|y1-y2|。
除非纸上谈兵,否则图算法将是一种矫枉过正的做法。
the distance matrix contains simply the distances to all other points.
Basically, you just have to calculate the distances using an appropriate metric. If you want the "normal" distance, it's sqrt((x1-x2)^2+(y1-y2)^2) where (x/y) are the coordinates of a point in mm / inches. If you want the distance on the paper just following the lines its |x1-x2|+|y1-y2|.
Graph algorithms would be a overkill unless you have walls on the paper.