Associating nearby points with a path

懵懂的女人 提交于 2019-12-04 13:14:18

It seems to me, you have two sets of points, the lat/lon points, and the red points. One of the lat/lon points is your starting point. Now considering all the other points as a set, use an (approximate?) nearest neighbor algorithm to find the next point. Now repeat. The only trouble is, that nearest neighbor algorithms tend to be O(n), which makes what you want to do O(n^2).

Building on the other suggestions provided here, I think I have found a O(n) algorithm that works effectively.

The idea is to first pick the first red point as the starting point (or could choose the first blue point). Then compare the distance from this point to the next red point and the next blue point, pick the closer. Repeat until both lists are depleted. This seems to be quite effective on the Translink data set. I will give an update if I make tweaks to this idea.

Perhaps you could use a custom sweep line algorithm, this should reduce the complexity of finding the nearest line segment.

For each red point iterate through blue segments and find the best segment for it. What exactly "best" is depends on the task, but it looks like a good measure would be "how much longer path becomes". If A is a red point and BC is a segment, then the best segment will minimize this: f(A,BC)=(|BA|+|AC|-|BC|).

When the best segment is found, it should be replaced with BA and AC. In the same way other points should be processed.

Without optimizations this will give O(N^2).

If points are distributed more or less uniformly and segment length is significantly less than size of entire figure, some space partitioning may help.

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