使用 C# 查找多边形的中轴

发布于 2024-07-26 02:09:00 字数 752 浏览 8 评论 0原文

我的任务是弄清楚如何找到多边形的中心线。 我的谷歌搜索让我相信我需要的是“中轴”。 像这样:

“替代文本”"
(来源:kiev.ua

根据我读过的、我需要的可以通过使用分段的 2D Voronoi 图构造算法来生成。

我在 codeplex (FortuneVoronoi) 上找到了 Voronoi 算法的 C# 版本,在将多边形应用到它之后,我最终得到了这个:

替代文本 http://www.carbonatlas.com/geonotes/gaia_voronoi.png

绿色是原始多边形。 橙色是 Voronoi 顶点,黑色线是 Voronoi 边。

我可以在这些顶点中看到我需要的东西的构成,但我不确定过滤掉所有我不需要的东西所需的下一步。

如果您能提供任何帮助,我将不胜感激。

I've been tasked to figure out how to find the centerline of a polygon. My google searches led me to believe that what I need is called the 'Medial Axis'. Like this:

alt text
(source: kiev.ua)

According to what I've read, what I need can be produced by using a 2D Voronoi diagram construction algorithm for segments.

I've found a C# version of the Voronoi algorithm on codeplex (FortuneVoronoi) and after applying my polygon to it, I end up with this:

alt text http://www.carbonatlas.com/geonotes/gaia_voronoi.png

The green is the original polygon. The orange are the Voronoi vertices and the black lines are the voronoi edges.

I can see the makings of what I need in those vertices, but I'm unsure of the next step required to filter out all the stuff I don't need.

I'd appreciate any help you can offer.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(3

三岁铭 2024-08-02 02:09:00

评论中建议了一种简单的解决方案:

  1. 构建多边形顶点的 Delaunay 三角剖分。
  2. 识别多边形内的 Voronoi 顶点(参见
    http://en.wikipedia.org/wiki/Point_in_polygon)
  3. 输出连接两个点的 Voronoi 边内部 Voronoi 顶点。

如果你有大量数据,交叉点的成本可能会相当高。

然后您可以执行类似的方法,例如 问题,以及这个解决方案也可能适合您。 我的做法是:

  1. 构建多边形顶点的 Delaunay 三角剖分。
  2. 插入未被 delaunay 边覆盖的每个多边形边的中点。 递归地执行此操作,直到所有多边形边都被 Delaunay 边覆盖。
  3. 标记与多边形边相对应的所有 Delaunay 边。
  4. 使用步骤 3.-5 提取中轴。 在此解决方案

PS。 请注意,这两种解决方案都给出了中轴的一些近似值,精确计算它的成本要高得多,但作为一个预告......您可以为黑色输入样本点获得如下结果:

中轴

One simple solution would be as suggested in the comments:

  1. Build the Delaunay triangulation of the polygon vertices.
  2. Identify the Voronoi vertices inside the polygon (see
    http://en.wikipedia.org/wiki/Point_in_polygon)
  3. Output the Voronoi edges connecting two interior Voronoi vertices.

If you have huge data the intersections might be quite costly.

Then you could do a similar approach like in the question, and this solution could work for you, as well. The way I would do it:

  1. Build the Delaunay triangulation of the polygon vertices.
  2. Insert the midpoint of every polygon edge that is not covered by a delaunay edge. Do this recursively until all polygon edges are covered by Delaunay edges.
  3. Mark all Delaunay edges which correspond to a polygon edge.
  4. Extract the medial axis using steps 3.-5. in this solution

PS. Note that both solutions give some approximation of the medial axis, computing it exactly is much more costly but as a teaser... you can get results like this for the black input sample points:

medial axis

德意的啸 2024-08-02 02:09:00

类似的构造是直骨架,可以通过将多边形收缩到自身并追踪来构造当顶点接近中心时。 这可能更容易构建,尽管它与中轴不是完全相同的曲线。

A similar construct is the Straight skeleton, which can be constructed by shrinking the polygon into itself and tracing the vertices as they approach the center. This may be a little easier to construct, though it's not quite the same curve as the medial axis.

清眉祭 2024-08-02 02:09:00

哇。 我将在这里冒险并建议算法可能对多边形的内部与外部感到困惑。 当您定义原始多边形的边和顶点时,您必须确保它们的定义方式始终可以使用“右手定则”之类的方法找到“内部”。 只要看看右下角的多边形,看起来多边形的边缘实际上与自身相交。 也许算法将该部分和其他部分视为“由内而外”。 左下角也一样。

这是我的直觉,算法似乎无法确定什么方向在内部,什么方向在外部。

我认为一个简单的方法是过滤掉多边形之外的所有 Voroni“节点”,但是,我认为这不会看起来。 仔细看看你的图,看起来每个节点都有 3 个边将其连接到其他节点。 也许您可以过滤掉任何 3 条边连接到多边形外部节点的节点。 那行得通吗?

Wow. I'm going to go out on a limb here and suggest that maybe the algorithm is confused about the inside vs. the outside of the polygon. When you define the edges and vertices of your original polygon, you have to make sure they're defined in such a way that "inside" is always found using something like the "right hand rule". Just looking at the polygon in the bottom right corner, it looks like the edge of your polygon actually crosses itself. Maybe the algorithm is seeing that section, and others, as "inside out". The same in the bottom left.

That's my gut feeling, that the algorithm doesn't seem to be able to determine what direction is inside and what is outside.

I think a naive approach would be to filter out all Voroni "nodes" that are outside the polygon, however, I don't think that will look. Taking a closer look at your diagram, it looks like each node has 3 edges that connect it to other nodes. Perhaps you can filter out nodes where any of the 3 edges are connected to nodes outside the polygon. Would that work?

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