75 printf(
"\n%d vertices and %d facets with normals:\n",
76 qh num_vertices,
qh num_facets);
78 for (k=0; k <
qh hull_dim; k++)
79 printf(
"%6.2g ", facet->
normal[k]);
92 for (j=0; j<numpoints; j++) {
93 point= points + j*dim;
122 for (j= 0; j < numnew ; j++) {
123 point= points + (numpoints+j)*dim;
124 if (points ==
qh first_point)
125 qh num_points= numpoints+j+1;
132 point[k]= (j & 1) ? 2.0 : -2.0;
141 printf(
"%d vertices and %d facets\n",
142 qh num_vertices,
qh num_facets);
147 else if (
qh KEEPnearinside)
159 seed= (int)time(NULL);
160 printf(
"seed: %d\n", seed);
162 for (j=0; j<numpoints; j++) {
163 point= points + j*dim;
164 for (k= 0; k < dim-1; k++) {
189 for (j= 0; j < numnew ; j++) {
190 point= points + (numpoints+j)*dim;
191 if (points ==
qh first_point)
192 qh num_points= numpoints+j+1;
197 for (k= 0; k < dim-1; k++) {
208 printf(
"%d points, %d extra points, %d vertices, and %d facets in total\n",
210 qh num_vertices,
qh num_facets);
216 else if (
qh KEEPnearinside)
237 for (k= 0; k < dim-1; k++)
242 fprintf(stderr,
"findDelaunay: not implemented for triangulated, non-simplicial Delaunay regions (tricoplanar facet, f%d).\n",
247 for (k=0; k < dim-1; k++)
248 printf(
"%5.2f ", vertex->
point[k]);
263 for (j=0; j<numpoints; j++) {
264 point= points + j*(dim+1);
298 coordT *point, normal[100], offset, *next;
303 for (j= 0; j < numnew ; j++) {
307 normal[k]= sqrt((
coordT)dim);
309 normal[k]= -normal[k];
313 point= points + (numpoints+j)* (dim+1);
321 printf(
"%d points, %d extra points, %d vertices, and %d facets in total\n",
323 qh num_vertices,
qh num_facets);
328 else if (
qh KEEPnearinside)
333 #define SIZEcube (1<<DIM) 334 #define SIZEdiamond (2*DIM) 335 #define TOTpoints (SIZEcube + SIZEdiamond) 346 int main(
int argc,
char *argv[]) {
348 int curlong, totlong, exitcode;
353 printf(
"This is the output from user_eg2.c\n\n\ 354 It shows how qhull() may be called from an application in the same way as\n\ 355 qconvex. It is not part of qhull itself. If it appears accidently,\n\ 356 please remove user_eg2.c from your project.\n\n");
360 printf(
"QH6237: Qhull link error. The global variable qh_qh was not initialized\n\ 361 to NULL by global.c. Please compile user_eg2.c with -Dqh_QHpointer_dllimport\n\ 362 as well as -Dqh_QHpointer, or use libqhullstatic, or use a different tool chain.\n\n");
372 qh_init_A(stdin, stdout, stderr, 0, NULL);
373 exitcode= setjmp(
qh errexit);
377 strcat(
qh rbox_command,
"user_eg cube");
378 sprintf(options,
"qhull s Tcv Q11 %s ", argc >= 2 ? argv[1] :
"");
380 printf(
"\ncompute triangulated convex hull of cube after rotating input\n");
387 if (
qh VERIFYoutput && !
qh STOPpoint && !
qh STOPcone)
389 printf(
"\nadd points in a diamond\n");
394 if (
qh VERIFYoutput && !
qh STOPpoint && !
qh STOPcone)
400 if (curlong || totlong)
401 fprintf(stderr,
"qhull warning (user_eg, run 1): did not free %d bytes of long memory (%d pieces)\n",
407 qh_init_A(stdin, stdout, stderr, 0, NULL);
408 exitcode= setjmp(
qh errexit);
412 strcat(
qh rbox_command,
"user_eg Delaunay");
413 sprintf(options,
"qhull s d Tcv %s", argc >= 3 ? argv[2] :
"");
415 printf(
"\ncompute %d-d Delaunay triangulation\n",
DIM-1);
430 if (
qh VERIFYoutput && !
qh STOPpoint && !
qh STOPcone)
432 printf(
"\nadd points to triangulation\n");
436 if (
qh VERIFYoutput && !
qh STOPpoint && !
qh STOPcone)
438 printf(
"\nfind Delaunay triangle closest to [0.5, 0.5, ...]\n");
444 if (curlong || totlong)
445 fprintf(stderr,
"qhull warning (user_eg, run 2): did not free %d bytes of long memory (%d pieces)\n",
451 qh_init_A(stdin, stdout, stderr, 0, NULL);
452 exitcode= setjmp(
qh errexit);
457 strcat(
qh rbox_command,
"user_eg halfspaces");
458 sprintf(options,
"qhull H0 s Tcv %s", argc >= 4 ? argv[3] :
"");
460 printf(
"\ncompute halfspace intersection about the origin for a diamond\n");
470 if (
qh VERIFYoutput && !
qh STOPpoint && !
qh STOPcone)
472 printf(
"\nadd halfspaces for cube to intersection\n");
476 if (
qh VERIFYoutput && !
qh STOPpoint && !
qh STOPcone)
483 if (curlong || totlong)
484 fprintf(stderr,
"qhull warning (user_eg, run 3): did not free %d bytes of long memory (%d pieces)\n",
500 if (
qh ERREXITcalled) {
501 fprintf(
qh ferr,
"qhull error while processing previous error. Exit program\n");
505 if (!
qh QHULLfinished)
506 qh hulltime= (unsigned)clock() -
qh hulltime;
507 fprintf(
qh ferr,
"\nWhile executing: %s | %s\n",
qh rbox_command,
qh qhull_command);
508 fprintf(
qh ferr,
"Options selected:\n%s\n",
qh qhull_options);
509 if (
qh furthest_id >= 0) {
510 fprintf(
qh ferr,
"\nLast point added to hull was p%d",
qh furthest_id);
513 if (
qh QHULLfinished)
514 fprintf(
qh ferr,
"\nQhull has finished constructing the hull.");
515 else if (
qh POSTmerging)
516 fprintf(
qh ferr,
"\nQhull has started post-merging");
517 fprintf(
qh ferr,
"\n\n");
520 fprintf(
qh ferr,
"qhull error while ending program. Exit program\n");
526 longjmp(
qh errexit, exitcode);
536 fprintf(
qh ferr,
"%s facets f%d f%d ridge r%d vertex v%d\n",
554 fprintf(
qh ferr,
"facet f%d\n", facet->
id);
565 if (
qh MERGEexact ||
qh PREmerge ||
qh JOGGLEmax <
REALmax/2)
567 A Qhull error has occurred. Qhull should have corrected the above\n\ 568 precision error. Please send the input and all of the output to\n\ 569 qhull_bug@qhull.org\n");
572 Precision problems were detected during construction of the convex hull.\n\ 573 This occurs because convex hull algorithms assume that calculations are\n\ 574 exact, but floating-point arithmetic has roundoff errors.\n\ 576 To correct for precision problems, do not use 'Q0'. By default, Qhull\n\ 577 selects 'C-0' or 'Qx' and merges non-convex facets. With option 'QJ',\n\ 578 Qhull joggles the input to prevent precision problems. See \"Imprecision\n\ 579 in Qhull\" (qh-impre.htm).\n\ 581 If you use 'Q0', the output may include\n\ 582 coplanar ridges, concave ridges, and flipped facets. In 4-d and higher,\n\ 583 Qhull may produce a ridge with four neighbors or two facets with the same \n\ 584 vertices. Qhull reports these events when they occur. It stops when a\n\ 585 concave ridge, flipped facet, or duplicate facet occurs.\n");
589 Qhull is currently using single precision arithmetic. The following\n\ 590 will probably remove the precision problems:\n\ 591 - recompile qhull for realT precision(#define REALfloat 0 in user.h).\n");
593 if (
qh DELAUNAY && !
qh SCALElast &&
qh MAXabs_coord > 1e4)
596 When computing the Delaunay triangulation of coordinates > 1.0,\n\ 597 - use 'Qbb' to scale the last coordinate to [0,m] (max previous coordinate)\n");
598 if (
qh DELAUNAY && !
qh ATinfinity)
600 When computing the Delaunay triangulation:\n\ 601 - use 'Qz' to add a point at-infinity. This reduces precision problems.\n");
605 If you need triangular output:\n\ 606 - use option 'Qt' to triangulate the output\n\ 607 - use option 'QJ' to joggle the input points and remove precision errors\n\ 608 - use option 'Ft'. It triangulates non-simplicial facets with added points.\n\ 610 If you must use 'Q0',\n\ 611 try one or more of the following options. They can not guarantee an output.\n\ 612 - use 'QbB' to scale the input to a cube.\n\ 613 - use 'Po' to produce output and prevent partitioning for flipped facets\n\ 614 - use 'V0' to set min. distance to visible facet as 0 instead of roundoff\n\ 615 - use 'En' to specify a maximum roundoff error less than %2.2g.\n\ 616 - options 'Qf', 'Qbb', and 'QR0' may also help\n",
620 To guarantee simplicial output:\n\ 621 - use option 'Qt' to triangulate the output\n\ 622 - use option 'QJ' to joggle the input points and remove precision errors\n\ 623 - use option 'Ft' to triangulate the output by adding points\n\ 624 - use exact arithmetic (see \"Imprecision in Qhull\", qh-impre.htm)\n\ 639 qh_fprintf(fp, 9375,
"qhull precision warning: \n\ 640 The initial hull is narrow (cosine of min. angle is %.16f).\n\ 641 A coplanar point may lead to a wide facet. Options 'QbB' (scale to unit box)\n\ 642 or 'Qbb' (scale last coordinate) may remove this warning. Use 'Pp' to skip\n\ 643 this warning. See 'Limitations' in qh-impre.htm.\n",
653 realT min, max, *coord, dist;
657 The input to qhull appears to be less than %d dimensional, or a\n\ 658 computation has overflowed.\n\n\ 659 Qhull could not construct a clearly convex simplex from points:\n",
664 The center point is coplanar with a facet, or a vertex is coplanar\n\ 665 with a neighboring facet. The maximum round off error for\n\ 666 computing distances is %2.2g. The center point, facets and distances\n\ 667 to the center point are as follows:\n\n",
qh DISTround);
676 qh_fprintf(fp, 9381,
" distance= %4.2g\n", dist);
681 These points are the dual of the given halfspaces. They indicate that\n\ 682 the intersection is degenerate.\n");
684 These points either have a maximum or minimum x-coordinate, or\n\ 685 they maximize the determinant for k coordinates. Trial points\n\ 686 are first selected from points that maximize a coordinate.\n");
689 Because of the high dimension, the min x-coordinate and max-coordinate\n\ 690 points are used if the determinant is non-zero. Option 'Qs' will\n\ 691 do a better, though much slower, job. Instead of 'Qs', you can change\n\ 692 the points by randomly rotating the input with 'QR0'.\n");
694 qh_fprintf(fp, 9385,
"\nThe min and max coordinates for each dimension are:\n");
695 for (k=0; k <
qh hull_dim; k++) {
698 for (i=
qh num_points, coord=
qh first_point+k; i--; coord +=
qh hull_dim) {
702 qh_fprintf(fp, 9386,
" %d: %8.4g %8.4g difference= %4.4g\n", k, min, max, max-min);
706 If the input should be full dimensional, you have several options that\n\ 707 may determine an initial simplex:\n\ 708 - use 'QJ' to joggle the input and make it full dimensional\n\ 709 - use 'QbB' to scale the points to the unit cube\n\ 710 - use 'QR0' to randomly rotate the input for different maximum points\n\ 711 - use 'Qs' to search all points for the initial simplex\n\ 712 - use 'En' to specify a maximum roundoff error less than %2.2g.\n\ 713 - trace execution with 'T3' to see the determinant for each point.\n",
717 - recompile qhull for realT precision(#define REALfloat 0 in libqhull.h).\n");
720 If the input is lower dimensional:\n\ 721 - use 'QJ' to joggle the input and make it full dimensional\n\ 722 - use 'Qbk:0Bk:0' to delete coordinate k from the input. You should\n\ 723 pick the coordinate with the least range. The hull will have the\n\ 725 - determine the flat containing the points, rotate the points\n\ 726 into a coordinate plane, and delete the other coordinates.\n\ 727 - add one or more points to make the input full dimensional.\n\ 729 if (
qh DELAUNAY && !
qh ATinfinity)
731 This is a Delaunay triangulation and the input is co-circular or co-spherical:\n\ 732 - use 'Qz' to add a point \"at infinity\" (i.e., above the paraboloid)\n\ 733 - or use 'QJ' to joggle the input and avoid co-circular data\n");
facetT * qh_findbestfacet(pointT *point, boolT bestoutside, realT *bestdist, boolT *isoutside)
void seed(unsigned int seed_value)
void qh_errprint(const char *string, facetT *atfacet, facetT *otherfacet, ridgeT *atridge, vertexT *atvertex)
#define FOREACHvertex_(vertices)
void qh_printpoint(FILE *fp, const char *string, pointT *point)
void findDelaunay(int dim)
void makehalf(coordT *points, int numpoints, int dim)
void qh_printhelp_singular(FILE *fp)
void qh_fprintf(FILE *fp, int msgcode, const char *fmt,...)
void qh_errexit(int exitcode, facetT *facet, ridgeT *ridge)
coordT * qh_sethalfspace_all(int dim, int count, coordT *halfspaces, pointT *feasible)
void qh_check_output(void)
void qh_printend(FILE *fp, qh_PRINT format, facetT *facetlist, setT *facets, boolT printall)
#define FORALLfacet_(facetlist)
void qh_printfacetlist(facetT *facetlist, setT *facets, boolT printall)
void addDelaunay(coordT *points, int numpoints, int numnew, int dim)
int qh_pointid(pointT *point)
void qh_nearcoplanar(void)
void qh_init_A(FILE *infile, FILE *outfile, FILE *errfile, int argc, char *argv[])
void addhalf(coordT *points, int numpoints, int numnew, int dim, coordT *feasible)
boolT qh_addpoint(pointT *furthest, facetT *facet, boolT checkdist)
void qh_triangulate(void)
boolT qh_sethalfspace(int dim, coordT *coords, coordT **nextp, coordT *normal, coordT *offset, coordT *feasible)
void qh_check_points(void)
void qh_printhelp_narrowhull(FILE *fp, realT minangle)
void qh_setdelaunay(int dim, int count, pointT *points)
void qh_printpointid(FILE *fp, const char *string, int dim, pointT *point, int id)
void qh_printhelp_degenerate(FILE *fp)
void makecube(coordT *points, int numpoints, int dim)
void qh_produce_output(void)
void qh_freeqhull(boolT allmem)
#define maximize_(maxval, val)
void qh_init_B(coordT *points, int numpoints, int dim, boolT ismalloc)
void qh_setfeasible(int dim)
#define FOREACHfacet_(facets)
void qh_printbegin(FILE *fp, qh_PRINT format, facetT *facetlist, setT *facets, boolT printall)
void qh_memfreeshort(int *curlong, int *totlong)
void qh_printafacet(FILE *fp, qh_PRINT format, facetT *facet, boolT printall)
void qh_check_maxout(void)
void makeDelaunay(coordT *points, int numpoints, int dim)
void qh_initflags(char *command)
void adddiamond(coordT *points, int numpoints, int numnew, int dim)
void qh_distplane(pointT *point, facetT *facet, realT *dist)
int qh_setsize(setT *set)
void qh_user_memsizes(void)
#define qh_RANDOMseed_(seed)
int main(int argc, char *argv[])
void qh_printvertexlist(FILE *fp, const char *string, facetT *facetlist, setT *facets, boolT printall)
#define minimize_(minval, val)