我正在研究一种算法,用于将STL文件切片为每个切片的单独SVG文件。我是这样一个点,在这里,我有一个线段数组,将在每个切片中组成一个或多个多边形(如果STL模型在其中有一个洞,就会有几个多边形组成等高线),我需要一种方法来将这些片段排序为
假设各段在阵列中呈随机顺序和随机方向。每个多边形中的所有段都会排列起来,但我希望它们也是从头到尾排列的,所以其中一些段可能需要翻转它们的顶点。
顶点结构只是xyz坐标。我并不关心这些部分是否被安排为CW或CCW,只要它们是有序的。
发布于 2013-08-14 03:05:12
您还没有向我们展示任何代码,所以我将编写伪代码:
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 collectionhttps://stackoverflow.com/questions/18222066
复制相似问题