c - algorithm for arranging coordinates of corner points of a hexahedron in order -



c - algorithm for arranging coordinates of corner points of a hexahedron in order -

i have set of randomly ordered 8 corner vortexes of hexahedron

(0.0, 0.0, 0.0) (0.0, 1.5, 0.0) (1.5, 1.5, 0.0) (1.5, 1.5, 1.5) (0.0, 1.5, 1.5) (1.5, 0.0, 1.5) (1.5, 0.0, 0.0) (0.0, 0.0, 1.5)

i need algorithm arrange these points in order. eg first want print 4 points of front end face , other 4 points of face(both in clockwise direction). above points uniformly spaced (like cube). need algorithm hexahedron.

the "algorithm" inquire simple sorting of vertices such ordered in way want. next function this:

void order_hexa(double points[8][3]) { double tmp; int i,j,k,l,m,n=8; k= n-1; // k holds position of lastly interchange. higher elements sorted. while (k > 0) { l= 0; (j=0; j < k; j++) { if ( /*z*/ points[j][2] > points[j+1][2] || ( /*x*/ points[j][2] == points[j+1][2] && points[j][0] > points[j+1][0]) || ( /*y*/ points[j][2] == points[j+1][2] && points[j][0] == points[j+1][0] && points[j][1] > points[j+1][1]) ) { (m=0; m<3; m++) { tmp = points[j] [m]; points[j] [m]= points[j+1][m]; points[j+1][m]= tmp; } l= j; } } k= l; } }

this simple bubble sort. though bubble sort slow (o(n^2)), efficient on little samples, such here 8 elements.

c algorithm

Comments

Popular posts from this blog

java - How to set log4j.defaultInitOverride property to false in jboss server 6 -

c - GStreamer 1.0 1.4.5 RTSP Example Server sends 503 Service unavailable -

Using ajax with sonata admin list view pagination -