在网格上找到外边缘
我正在使用具有构造点网格的算法,每个算法都带有x和y坐标。网格分为几个程序区域。我正在寻找一种通过这些区域中存在的顶点找到每个区域(不同区域用不同颜色表示的不同区域)的方法。我有一个网格中所有顶点的2D数组,以及每个区域的2D阵列,其中包含该区域中的所有顶点。
我现在想知道如何创建一种算法,以找到每个区域的外边缘,同时打折“内部”部分。我目前正在Unity3D中使用C#,但是编程语言并不重要。我正在寻找一种关于如何假设做到这一点的一般算法。我不太知道从哪里开始
I am working with an algorithm that has a grid of constructed dots, each with an X and Y coordinate. 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.
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. I'm looking for a general algorithm of how this would hypothetically be done. I do not quite know where to start
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以识别出这样的边缘点:
这是一个点,即(任何一个):
算法:
循环遍历所有点并测试每个点(最多)4个邻居,以确定上述两个点是否适用。
复杂性:o(n)(在点数中)
You can identify an edge-dot like this:
It is a dot that (any of):
Algorithm:
Loop through all the dots and test each dots (up to) 4 neighbors to determine if either of the two above points applies.
Complexity: O(n) (in the number of dots)
这是克里斯蒂安·斯洛普(Christian Sloper)的建议的稍有变化的版本:
对于每个点,在对角线上的4个最接近点上找到点(左上,右上,左上,左下和右下)。如果其中1或3个是不同的颜色,则点的坐标是形状的角。
Here is a lightly altered version of Christian Sloper' suggestion:
For each dot, find the dots on the 4 closest dots on the diagonals (top left, top right, bottom left, and bottom right). If 1 or 3 of them are a different color, the dot's coordinate is the corner of a shape.