首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >C++排序线段数组为CW或CCW顺序

C++排序线段数组为CW或CCW顺序
EN

Stack Overflow用户
提问于 2013-08-14 02:01:48
回答 1查看 1.3K关注 0票数 2

我正在研究一种算法,用于将STL文件切片为每个切片的单独SVG文件。我是这样一个点,在这里,我有一个线段数组,将在每个切片中组成一个或多个多边形(如果STL模型在其中有一个洞,就会有几个多边形组成等高线),我需要一种方法来将这些片段排序为

  1. CW或“特定常规武器公约”命令(必要时调整方向)
  2. 为起始数组中的每个多边形设置单独的数组。

假设各段在阵列中呈随机顺序和随机方向。每个多边形中的所有段都会排列起来,但我希望它们也是从头到尾排列的,所以其中一些段可能需要翻转它们的顶点。

顶点结构只是xyz坐标。我并不关心这些部分是否被安排为CW或CCW,只要它们是有序的。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-08-14 03:05:12

您还没有向我们展示任何代码,所以我将编写伪代码:

代码语言:javascript
复制
while there are still loose segments
  take a loose segment and put it in a new polygon
  while the tail vertex of the polygon doesn't match its head vertex
    iterate over the remaining loose segments
      if the head of the segment matches the tail of the polygon
        append it to the polygon
        break out of the iteration
      reverse the segment
      if the head of the segment matches the tail of the polygon
        append it to the polygon
        break out of the iteration
    if control reaches here, the segments don't form a polygon -- ERROR!
  the polygon is complete, add it to the collection
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/18222066

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档