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 

so result of shown in figur. unsorted points

my first approach sort points, result far away need have. sorted

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 

enter image description here

with update, trivial. want sort points atan2(p1.y,p1.x) < atan2(p2,y, p2,x).


Comments

Popular posts from this blog

javascript - Laravel datatable invalid JSON response -

java - Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; -

sql server 2008 - My Sql Code Get An Error Of Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the varchar value '8:45 AM' to data type int -