2

STL ファイルをスライスごとに個別の SVG ファイルにスライスするためのアルゴリズムに取り組んでいます。私は、各スライスで 1 つまたは複数のポリゴンを構成する線分の配列があるポイントです (STL モデルに穴がある場合、輪郭を構成する複数のポリゴンが存在します)。これらのセグメントをソートする方法

  1. 時計回りまたは反時計回りの順序 (必要に応じて向きを変える)
  2. 開始配列のポリゴンごとに個別の配列に。

セグメントは、配列内でランダムな順序およびランダムな向きであると想定されます。各ポリゴンのすべてのセグメントが整列しますが、それらも頭から尾まで整列させたいので、一部のセグメントでは頂点を反転する必要がある場合があります

頂点構造体は単なる xyz 座標です。セグメントが正しい順序であれば、時計回りまたは反時計回りのどちらに配置されていても、実際には気にしません。

4

1 に答える 1

3

コードを示していないので、疑似コードを書きます。

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
于 2013-08-14T03:05:12.513 に答える