简体   繁体   English

网格切片的排序算法

[英]Sorting algorithm for mesh slicing

I got a problem with the sorting algorithms for a 3D printer software. 3D打印机软件的排序算法出现问题。 I get the xyz Data of the slices of a given .stl File as a vector with three columns and n rows, where n is the number of points for each slice. 我获得给定.stl文件的切片的xyz数据作为具有三列和n行的向量,其中n是每个切片的点数。

So the code for the vector looks like this: 因此,向量的代码如下所示:

        x=matrix[n][0];
        y=matrix[n][1];
        z=matrix[n][2];

So matrix is my vector containing all coordinates for all points in the mesh. 所以矩阵是我的向量,包含了网格中所有点的所有坐标。

When I print out the coordinates of the points I get an unsorted list. 当我打印出点的坐标时,会得到一个未排序的列表。 So the following list shows the points of the first layer/slice of a cube, with the dimensions of 10x10x10mm. 因此,以下列表显示了多维数据集的第一层/切片的点,尺寸为10x10x10mm。

X=-5.000000, Y=2.000000, Z=-2.000000
X=-5.000000, Y=-5.000000, Z=-2.000000
X=5.000000, Y=5.000000, Z=-2.000000
X=5.000000, Y=-2.000000, Z=-2.000000
X=5.000000, Y=-2.000000, Z=-2.000000
X=5.000000, Y=-5.000000, Z=-2.000000
X=5.000000, Y=5.000000, Z=-2.000000
X=2.000000, Y=5.000000, Z=-2.000000
X=2.000000, Y=5.000000, Z=-2.000000
X=-5.000000, Y=5.000000, Z=-2.000000
X=5.000000, Y=-5.000000, Z=-2.000000
X=-2.000000, Y=-5.000000, Z=-2.000000
X=-2.000000, Y=-5.000000, Z=-2.000000
X=-5.000000, Y=-5.000000, Z=-2.000000

So the result of this is shown in this figur. 因此,此结果在此图中显示。 未排序的点

My first approach was to sort the points, but the result is far away from what I need to have. 我的第一种方法是对点进行排序,但结果与我需要的东西相去甚远。 分类

The sorted list looks like this 排序后的列表如下所示

X=5.000000, Y=5.000000, Z=-2.000000 
X=5.000000, Y=5.000000, Z=-2.000000 
X=5.000000, Y=-2.000000, Z=-2.000000 
X=5.000000, Y=-2.000000, Z=-2.000000 
X=5.000000, Y=-5.000000, Z=-2.000000 
X=5.000000, Y=-5.000000, Z=-2.000000 
X=2.000000, Y=5.000000, Z=-2.000000 
X=2.000000, Y=5.000000, Z=-2.000000 
X=-2.000000, Y=-5.000000, Z=-2.000000 
X=-2.000000, Y=-5.000000, Z=-2.000000 
X=-5.000000, Y=5.000000, Z=-2.000000 
X=-5.000000, Y=2.000000, Z=-2.000000 
X=-5.000000, Y=-5.000000, Z=-2.000000 
X=-5.000000, Y=-5.000000, Z=-2.000000 

The only idea, how I could sort the points is to start in the first quadrant of a Cartesian coordinate system and then move to the following quadrants. 唯一的想法,如何对点进行排序是从笛卡尔坐标系的第一象限开始,然后移至随后的象限。 As I'm computing layer by layer the z-coodrinate can be ignored. 当我逐层计算时,z-coodrinate可以忽略。 But for this, I don't know how to start the code. 但是为此,我不知道如何启动代码。 Does someone have a hint for me? 有人对我有提示吗?

What I want to achieve is to sort the list of points in the following way: 我要实现的是按以下方式对点列表进行排序:

X=-5.000000, Y=5.000000, Z=-2.000000
X=-5.000000, Y=2.000000, Z=-2.000000
X=-5.000000, Y=-5.000000, Z=-2.000000
X=-5.000000, Y=-5.000000, Z=-2.000000
X=-2.000000, Y=-5.000000, Z=-2.000000
X=-2.000000, Y=-5.000000, Z=-2.000000
X=5.000000, Y=-5.000000, Z=-2.000000
X=5.000000, Y=-5.000000, Z=-2.000000
X=5.000000, Y=-2.000000, Z=-2.000000
X=5.000000, Y=-2.000000, Z=-2.000000
X=5.000000, Y=5.000000, Z=-2.000000
X=5.000000, Y=5.000000, Z=-2.000000
X=2.000000, Y=5.000000, Z=-2.000000
X=2.000000, Y=5.000000, Z=-2.000000

在此处输入图片说明

With the update, this is now fairly trivial. 通过更新,这现在变得微不足道了。 You want to sort the points by atan2(p1.y,p1.x) < atan2(p2,y, p2,x) . 您要按atan2(p1.y,p1.x) < atan2(p2,y, p2,x)排序点。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM