gpt4 book ai didi

c# - 从矩阵获取区域/区域边界

转载 作者:太空宇宙 更新时间:2023-11-03 14:09:47 25 4
gpt4 key购买 nike

对我来说,我有一个非常基本的需求:提取构成矩阵的区域的坐标。

我举个例子。这是一些矩阵:

    | A | B | D | E | F | G | H | I | J |
| 1 | 0 | 0 | 0 | 2 | 2 | 2 | 4 | 4 | 4 |
| 2 | 0 | 0 | 2 | 2 | 2 | 2 | 4 | 4 | 4 |
| 3 | 0 | 0 | 2 | 2 | 2 | 3 | 3 | 4 | 4 |
| 4 | 1 | 1 | 1 | 2 | 2 | 3 | 3 | 4 | 4 |
| 5 | 1 | 1 | 1 | 2 | 2 | 3 | 3 | 4 | 4 |
| 6 | 1 | 1 | 1 | 2 | 2 | 3 | 3 | 4 | 4 |
| 7 | 1 | 0 | 0 | 0 | 1 | 1 | 3 | 0 | 4 |
| 8 | 0 | 0 | 0 | 0 | 1 | 1 | 1 | 0 | 0 |
| 9 | 0 | 0 | 0 | 1 | 1 | 1 | 1 | 0 | 0 |
| 10| 0 | 0 | 0 | 1 | 1 | 1 | 1 | 0 | 0 |

我想得到一个数组,其中包含每个区域的边界和值(不需要特定的顺序)。

左上区域示例:

  • 值:0
  • 边界:{A1、D1、B2、B3、13}

您是否知道一些图书馆可以满足这种需求,还是我应该自己编写代码?

最佳答案

我会自己编写代码,不确定是否有库。

我会依次考虑每个区域的每个点。然后(我认为)这应该有效:

if (surrounding 8 squares has at least one with different region)
{
for each 3 squares, above, below, left and right
{
if (less than 3 are different, and the middle is different)
{
is a boundry
}
}

for each 3 squares, above, below
{
for each 3 squares, left, right
{
if(all 3 from outer loop and all 3 from inner loop are different)
{
is a boundry
}
}
}

not a boundry
}
else
{
not a boundry
}

将越界方 block 视为不同。

关于c# - 从矩阵获取区域/区域边界,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8214208/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com