将三角形带的顶点转换为多边形的算法

发布于 2024-09-15 19:00:58 字数 438 浏览 2 评论 0原文

我有一个数组,其顶点代表三角形带。 我需要将其转换为多边形。 有很多解决方案可以进行相反的操作,但我未能找到解决上述问题的方法。 或者它可能太容易了,我只是看不到它。 请帮忙。

OpenGL=兼容,请参阅 http://en.wikipedia.org/wiki/Triangle_strip

示例: 对于此条 http://en.wikipedia.org/wiki/File:Triangle_Strip_Small.png< /a> 我需要输出 ABDFEC 或 ACEFDB

I have an array with vertices representing a triangular strip.
I need to convert it into polygon.
There are many solution to do the reverse, but I failed to find one for the above problem.
Or it could be too easy and I just cannot see it.
Please help.

OpenGL=compatible, see
http://en.wikipedia.org/wiki/Triangle_strip

Example:
for this strip http://en.wikipedia.org/wiki/File:Triangle_Strip_Small.png
I need output A B D F E C or A C E F D B

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

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

发布评论

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

评论(3

酒几许 2024-09-22 19:00:59

如果您的形状具有特别简单的结构,可能有一个快捷方式,但一般来说,我认为您想要执行以下操作:

  • 从三角形列表中创建顶点和边的列表。这涉及到检测共享点(希望它们是完全匹配的,这样您就可以通过散列找到它们,而不需要某种模糊搜索)和共享线(这很简单 - 只是不要在同一对共享顶点之间绘制两条边) 。
  • 找到最左上角的点。
  • 找到尽可能位于左上角且逆时针方向的边。
  • 走到下一个顶点。
  • 找到下一条边,尽可能地在前一条边上加倍。
  • 继续前进,直到再次到达最左上角的点。

There may be a shortcut if your shape has a particularly simple structure, but in general I think you want to do the following

  • Create a list of vertices and edges from your list of triangles. This involves detecting shared points (hopefully they are exact matches so you can find them by hashing instead of needing some sort of fuzzy search) and shared lines (that's easy--just don't draw two edges between the same pair of shared vertices).
  • Find the upper-left-most point.
  • Find the edge that travels as upper-left-most as possible, and is in the counterclockwise direction.
  • Walk to the next vertex.
  • Find the next edge that doubles back on the previous one as much as possible.
  • Keep going until you hit the upper-left-most point again.
阳光①夏 2024-09-22 19:00:58

我相信以下方法应该有效:

遍历顶点列表。将第一个点添加到多边形中。将第二个点压入堆栈。将第三个点添加到多边形中。继续交替推入堆栈上的点并将它们添加到多边形中,直到到达列表的末尾。当到达列表末尾时,弹出堆栈中的点并将它们添加到多边形中。

I believe the following should work:

Walk through the list of vertices. Add the first point to your polygon. Push the second point on the stack. Add the third point to the polygon. Continue alternating between pushing points on the stack and adding them to the polygon until you reach the end of the list. When you get to the end of the list, pop the points of the stack and add them to the polygon.

倾`听者〃 2024-09-22 19:00:58

alt text

我假设你的三角形带总是以相同的方式连接(我相信对于 OpenGL 来说也是如此)。

  • “底部”顶点始终是两个
    分开:A、C、E……
  • “顶部”
    顶点始终相距两个:B、D、
    F,...

获取“底部”列表并附加“顶部”列表的相反内容。 (以 ACEFDB 为例)


或者,更直接地,使用从零开始的索引而不是字母:

// do "bottom"
for ( i = 0; i < N; i += 2 )
  addVertex( i )

// do "top"
largestOddNumberLessThanN = N % 2 == 0 ? N - 1 : N - 2;
for ( i = largestOddNumberLessThanN; i >= 0; i -= 2 )
  addVertex( i )

alt text

I'll assume your triangle strip is always connected the same way (which I believe is true for OpenGL).

  • The "bottom" vertices are always two
    apart: A, C, E, ...
  • The "top"
    vertices are always two apart: B, D,
    F, ...

Take the "bottom" list and append the reverse of the "top" list. (ACEFDB for the example)


Or, more directly, using a zero-based index instead of letters:

// do "bottom"
for ( i = 0; i < N; i += 2 )
  addVertex( i )

// do "top"
largestOddNumberLessThanN = N % 2 == 0 ? N - 1 : N - 2;
for ( i = largestOddNumberLessThanN; i >= 0; i -= 2 )
  addVertex( i )
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文