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];
66 *dist += *coordp++ * *normal++;
142 realT *dist,
boolT *isoutside,
int *numpart) {
144 facetT *facet, *neighbor, **neighborp;
145 facetT *bestfacet= NULL, *lastfacet= NULL;
147 unsigned int visitid= ++qh->
visit_id;
155 qh_fprintf(qh, qh->
ferr, 8004,
"qh_findbest: point p%d starting at f%d isnewfacets? %d, unless %d exit if > %2.2g\n",
157 qh_fprintf(qh, qh->
ferr, 8005,
" testhorizon? %d noupper? %d", testhorizon, noupper);
168 bestfacet= startfacet;
169 goto LABELreturn_best;
173 bestfacet= startfacet;
180 trace4((qh, 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) {
196 goto LABELreturn_best;
202 }
else if (!bestfacet) {
214 bestfacet=
qh_findbestnew(qh, point, startfacet->
next, &bestdist, bestoutside, isoutside, &numpartnew);
220 bestfacet=
qh_findbestnew(qh, point, bestfacet, &bestdist, bestoutside, isoutside, &numpartnew);
232 if (isoutside && bestdist < qh->MINoutside)
237 (*numpart) += numpartnew;
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;
300 minsearch= *bestdist - searchdist;
305 coplanarfacetset_size= 0;
308 trace4((qh, 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) {
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, qh->
ferr, 4003,
"qh_findbesthorizon: newbest? %d bestfacet f%d bestdist %2.2g\n", newbest,
getid_(bestfacet), *bestdist));
415 facetT *bestfacet= NULL, *facet;
417 unsigned int visitid= ++qh->
visit_id;
418 realT distoutside= 0.0;
424 qh_fprintf(qh, 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, qh->
ferr, 6002,
"qhull internal error (qh_findbestnew): no new facets for point p%d\n",
432 isdistoutside=
False;
443 qh_fprintf(qh, qh->
ferr, 8008,
"qh_findbestnew: point p%d facet f%d. Stop? %d if dist > %2.2g\n",
444 qh_pointid(qh, point), startfacet->
id, isdistoutside, distoutside);
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, qh->
ferr, 4004,
"qh_findbestnew: bestfacet f%d bestdist %2.2g\n",
getid_(bestfacet), *dist));
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];
539 *(normalp--) /= diagonal;
545 *(normalp--)= (sign ? -1.0 : 1.0);
546 for (normal_tail= normalp+2; normal_tail < normal + numcol; normal_tail++)
555 trace4((qh, 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) {
607 qh_fprintf(qh, qh->
ferr, 8011,
"qh_gausselim: 0 pivot at column %d. (%2.2g < %2.2g)\n", k, pivot_abs, qh->
DISTround);
611 qh_precision(qh,
"zero pivot for Gaussian elimination");
615 pivotrow= rows[k] + k;
617 for (i=k+1; i < numrow; i++) {
621 for (j= numcol - (k+1); j--; )
645 realT angle= 0, randr;
649 angle += *vect1++ * *vect2++;
655 trace4((qh, qh->
ferr, 4006,
"qh_getangle: %2.2g\n", angle));
676 qh_fprintf(qh, qh->
ferr, 6003,
"qhull internal error (qh_getcenter): not defined for %d points\n", count);
684 *coord += vertex->
point[k];
709 trace4((qh, 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);
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, qh->
ferr, 1,
"qh_normalize: norm=%2.2g too small during p%d\n",
894 pointT *newpoint, *np, *normal;
903 *(np++)= *point++ - dist * *normal++;
933 int k,i, oldtrace= 0;
946 qh_fprintf(qh, qh->
ferr, 8012,
"qh_setfacetplane: facet f%d created.\n", facet->
id);
959 coord= vertex->
point;
974 if (vertex->
point != point0) {
976 coord= vertex->
point;
979 *(gmcoord++)= *coord++ - *point++;
994 trace0((qh, qh->
ferr, 2,
"qh_setfacetplane: flipped orientation after testing interior_point during p%d\n", qh->
furthest_id));
1022 if (vertex->
point != point0) {
1039 qh_fprintf(qh, 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",
1041 qh_errprint(qh,
"DISTANT", facet, NULL, NULL, NULL);
1048 qh_fprintf(qh, qh->
ferr, 8017,
"qh_setfacetplane: f%d offset %2.2g normal: ",
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]);
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]);
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) {
1203 coordT *pointcoord, *normalcoef;
1208 for (k=dim-1; k--; ) {
1209 if ((rows[k])[k] < 0)
1214 trace0((qh, qh->
ferr, 4,
"qh_sethyperplane_gauss: nearly singular or axis parallel hyperplane during p%d.\n", qh->
furthest_id));
1215 qh_backnormal(qh, rows, dim-1, dim, sign, normal, &nearzero2);
1217 qh_backnormal(qh, rows, dim-1, dim, sign, normal, &nearzero2);
1220 trace0((qh, 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)
#define FOREACHvertex_(vertices)
void qh_normalize2(qhT *qh, coordT *normal, int dim, boolT toporient, realT *minnorm, boolT *ismin)
#define SETfirstt_(set, type)
#define qh_memalloc_(insize, freelistp, object, type)
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_getdistance(qhT *qh, facetT *facet, facetT *neighbor, realT *mindist, realT *maxdist)
void qh_setfacetplane(qhT *qh, facetT *facet)
pointT * qh_getcentrum(qhT *qh, facetT *facet)
pointT * qh_projectpoint(qhT *qh, pointT *point, facetT *facet, realT dist)
#define det2_(a1, a2, b1, b2)
facetT * qh_findbest(qhT *qh, pointT *point, facetT *startfacet, boolT bestoutside, boolT isnewfacets, boolT noupper, realT *dist, boolT *isoutside, int *numpart)
boolT qh_sharpnewfacets(void)
facetT * qh_findbesthorizon(qhT *qh, boolT ischeckmax, pointT *point, facetT *startfacet, boolT noupper, realT *bestdist, int *numpart)
void qh_distplane(qhT *qh, pointT *point, facetT *facet, realT *dist)
void qh_sethyperplane_gauss(qhT *qh, int dim, coordT **rows, pointT *point0, boolT toporient, coordT *normal, coordT *offset, boolT *nearzero)
#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)
void qh_gausselim(qhT *qh, realT **rows, int numrow, int numcol, boolT *sign, boolT *nearzero)
realT qh_randomfactor(realT scale, realT offset)
void qh_backnormal(qhT *qh, realT **rows, int numrow, int numcol, boolT sign, coordT *normal, boolT *nearzero)
boolT qh_orientoutside(facetT *facet)
#define FOREACHneighbor_(facet)
void qh_sethyperplane_det(qhT *qh, int dim, coordT **rows, coordT *point0, boolT toporient, coordT *normal, realT *offset, boolT *nearzero)
void qh_setappend(setT **setp, void *newelem)
void qh_normalize(qhT *qh, coordT *normal, int dim, boolT toporient)
realT qh_getangle(qhT *qh, pointT *vect1, pointT *vect2)
void * qh_setdellast(setT *set)
void qh_memfree(void *object, int insize)
void qh_printsummary(FILE *fp)
facetT * qh_findbestnew(qhT *qh, pointT *point, facetT *startfacet, realT *dist, boolT bestoutside, boolT *isoutside, int *numpart)
#define SETtruncate_(set, size)
void qh_errexit(int exitcode, facetT *facet, ridgeT *ridge)
pointT * qh_getcenter(qhT *qh, setT *vertices)
realT * qh_maxabsval(realT *normal, int dim)
realT qh_divzero(realT numer, realT denom, realT mindenom1, boolT *zerodiv)
void * qh_memalloc(int insize)
int qh_setsize(setT *set)
void qh_errprint(const char *string, facetT *atfacet, facetT *otherfacet, ridgeT *atridge, vertexT *atvertex)
#define minimize_(minval, val)