algorithm - 如何找到 "Eastern"区域的大部分点位于环绕二维平面内

标签 algorithm matrix 2d

我试图找到一种方法来确定环绕二维平面上存在的连续区域的最远方(最东边、最西边等)。左下角的点是 [0,0],例如,右上角的点是 [244,244] 我在下面包含了我的数据示例。请注意,出现在 4 个角上的深灰色区域是同一区域。

enter image description here

通过检查给定区域内的每个方 block 并记录具有最高 X 的方 block ,我能够用我的数据解决这个问题。我也进行了相同的搜索,除了限于 [0,width * .5]。但是,此解决方案仅适用于我的区域主要围绕一个点而不是又长又薄的区域。

@maraca 在评论中概述了一种方法,我认为可以提炼为:

* find an edge square
* assign 0 to current square
* walk around the edges, adding 1 when travelling east, -1 when travelling west (or north/ south) 
* the square with the highest value is the furthest east, the square with the lowest value is the furthest west

最佳答案

@maraca 在评论中概述了一种方法,我认为可以提炼为:

* find an edge square
* assign 0 to current square
* walk around the edges, adding 1 when travelling east, -1 when travelling west (or north/ south) 
* the square with the highest value is the furthest east, the square with the lowest value is the furthest west

效果很好。谢谢!

关于algorithm - 如何找到 "Eastern"区域的大部分点位于环绕二维平面内,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48329918/

相关文章:

ios - 我怎样才能插入一个字符串的二维数组

directx - 在 DirectX 11 中渲染 Sprite 的最佳实践是什么?

java - 深度优先搜索 1 循环打印

python - python中for循环内的递归调用不会在预期的位置退出

algorithm - 最小化两段路由的最大长度

c++ - 将文本文件中的整数矩阵存储到 C++ 中的数组中

c - 点在 2D 轴对齐矩形内,无分支

c# - 数组中出现次数最多的数

c++ - (简单 C++)从文件中获取带有 vector 的矩阵

java - 如何对 nxn 矩阵(最多 n=2^i)测试 1000 组数据,每组数据 20 次?