更改 FloodFill 算法以获取两个数据点的 Voronoi 区域?
我得到了一个有两个点的网格。我想计算每个点在另一个点之前可以到达的平方数。目前我实现了一个FloodFill-Algoritm,它可以计算一个点可以到达的方块数量。
我如何更改该算法以同时或至少一个接一个地对两个点进行“洪泛”?
I got a grid with two points. I want to calculate the amount squares each point can reach before the other. Currently I implement a FloodFill-Algoritm, which can calculate the amount of squares one point can reach.
How can I change that algorithm to do the "flooding" for both points simaltaneuosly or at least one after another?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
“每个点都可以先于另一个点到达”是什么意思?
在我看来你需要找个BF。使用 FIFO 队列,如下所示:
令 p1 和 p2 为两个点的位置。
令 f 为队列中的第一个元素,l 为最后一个元素。最初 f = 0,l = 1。设 Q 为队列。
Q 需要是网格的大小(行 x 列)。您可以使用两个矩阵:一个具有 p1 可到达的位置,另一个具有 p2 可到达的位置,或者您可以使用一个矩阵,并用正数标记 p1 到达的方格,用负数标记 p2 到达的方格。如果您对它们相遇的位置感兴趣,您只需检查您是否要从负值(poz 负值和 poz' 正值)中标记正值,或者反之亦然。这基本上会依次进行泛洪:从 p1 泛洪一个方格,然后从 p2 泛洪,然后从 p1 泛洪,然后从 p2 泛洪,依此类推。
What do you mean by "each point can reach before the other"?
It looks to me like you need a BF search. Use a FIFO queue like so:
Let p1 and p2 be the positions of the two points.
let f be the first element in the queue and l the last. Initially f = 0, l = 1. Let Q be the queue.
Q will need to be the size of your grid (rows x cols). You can use two matrices: one with the positions p1 can reach and the other with the positions p2 can reach, or you can use one matrix and mark the squares p1 reaches with positive numbers and the squares p2 reaches with negative numbers. If you are interested where they meet, you just need to check if you are about to mark a positive value from a negative value (poz negative and poz' positive) or the other way around. This will basically do your flooding in turns: flood one square from p1, then from p2, then from p1, then from p2 and so on.