c++ - Sorting algorithm for mesh slicing -
i got problem sorting algorithms 3d printer software. xyz data of slices of given .stl file vector 3 columns , n rows, n number of points each slice.
so code vector looks this:
x=matrix[n][0]; y=matrix[n][1]; z=matrix[n][2];
so matrix vector containing coordinates points in mesh.
when print out coordinates of points unsorted list. following list shows points of first layer/slice of cube, dimensions of 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
my first approach sort points, result far away need have.
the sorted list looks 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 idea, how sort points start in first quadrant of cartesian coordinate system , move following quadrants. i'm computing layer layer z-coodrinate can ignored. this, don't know how start code. have hint me?
what want achieve sort list of points in 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 update, trivial. want sort points atan2(p1.y,p1.x) < atan2(p2,y, p2,x)
.
Comments
Post a Comment