42 *dist= facet->
offset + point[0] * normal[0] + point[1] * normal[1];
45 *dist= facet->
offset + point[0] * normal[0] + point[1] * normal[1] + point[2] * normal[2];
48 *dist= facet->
offset+point[0]*normal[0]+point[1]*normal[1]+point[2]*normal[2]+point[3]*normal[3];
51 *dist= facet->
offset+point[0]*normal[0]+point[1]*normal[1]+point[2]*normal[2]+point[3]*normal[3]+point[4]*normal[4];
54 *dist= facet->
offset+point[0]*normal[0]+point[1]*normal[1]+point[2]*normal[2]+point[3]*normal[3]+point[4]*normal[4]+point[5]*normal[5];
57 *dist= facet->
offset+point[0]*normal[0]+point[1]*normal[1]+point[2]*normal[2]+point[3]*normal[3]+point[4]*normal[4]+point[5]*normal[5]+point[6]*normal[6];
60 *dist= facet->
offset+point[0]*normal[0]+point[1]*normal[1]+point[2]*normal[2]+point[3]*normal[3]+point[4]*normal[4]+point[5]*normal[5]+point[6]*normal[6]+point[7]*normal[7];
65 for (k=
qh hull_dim; k--; )
66 *dist += *coordp++ * *normal++;
70 if (!
qh RANDOMdist &&
qh IStracing < 4)
75 qh RANDOMfactor *
qh MAXabs_coord;
77 if (
qh IStracing >= 4) {
142 realT *dist,
boolT *isoutside,
int *numpart) {
144 facetT *facet, *neighbor, **neighborp;
145 facetT *bestfacet= NULL, *lastfacet= NULL;
146 int oldtrace=
qh IStracing;
147 unsigned int visitid= ++
qh visit_id;
152 if (
qh IStracing >= 3 || (
qh TRACElevel &&
qh TRACEpoint >= 0 &&
qh TRACEpoint ==
qh_pointid(point))) {
153 if (
qh TRACElevel >
qh IStracing)
154 qh IStracing=
qh TRACElevel;
155 qh_fprintf(
qh ferr, 8004,
"qh_findbest: point p%d starting at f%d isnewfacets? %d, unless %d exit if > %2.2g\n",
156 qh_pointid(point), startfacet->
id, isnewfacets, bestoutside,
qh MINoutside);
157 qh_fprintf(
qh ferr, 8005,
" testhorizon? %d noupper? %d", testhorizon, noupper);
158 qh_fprintf(
qh ferr, 8006,
" Last point added was p%d.",
qh furthest_id);
166 if (!bestoutside && *dist >=
qh MINoutside
168 bestfacet= startfacet;
169 goto LABELreturn_best;
173 bestfacet= startfacet;
180 trace4((
qh ferr, 4001,
"qh_findbest: neighbors of f%d, bestdist %2.2g f%d\n",
181 facet->
id, bestdist,
getid_(bestfacet)));
184 if (!neighbor->
newfacet && isnewfacets)
186 if (neighbor->
visitid == visitid)
192 if (*dist > bestdist) {
193 if (!bestoutside && *dist >=
qh MINoutside
196 goto LABELreturn_best;
202 }
else if (!bestfacet) {
214 bestfacet=
qh_findbestnew(point, startfacet->
next, &bestdist, bestoutside, isoutside, &numpartnew);
216 }
else if (!
qh findbest_notsharp && bestdist < -
qh DISTround) {
220 bestfacet=
qh_findbestnew(point, bestfacet, &bestdist, bestoutside, isoutside, &numpartnew);
224 qh findbest_notsharp=
True;
232 if (isoutside && bestdist <
qh MINoutside)
237 (*numpart) += numpartnew;
238 qh IStracing= oldtrace;
282 facetT *bestfacet= startfacet;
284 facetT *neighbor, **neighborp, *facet;
286 int numpartinit= *numpart, coplanarfacetset_size;
287 unsigned int visitid= ++
qh visit_id;
289 realT minsearch, searchdist;
295 if ((!
qh ONLYgood || startfacet->
good) && *bestdist > startfacet->
maxoutside)
300 minsearch= *bestdist - searchdist;
305 coplanarfacetset_size= 0;
308 trace4((
qh ferr, 4002,
"qh_findbesthorizon: neighbors of f%d bestdist %2.2g f%d ischeckmax? %d noupper? %d minsearch %2.2g searchdist %2.2g\n",
309 facet->
id, *bestdist,
getid_(bestfacet), ischeckmax, noupper,
310 minsearch, searchdist));
312 if (neighbor->
visitid == visitid)
318 if (dist > *bestdist) {
319 if (!neighbor->
upperdelaunay || ischeckmax || (!noupper && dist >=
qh MINoutside)) {
324 minsearch= dist - searchdist;
325 if (dist > *bestdist + searchdist) {
327 coplanarfacetset_size= 0;
331 }
else if (dist < minsearch)
334 if (ischeckmax && dist > neighbor->
maxoutside)
339 if (!coplanarfacetset_size++) {
351 else if (!coplanarfacetset_size)
353 else if (!--coplanarfacetset_size) {
365 trace4((
qh ferr, 4003,
"qh_findbesthorizon: newbest? %d bestfacet f%d bestdist %2.2g\n", newbest,
getid_(bestfacet), *bestdist));
415 facetT *bestfacet= NULL, *facet;
416 int oldtrace=
qh IStracing, i;
417 unsigned int visitid= ++
qh visit_id;
418 realT distoutside= 0.0;
424 qh_fprintf(
qh ferr, 6001,
"qhull precision error (qh_findbestnew): merging has formed and deleted a cone of new facets. Can not continue.\n");
426 qh_fprintf(
qh ferr, 6002,
"qhull internal error (qh_findbestnew): no new facets for point p%d\n",
431 if (
qh BESToutside || bestoutside)
432 isdistoutside=
False;
440 if (
qh IStracing >= 3 || (
qh TRACElevel &&
qh TRACEpoint >= 0 &&
qh TRACEpoint ==
qh_pointid(point))) {
441 if (
qh TRACElevel >
qh IStracing)
442 qh IStracing=
qh TRACElevel;
443 qh_fprintf(
qh ferr, 8008,
"qh_findbestnew: point p%d facet f%d. Stop? %d if dist > %2.2g\n",
444 qh_pointid(point), startfacet->
id, isdistoutside, distoutside);
445 qh_fprintf(
qh ferr, 8009,
" Last point added p%d visitid %d.",
qh furthest_id, visitid);
449 for (i=0, facet=startfacet; i < 2; i++, facet=
qh newfacet_list) {
451 if (facet == startfacet && i)
453 facet->visitid= visitid;
454 if (!facet->flipped) {
457 if (*dist > bestdist) {
458 if (!facet->upperdelaunay || *dist >=
qh MINoutside) {
460 if (isdistoutside && *dist >= distoutside)
461 goto LABELreturn_bestnew;
468 if (testhorizon || !bestfacet)
472 if (isoutside && *dist <
qh MINoutside)
477 trace4((
qh ferr, 4004,
"qh_findbestnew: bestfacet f%d bestdist %2.2g\n",
getid_(bestfacet), *dist));
478 qh IStracing= oldtrace;
524 coordT *normalp, *normal_tail, *ai, *ak;
529 normalp= normal + numcol - 1;
530 *normalp--= (sign ? -1.0 : 1.0);
531 for (i=numrow; i--; ) {
535 for (j=i+1; j < numcol; j++)
536 *normalp -= *ai++ * *ak++;
537 diagonal= (rows[i])[i];
538 if (
fabs_(diagonal) >
qh MINdenom_2)
539 *(normalp--) /= diagonal;
542 *normalp=
qh_divzero(*normalp, diagonal,
qh MINdenom_1_2, &waszero);
545 *(normalp--)= (sign ? -1.0 : 1.0);
546 for (normal_tail= normalp+2; normal_tail < normal + numcol; normal_tail++)
555 trace4((
qh ferr, 4005,
"qh_backnormal: zero diagonal at column %d.\n", i));
582 realT *ai, *ak, *rowp, *pivotrow;
583 realT n, pivot, pivot_abs= 0.0, temp;
584 int i, j, k, pivoti, flip=0;
587 for (k=0; k < numrow; k++) {
588 pivot_abs=
fabs_((rows[k])[k]);
590 for (i=k+1; i < numrow; i++) {
591 if ((temp=
fabs_((rows[i])[k])) > pivot_abs) {
598 rows[pivoti]= rows[k];
603 if (pivot_abs <=
qh NEARzero[k]) {
605 if (pivot_abs == 0.0) {
606 if (
qh IStracing >= 4) {
607 qh_fprintf(
qh ferr, 8011,
"qh_gausselim: 0 pivot at column %d. (%2.2g < %2.2g)\n", k, pivot_abs,
qh DISTround);
615 pivotrow= rows[k] + k;
617 for (i=k+1; i < numrow; i++) {
621 for (j= numcol - (k+1); j--; )
628 if (
qh IStracing >= 5)
645 realT angle= 0, randr;
648 for (k=
qh hull_dim; k--; )
649 angle += *vect1++ * *vect2++;
655 trace4((
qh ferr, 4006,
"qh_getangle: %2.2g\n", angle));
676 qh_fprintf(
qh ferr, 6003,
"qhull internal error (qh_getcenter): not defined for %d points\n", count);
680 for (k=0; k <
qh hull_dim; k++) {
684 *coord += vertex->
point[k];
709 trace4((
qh ferr, 4007,
"qh_getcentrum: for f%d, %d vertices dist= %2.2g\n",
730 realT dist, maxd, mind;
744 else if (dist > maxd)
807 realT *colp, *maxp, norm= 0, temp, *norm1, *norm2, *norm3;
814 norm= sqrt((*normal)*(*normal) + (*norm1)*(*norm1));
816 norm= sqrt((*normal)*(*normal) + (*norm1)*(*norm1) + (*norm2)*(*norm2));
818 norm= sqrt((*normal)*(*normal) + (*norm1)*(*norm1) + (*norm2)*(*norm2)
819 + (*norm3)*(*norm3));
821 norm= (*normal)*(*normal) + (*norm1)*(*norm1) + (*norm2)*(*norm2)
823 for (k=dim-4, colp=normal+4; k--; colp++)
824 norm += (*colp) * (*colp);
834 if (norm >
qh MINdenom) {
849 for (k=dim-4, colp=normal+4; k--; )
852 }
else if (norm == 0.0) {
854 for (k=dim, colp=normal; k--; )
859 for (k=dim, colp=normal; k--; colp++) {
865 temp= ((*maxp * norm >= 0.0) ? 1.0 : -1.0);
866 for (k=dim, colp=normal; k--; colp++)
870 trace0((
qh ferr, 1,
"qh_normalize: norm=%2.2g too small during p%d\n",
871 norm,
qh furthest_id));
894 pointT *newpoint, *np, *normal;
895 int normsize=
qh normal_size;
902 for (k=
qh hull_dim; k--; )
903 *(np++)= *point++ - dist * *normal++;
932 int normsize=
qh normal_size;
933 int k,i, oldtrace= 0;
943 if (facet ==
qh tracefacet) {
944 oldtrace=
qh IStracing;
946 qh_fprintf(
qh ferr, 8012,
"qh_setfacetplane: facet f%d created.\n", facet->
id);
947 qh_fprintf(
qh ferr, 8013,
" Last point added to hull was p%d.",
qh furthest_id);
953 if (
qh hull_dim <= 4) {
956 gmcoord=
qh gm_matrix;
958 qh gm_row[i++]= gmcoord;
959 coord= vertex->
point;
960 for (k=
qh hull_dim; k--; )
970 if (
qh hull_dim > 4 || nearzero) {
972 gmcoord=
qh gm_matrix;
974 if (vertex->
point != point0) {
975 qh gm_row[i++]= gmcoord;
976 coord= vertex->
point;
978 for (k=
qh hull_dim; k--; )
979 *(gmcoord++)= *coord++ - *point++;
982 qh gm_row[i]= gmcoord;
984 gmcoord=
qh gm_matrix;
985 for (i=
qh hull_dim-1; i--; ) {
986 for (k=
qh hull_dim; k--; )
994 trace0((
qh ferr, 2,
"qh_setfacetplane: flipped orientation after testing interior_point during p%d\n",
qh furthest_id));
1010 if (
qh UPPERdelaunay) {
1018 if (
qh PRINTstatistics ||
qh IStracing ||
qh TRACElevel ||
qh JOGGLEmax <
REALmax) {
1019 qh old_randomdist=
qh RANDOMdist;
1022 if (vertex->
point != point0) {
1031 if (dist >
qh max_outside) {
1032 qh max_outside= dist;
1033 if (dist >
qh TRACEdist)
1036 }
else if (-dist >
qh TRACEdist)
1039 qh_fprintf(
qh ferr, 8016,
"qh_setfacetplane: ====== vertex p%d(v%d) increases max_outside to %2.2g for new facet f%d last p%d\n",
1045 qh RANDOMdist=
qh old_randomdist;
1047 if (
qh IStracing >= 3) {
1048 qh_fprintf(
qh ferr, 8017,
"qh_setfacetplane: f%d offset %2.2g normal: ",
1050 for (k=0; k <
qh hull_dim; k++)
1054 if (facet ==
qh tracefacet)
1055 qh IStracing= oldtrace;
1105 realT maxround, dist;
1114 *offset= -(point0[0]*normal[0]+point0[1]*normal[1]);
1116 }
else if (dim == 3) {
1124 *offset= -(point0[0]*normal[0] + point0[1]*normal[1]
1125 + point0[2]*normal[2]);
1126 maxround=
qh DISTround;
1127 for (i=dim; i--; ) {
1129 if (point != point0) {
1130 dist= *offset + (point[0]*normal[0] + point[1]*normal[1]
1131 + point[2]*normal[2]);
1132 if (dist > maxround || dist < -maxround) {
1138 }
else if (dim == 4) {
1140 dY(1,0),
dZ(1,0),
dW(1,0),
1141 dY(3,0),
dZ(3,0),
dW(3,0));
1143 dX(1,0),
dZ(1,0),
dW(1,0),
1144 dX(3,0),
dZ(3,0),
dW(3,0));
1146 dX(1,0),
dY(1,0),
dW(1,0),
1147 dX(3,0),
dY(3,0),
dW(3,0));
1149 dX(1,0),
dY(1,0),
dZ(1,0),
1150 dX(3,0),
dY(3,0),
dZ(3,0));
1152 *offset= -(point0[0]*normal[0] + point0[1]*normal[1]
1153 + point0[2]*normal[2] + point0[3]*normal[3]);
1154 maxround=
qh DISTround;
1155 for (i=dim; i--; ) {
1157 if (point != point0) {
1158 dist= *offset + (point[0]*normal[0] + point[1]*normal[1]
1159 + point[2]*normal[2] + point[3]*normal[3]);
1160 if (dist > maxround || dist < -maxround) {
1169 trace0((
qh ferr, 3,
"qh_sethyperplane_det: degenerate norm during p%d.\n",
qh furthest_id));
1203 coordT *pointcoord, *normalcoef;
1208 for (k=dim-1; k--; ) {
1209 if ((rows[k])[k] < 0)
1214 trace0((
qh ferr, 4,
"qh_sethyperplane_gauss: nearly singular or axis parallel hyperplane during p%d.\n",
qh furthest_id));
1220 trace0((
qh ferr, 5,
"qh_sethyperplane_gauss: singular or axis parallel hyperplane at normalization during p%d.\n",
qh furthest_id));
1228 *offset= -(*pointcoord++ * *normalcoef++);
1229 for (k=dim-1; k--; )
1230 *offset -= *pointcoord++ * *normalcoef++;
facetT * qh_findbestlower(facetT *upperfacet, pointT *point, realT *bestdistp, int *numpart)
void qh_sethyperplane_gauss(int dim, coordT **rows, pointT *point0, boolT toporient, coordT *normal, coordT *offset, boolT *nearzero)
pointT * qh_getcenter(setT *vertices)
void qh_sethyperplane_det(int dim, coordT **rows, coordT *point0, boolT toporient, coordT *normal, realT *offset, boolT *nearzero)
#define FOREACHvertex_(vertices)
#define SETfirstt_(set, type)
#define qh_memalloc_(insize, freelistp, object, type)
facetT * qh_findbestnew(pointT *point, facetT *startfacet, realT *dist, boolT bestoutside, boolT *isoutside, int *numpart)
void qh_fprintf(FILE *fp, int msgcode, const char *fmt,...)
void qh_precision(const char *reason)
#define FORALLfacet_(facetlist)
int qh_pointid(pointT *point)
realT qh_getangle(pointT *vect1, pointT *vect2)
#define det2_(a1, a2, b1, b2)
facetT * qh_findbest(pointT *point, facetT *startfacet, boolT bestoutside, boolT isnewfacets, boolT noupper, realT *dist, boolT *isoutside, int *numpart)
boolT qh_sharpnewfacets(void)
void qh_gausselim(realT **rows, int numrow, int numcol, boolT *sign, boolT *nearzero)
void qh_backnormal(realT **rows, int numrow, int numcol, boolT sign, coordT *normal, boolT *nearzero)
facetT * qh_findbesthorizon(boolT ischeckmax, pointT *point, facetT *startfacet, boolT noupper, realT *bestdist, int *numpart)
pointT * qh_getcentrum(facetT *facet)
#define det3_(a1, a2, a3, b1, b2, b3, c1, c2, c3)
void qh_printmatrix(FILE *fp, const char *string, realT **rows, int numrow, int numcol)
realT qh_randomfactor(realT scale, realT offset)
boolT qh_orientoutside(facetT *facet)
#define FOREACHneighbor_(facet)
void qh_normalize(coordT *normal, int dim, boolT toporient)
void qh_setappend(setT **setp, void *newelem)
void * qh_setdellast(setT *set)
void qh_memfree(void *object, int insize)
void qh_printsummary(FILE *fp)
#define SETtruncate_(set, size)
void qh_errexit(int exitcode, facetT *facet, ridgeT *ridge)
void qh_normalize2(coordT *normal, int dim, boolT toporient, realT *minnorm, boolT *ismin)
realT * qh_maxabsval(realT *normal, int dim)
realT qh_divzero(realT numer, realT denom, realT mindenom1, boolT *zerodiv)
pointT * qh_projectpoint(pointT *point, facetT *facet, realT dist)
void * qh_memalloc(int insize)
void qh_distplane(pointT *point, facetT *facet, realT *dist)
int qh_setsize(setT *set)
realT qh_getdistance(facetT *facet, facetT *neighbor, realT *mindist, realT *maxdist)
void qh_errprint(const char *string, facetT *atfacet, facetT *otherfacet, ridgeT *atridge, vertexT *atvertex)
#define minimize_(minval, val)
void qh_setfacetplane(facetT *facet)