在网格上找到外边缘

发布于 2025-02-03 14:18:52 字数 411 浏览 3 评论 0原文

我正在使用具有构造点网格的算法,每个算法都带有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.

This image displays the algorithm

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

九局 2025-02-10 14:18:52

您可以识别出这样的边缘点:

这是一个点,即(任何一个):

  • 具有与自身不同的邻居
  • 在网格的边缘。

算法:
循环遍历所有点并测试每个点(最多)4个邻居,以确定上述两个点是否适用。

复杂性:o(n)(在点数中)

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.

Complexity: O(n) (in the number of dots)

物价感观 2025-02-10 14:18:52

这是克里斯蒂安·斯洛普(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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文