遍历由相连三角形组成的多边形的边界点

发布于 2024-08-18 12:17:51 字数 870 浏览 2 评论 0原文

我有一个由连接的三角形组成的二维多边形网格,如下所示:

  • 顶点数组V = A,B,C,D,E,...
  • 索引数组,三角形顶点索引按逆时针顺序为 3 个一组:I = 0, 4, 3, ...
    (例如,V[0]、V[4]、V[3](即 AED)形成一个三角形)

http://img694.imageshack.us/img694/8968/meshg.png 网格示例

现在我想以逆时针顺序遍历边界点,起始顶点并不重要:
G、H、A、D、C、F

这样做的原因是我想计算动态 2D 阴影,如本文中所示: http://www.gamedev.net/reference/programming/features/2dsoftshadow/page3.asp

最好的方法是什么做这个吗?我考虑过计算凸包,但这似乎太昂贵了,因为它没有使用三角形顶点索引,必须有更好的方法。

有没有一种方法可以使其甚至适用于一个表示中的多个多边形,以便我获得每个连接的多边形的边界点列表列表?

谢谢,阿本西

I have a two dimensional polygon mesh made of connected triangles represented like this:

  • vertex array: V = A, B, C, D, E, ...
  • index array, triangle vertex indices in groups of 3 in counter-clockwise-order: I = 0, 4, 3,
    ...

    (so that e.g. V[0], V[4], V[3] which is A-E-D forms a triangle)

http://img694.imageshack.us/img694/8968/meshg.png
Example mesh

Now i want to traverse the boundary points in counter-clockwise-order, the starting vertex doesn't matter:
G, H, A, D, C, F

The reason for this is that i want to compute dynamic 2D shadows like in this article: http://www.gamedev.net/reference/programming/features/2dsoftshadow/page3.asp

Whats the best way to do this? I thought about computing a convex hull, but this seems too expensive because it's not using the triangle vertex indices, there has to be a better way.

Is there a way to make it work even for several polygons in one representation so that i get a list of boundary point lists for every connected polygon?

Thanks, abenthy

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

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

发布评论

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

评论(1

你没皮卡萌 2024-08-25 12:17:51

这是一种方法:

  1. 找到边界边,这是通过遍历三角形的所有边并删除出现两次的所有边来完成的(因为除了边界边之外的所有边都由两个三角形共享)(还记得 (A, B)(B, A)) 是同一条边。
  2. 您现在有了边界边的列表。从其中之一开始,依次循环其余边,直到找到一条连接的边,追加该边并将其从列表中删除。重复直到边界闭合。

由于三角形是逆时针方向,计算出的边界也将是逆时针方向。这种方法很好,因为它不需要顶点的实际位置,它只使用索引指定的拓扑。

Here's one way:

  1. Find the boundary edges, this is done by traversing all the edges of the triangles and removing all edges which occur twice (because all edges except the boundary edges are shared by two triangles) (Also remember (A, B) is the same edge as (B, A)).
  2. You now have a list of the boundary edges. Start with one of them and successively loop through the rest of the edges until you find one which is connected, append this edge and remove it from the list. Repeat until the boundary is closed.

Since the triangles are counter clockwise the computed boundary will also be counter clockwise. This method is good because it doesn't need the actual positions of the vertices, it only uses the topology specified by the indices.

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