我遇到了 3D 打印机软件的排序算法问题。我将给定 .stl 文件的切片的 xyz 数据作为具有三列和 n 行的向量,其中 n 是每个切片的点数。
所以向量的代码如下所示:
x=matrix[n][0];
y=matrix[n][1];
z=matrix[n][2];
所以矩阵是我的向量,包含网格中所有点的所有坐标。
当我打印出点的坐标时,我得到一个未排序的列表。所以下面的列表显示了立方体的第一层/切片的点,尺寸为 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
排序后的列表如下所示
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
唯一的想法是,我如何对点进行排序是从笛卡尔坐标系的第一象限开始,然后移动到以下象限。当我逐层计算时,可以忽略 z 坐标。但是为此,我不知道如何启动代码。有人对我有提示吗?
我想要实现的是按以下方式对点列表进行排序:
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