Created
January 2, 2015 13:44
-
-
Save nyanloutre/2763d93c8786cb532f5d to your computer and use it in GitHub Desktop.
convexhullPolygon
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Polygon convexhullPolygon(Polygon inpoly) | |
{ | |
Polygon outpoly = createPolygon(); | |
Polygon outpolyref = createPolygon(); | |
int i,j; | |
printf("\ninpoly original :\n"); | |
for(j=0;j<inpoly.size;j++) | |
{ | |
printf("\n\nx %de point : %f", j+1, inpoly.head->value.x); | |
printf("\ny %de point : %f\n\n", j+1, inpoly.head->value.y); | |
inpoly.head=inpoly.head->next; | |
} | |
outpoly = addPoint(outpoly, inpoly.head->value); | |
outpolyref.head = outpoly.head; | |
outpoly.size++; | |
inpoly.head = inpoly.head->next; | |
outpoly = addPoint(outpoly, inpoly.head->value); | |
outpoly.size++; | |
for (i = 3; i < inpoly.size; i++) | |
{ | |
inpoly.head = inpoly.head->next; | |
printf("\nboucle numero : %d\n====================================\n\ninpoly :\n", i-2); | |
for(j=0;j<inpoly.size;j++) | |
{ | |
printf("\n\nx %de point : %f", j+1, inpoly.head->value.x); | |
printf("\ny %de point : %f\n\n", j+1, inpoly.head->value.y); | |
inpoly.head=inpoly.head->next; | |
} | |
/*Vectorial product of the first point, the sign should be positive to continue (it would mean that the polygon turn always in the same direction)*/ | |
printf("Produit vectoriel sur z = %f", (outpoly.head->next->value.x - outpoly.head->value.x) * (inpoly.head->value.y - outpoly.head->next->value.y) - (inpoly.head->value.x - outpoly.head->next->value.x) * (outpoly.head->next->value.y - outpoly.head->value.y)); | |
while (outpoly.size >= 2 && ((outpoly.head->next->value.x - outpoly.head->value.x) * (inpoly.head->value.y - outpoly.head->next->value.y) - (inpoly.head->value.x - outpoly.head->next->value.x) * (outpoly.head->next->value.y - outpoly.head->value.y) < 0)) | |
{ | |
outpoly.head = outpoly.head->prev; | |
outpoly = removePoint(outpoly,3); | |
outpolyref.size--; | |
printf("\noutpoly :\n"); | |
for(j=0;j<outpoly.size;j++) | |
{ | |
printf("\n\nx %de point : %f", j+1, outpoly.head->value.x); | |
printf("\ny %de point : %f\n\n", j+1, outpoly.head->value.y); | |
outpoly.head=outpoly.head->next; | |
} | |
printf("Produit vectoriel sur z = %f", (outpoly.head->next->value.x - outpoly.head->value.x) * (inpoly.head->value.y - outpoly.head->next->value.y) - (inpoly.head->value.x - outpoly.head->next->value.x) * (outpoly.head->next->value.y - outpoly.head->value.y)); | |
} | |
outpolyref = addPoint(outpolyref, inpoly.head->value); | |
outpoly.size++; | |
outpoly.head = outpoly.head->next; | |
printf("\noutpoly :\n"); | |
for(j=0;j<outpoly.size;j++) | |
{ | |
printf("\n\nx %de point : %f", j+1, outpoly.head->value.x); | |
printf("\ny %de point : %f\n\n", j+1, outpoly.head->value.y); | |
outpoly.head=outpoly.head->next; | |
} | |
} | |
return outpoly; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment