简体   繁体   English

在网格上查找外边缘

[英]Find Outer Edges On A Grid

I am working with an algorithm that has a grid of constructed dots, each with an X and Y coordinate.我正在使用一种算法,该算法具有构造点的网格,每个点都有一个 X 和 Y 坐标。 The grid is split into several procedural areas.网格被分成几个程序区域。 I am looking for a way to find the outer edges of each area (different areas are indicated by different colors) via the vertices present in these areas.我正在寻找一种方法来通过这些区域中存在的顶点找到每个区域的外边缘(不同的区域用不同的颜色表示)。 I have a 2D array of all the vertices in the grid, as well as 2D arrays for each individual area, containing all of the vertices in that area.我有网格中所有顶点的二维数组,以及每个单独区域的 2D arrays,包含该区域中的所有顶点。

此图像显示算法

I am now wondering how to create an algorithm that finds the outer edges of each area, while discounting the "inner" parts.我现在想知道如何创建一种算法来找到每个区域的外边缘,同时忽略“内部”部分。 I am currently using C# in Unity3d, but programming language isn't really important.我目前在 Unity3d 中使用 C#,但编程语言并不是很重要。 I'm looking for a general algorithm of how this would hypothetically be done.我正在寻找一种假设如何完成的通用算法。 I do not quite know where to start我不知道从哪里开始

You can identify an edge-dot like this:您可以像这样识别边缘点:

It is a dot that (any of):这是一个点(任何一个):

  • has a neighbor that is of different color than itself有一个与自己颜色不同的邻居
  • it is on the edge of the grid.它在网格的边缘。

Algorithm: Loop through all the dots and test each dots (up to) 4 neighbors to determine if either of the two above points applies.算法:遍历所有点并测试每个点(最多)4 个邻居以确定以上两点中的任何一个是否适用。

Complexity: O(n) (in the number of dots)复杂度:O(n)(点数)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM