33 size= numpoints * dimension * (int)
sizeof(
coordT);
35 qh_fprintf(
qh ferr, 6004,
"qhull error: insufficient memory to copy %d points\n",
39 memcpy((
char *)newpoints, (
char *)points, (
size_t)size);
57 vecC[0]=
det2_(vecA[1], vecA[2],
59 vecC[1]= -
det2_(vecA[0], vecA[2],
61 vecC[2]=
det2_(vecA[0], vecA[1],
89 qh_fprintf(
qh ferr, 6005,
"qhull internal error (qh_determinate): only implemented for dimension >= 2\n");
94 if (
fabs_(det) < 10*
qh NEARzero[1])
100 if (
fabs_(det) < 10*
qh NEARzero[2])
130 realT abscoord, distround, joggle, maxcoord, mincoord;
131 pointT *point, *pointtemp;
137 for (k=0; k < dimension; k++) {
138 if (
qh SCALElast && k == dimension-1)
140 else if (
qh DELAUNAY && k == dimension-1)
141 abscoord= 2 * maxabs * maxabs;
150 abscoord=
fmax_(maxcoord, -mincoord);
158 trace2((
qh ferr, 2001,
"qh_detjoggle: joggle=%2.2g maxwidth=%2.2g\n", joggle, maxwidth));
195 if (!
qh SETroundoff) {
198 qh DISTround +=
qh RANDOMfactor *
qh MAXabs_coord;
201 qh MINdenom=
qh MINdenom_1 *
qh MAXabs_coord;
202 qh MINdenom_1_2= sqrt(
qh MINdenom_1 *
qh hull_dim) ;
203 qh MINdenom_2=
qh MINdenom_1_2 *
qh MAXabs_coord;
207 qh ANGLEround +=
qh RANDOMfactor;
209 qh premerge_cos -=
qh ANGLEround;
211 qh_option(
"Angle-premerge-with-random", NULL, &
qh premerge_cos);
214 qh postmerge_cos -=
qh ANGLEround;
216 qh_option(
"Angle-postmerge-with-random", NULL, &
qh postmerge_cos);
218 qh premerge_centrum += 2 *
qh DISTround;
219 qh postmerge_centrum += 2 *
qh DISTround;
220 if (
qh RANDOMdist && (
qh MERGEexact ||
qh PREmerge))
221 qh_option(
"Centrum-premerge-with-random", NULL, &
qh premerge_centrum);
222 if (
qh RANDOMdist &&
qh POSTmerge)
223 qh_option(
"Centrum-postmerge-with-random", NULL, &
qh postmerge_centrum);
225 realT maxangle= 1.0, maxrho;
230 qh ONEmerge= sqrt((
realT)
qh hull_dim) *
qh MAXwidth *
231 sqrt(1.0 - maxangle * maxangle) +
qh DISTround;
232 maxrho=
qh hull_dim *
qh premerge_centrum +
qh DISTround;
234 maxrho=
qh hull_dim *
qh postmerge_centrum +
qh DISTround;
240 if (
qh JOGGLEmax <
REALmax/2 && (
qh KEEPcoplanar ||
qh KEEPinside)) {
243 maxdist= sqrt((
realT)
qh hull_dim) *
qh JOGGLEmax +
qh DISTround;
247 if (
qh KEEPnearinside)
249 if (
qh JOGGLEmax <
qh DISTround) {
250 qh_fprintf(
qh ferr, 6006,
"qhull error: the joggle for 'QJn', %.2g, is below roundoff for distance computations, %.2g\n",
251 qh JOGGLEmax,
qh DISTround);
256 qh MINvisible=
qh DISTround;
257 else if (
qh hull_dim <= 3)
258 qh MINvisible=
qh premerge_centrum;
261 if (
qh APPROXhull &&
qh MINvisible >
qh MINoutside)
262 qh MINvisible=
qh MINoutside;
263 qh_option(
"Visible-distance", NULL, &
qh MINvisible);
266 qh MAXcoplanar=
qh MINvisible;
267 qh_option(
"U-coplanar-distance", NULL, &
qh MAXcoplanar);
269 if (!
qh APPROXhull) {
270 qh MINoutside= 2 *
qh MINvisible;
275 qh WIDEfacet=
qh MINoutside;
280 && !
qh BESToutside && !
qh FORCEoutput)
281 qh_fprintf(
qh ferr, 7001,
"qhull input warning: minimum visibility V%.2g is greater than \nminimum outside W%.2g. Flipped facets are likely.\n",
282 qh MINvisible,
qh MINoutside);
283 qh max_vertex=
qh DISTround;
284 qh min_vertex= -
qh DISTround;
305 pointT *coorda, *coordp, *gmcoord, *point, **pointp;
311 gmcoord=
qh gm_matrix;
320 *(gmcoord++)= *coordp++ - *coorda++;
323 qh_fprintf(
qh ferr, 6007,
"qhull internal error (qh_detsimplex): #points %d < dimension %d\n",
328 trace2((
qh ferr, 2002,
"qh_detsimplex: det=%2.2g for point p%d, dim %d, nearzero? %d\n",
349 coordT *normalp= normal, *coordp= point;
355 dist += *(coordp++) * *(normalp++);
377 realT maxdistsum, maxround;
379 maxdistsum= sqrt((
realT)dimension) * maxabs;
381 maxround=
REALepsilon * (dimension * maxdistsum * 1.01 + maxabs);
383 trace4((
qh ferr, 4008,
"qh_distround: %2.2g maxabs %2.2g maxsumabs %2.2g maxdistsum %2.2g\n",
384 maxround, maxabs, maxsumabs, maxdistsum));
410 realT temp, numerx, denomx;
413 if (numer < mindenom1 && numer > -mindenom1) {
414 numerx=
fabs_(numer);
415 denomx=
fabs_(denom);
416 if (numerx < denomx) {
425 if (temp > mindenom1 || temp < -mindenom1) {
480 trace4((
qh ferr, 4009,
"qh_facetarea: f%d area %2.2g\n", facet->
id, area));
519 pointT *coorda, *coordp, *gmcoord;
526 gmcoord=
qh gm_matrix;
529 if (vertex == notvertex)
533 coordp= vertex->
point;
537 *(gmcoord++)= *coordp++ - *coorda++;
541 dist += *coordp++ * *normalp++;
542 if (dist < -
qh WIDEfacet) {
546 coordp= vertex->
point;
549 *(gmcoord++)= (*coordp++ - dist * *normalp++) - *coorda++;
553 qh_fprintf(
qh ferr, 6008,
"qhull internal error (qh_facetarea_simplex): #points %d != dim %d -1\n",
559 for (i=0; i <
dim-1; i++)
567 *(gmcoord++)= *normalp++;
573 area *=
qh AREAfactor;
574 trace4((
qh ferr, 4010,
"qh_facetarea_simplex: area=%2.2g for point p%d, toporient %d, nearzero? %d\n",
575 area,
qh_pointid(apex), toporient, nearzero));
633 facetT *neighbor, **neighborp, *bestfacet=NULL, *facet;
651 if (goodseen && !neighbor->
good)
658 if (neighbor->
good) {
660 if (dist > bestdist) {
670 trace2((
qh ferr, 2003,
"qh_findgooddist: p%d is %2.2g above good facet f%d\n",
674 trace4((
qh ferr, 4011,
"qh_findgooddist: no good facet for p%d above f%d\n",
707 if (
qh hasAreaVolume)
710 qh_fprintf(
qh ferr, 8020,
"computing area of each facet and volume of the convex hull\n");
712 trace1((
qh ferr, 1001,
"qh_getarea: computing volume and area for each facet\n"));
713 qh totarea=
qh totvol= 0.0;
730 qh totvol += -dist * area/
qh hull_dim;
732 if (
qh PRINTstatistics) {
764 realT *rowi, *rowj, norm;
767 for (i=0; i <
dim; i++) {
769 for (norm= 0.0, k=
dim; k--; rowi++)
770 norm += *rowi * *rowi;
777 for (j=i+1; j <
dim; j++) {
779 for (norm= 0.0, k=
dim; k--; )
780 norm += *rowi++ * *rowj++;
782 *(--rowj) -= *(--rowi) * norm;
818 for (k=0; k <
qh hull_dim; k++) {
819 threshold=
qh lower_threshold[k];
821 if (normal[k] < threshold)
824 threshold -= normal[k];
825 *angle +=
fabs_(threshold);
829 threshold=
qh upper_threshold[k];
830 if (normal[k] > threshold)
833 threshold -= normal[k];
834 *angle +=
fabs_(threshold);
877 realT randr, randa, randb;
879 if (!
qh input_points) {
880 qh input_points=
qh first_point;
881 qh input_malloc=
qh POINTSmalloc;
882 size=
qh num_points *
qh hull_dim *
sizeof(
coordT);
884 qh_fprintf(
qh ferr, 6009,
"qhull error: insufficient memory to joggle %d points\n",
889 if (
qh JOGGLEmax == 0.0) {
897 if (
qh JOGGLEmax < maxjoggle) {
905 if (
qh build_cnt > 1 &&
qh JOGGLEmax >
fmax_(
qh MAXwidth/4, 0.1)) {
906 qh_fprintf(
qh ferr, 6010,
"qhull error: the current joggle for 'QJn', %.2g, is too large for the width\nof the input. If possible, recompile Qhull with higher-precision reals.\n",
913 trace0((
qh ferr, 6,
"qh_joggleinput: joggle input by %2.2g with seed %d\n",
915 inputp=
qh input_points;
916 coordp=
qh first_point;
918 randb= -
qh JOGGLEmax;
919 size=
qh num_points *
qh hull_dim;
920 for (i=size; i--; ) {
922 *(coordp++)= *(inputp++) + (randr * randa + randb);
939 realT *maxp= NULL, *colp, absval;
942 for (k=
dim, colp= normal; k--; colp++) {
943 absval=
fabs_(*colp);
944 if (absval > maxval) {
981 realT maxcoord, temp;
982 pointT *minimum, *maximum, *point, *pointtemp;
986 qh MAXabs_coord= 0.0;
997 qh_fprintf(
qh ferr, 6011,
"qhull error: floating point constants in user.h are wrong\n\
998 REALepsilon %g REALmin %g REALmax %g -REALmax %g\n",
1003 for (k=0; k < dimension; k++) {
1004 if (points ==
qh GOODpointp)
1005 minimum= maximum= points + dimension;
1007 minimum= maximum= points;
1009 if (point ==
qh GOODpointp)
1011 if (maximum[k] < point[k])
1013 else if (minimum[k] > point[k])
1016 if (k == dimension-1) {
1017 qh MINlastcoord= minimum[k];
1018 qh MAXlastcoord= maximum[k];
1020 if (
qh SCALElast && k == dimension-1)
1021 maxcoord=
qh MAXwidth;
1023 maxcoord=
fmax_(maximum[k], -minimum[k]);
1024 if (
qh GOODpointp) {
1025 temp=
fmax_(
qh GOODpointp[k], -
qh GOODpointp[k]);
1028 temp= maximum[k] - minimum[k];
1032 qh MAXsumcoord += maxcoord;
1041 if (
qh IStracing >=1)
1042 qh_printpoints(
qh ferr,
"qh_maxmin: found the max and min points(by dim):", set);
1069 dist=
fmax_(
qh max_outside,
qh DISTround);
1070 dist +=
qh DISTround;
1071 trace4((
qh ferr, 4012,
"qh_maxouter: max distance from facet to outer plane is %2.2g max_outside is %2.2g\n", dist,
qh max_outside));
1099 pointT *point, **pointp, *pointtemp, *maxpoint, *minx=NULL, *maxx=NULL;
1108 if (maxcoord < point[0]) {
1112 if (mincoord > point[0]) {
1119 if (point ==
qh GOODpointp)
1121 if (maxcoord < point[0]) {
1125 if (mincoord > point[0]) {
1138 qh_fprintf(
qh ferr, 6012,
"qhull precision error (qh_maxsimplex for voronoi_center):\n%d points with the same x coordinate.\n",
1142 qh_fprintf(
qh ferr, 6013,
"qhull input error: input is less than %d-dimensional since it has the same x coordinate\n",
qh hull_dim);
1147 for (k=sizinit; k <
dim+1; k++) {
1153 if ((det=
fabs_(det)) > maxdet) {
1156 maxnearzero= nearzero;
1160 if (!maxpoint || maxnearzero) {
1163 trace0((
qh ferr, 7,
"qh_maxsimplex: searching all points for %d-th initial vertex.\n", k+1));
1165 trace0((
qh ferr, 8,
"qh_maxsimplex: searching all points for %d-th initial vertex, better than p%d det %2.2g\n",
1169 if (point ==
qh GOODpointp)
1173 if ((det=
fabs_(det)) > maxdet) {
1176 maxnearzero= nearzero;
1182 qh_fprintf(
qh ferr, 6014,
"qhull internal error (qh_maxsimplex): not enough points available\n");
1186 trace1((
qh ferr, 1002,
"qh_maxsimplex: selected point p%d for %d`th initial vertex, det=%2.2g\n",
1203 for (k=
dim, colp=normal; k--; colp++) {
1207 return fmax_(maxval, -minval);
1219 realT *vecAp= vecA, *vecBp= vecB;
1222 for (k=0; k <
dim; k++) {
1223 diff= *vecAp++ - *vecBp++;
1225 if (diff < mindiff) {
1250 for (k=
qh hull_dim; k--; )
1280 realT dist, mindist;
1293 *outerplane +=
qh JOGGLEmax * sqrt((
realT)
qh hull_dim);
1303 *innerplane= mindist -
qh DISTround;
1305 *innerplane=
qh min_vertex -
qh DISTround;
1307 *innerplane -=
qh JOGGLEmax * sqrt((
realT)
qh hull_dim);
1325 for (k= (
dim > 0 ?
dim : -
dim); k--; ) {
1326 diff= *point1++ - *point2++;
1327 dist += diff * diff;
1351 for (i=0; i < numrow; i++) {
1353 for (k=0; k < numcol; k++) {
1426 int newdim=
qh input_dim, newnum=
qh num_points;
1427 signed char *project;
1428 int projectsize= (
qh input_dim+1)*
sizeof(*project);
1429 pointT *newpoints, *coord, *infinity;
1430 realT paraboloid, maxboloid= 0;
1433 memset((
char*)project, 0, (
size_t)projectsize);
1434 for (k=0; k <
qh input_dim; k++) {
1435 if (
qh lower_bound[k] == 0 &&
qh upper_bound[k] == 0) {
1446 if (newdim !=
qh hull_dim) {
1448 qh_fprintf(
qh ferr, 6015,
"qhull internal error (qh_projectinput): dimension after projection %d != hull_dim %d\n", newdim,
qh hull_dim);
1453 qh_fprintf(
qh ferr, 6016,
"qhull error: insufficient memory to project %d points\n",
1459 qh num_points,
qh input_dim, newpoints, newdim);
1460 trace1((
qh ferr, 1003,
"qh_projectinput: updating lower and upper_bound\n"));
1462 1,
qh input_dim+1,
qh lower_bound, newdim+1);
1464 1,
qh input_dim+1,
qh upper_bound, newdim+1);
1466 if (!
qh feasible_point) {
1468 qh_fprintf(
qh ferr, 6017,
"qhull internal error (qh_projectinput): HALFspace defined without qh.feasible_point\n");
1472 1,
qh input_dim,
qh feasible_point, newdim);
1475 if (
qh POINTSmalloc)
1477 qh first_point= newpoints;
1479 qh temp_malloc= NULL;
1480 if (
qh DELAUNAY &&
qh ATinfinity) {
1481 coord=
qh first_point;
1482 infinity=
qh first_point +
qh hull_dim *
qh num_points;
1483 for (k=
qh hull_dim-1; k--; )
1485 for (i=
qh num_points; i--; ) {
1487 for (k=0; k <
qh hull_dim-1; k++) {
1488 paraboloid += *coord * *coord;
1489 infinity[k] += *coord;
1492 *(coord++)= paraboloid;
1496 for (k=
qh hull_dim-1; k--; )
1497 *(coord++) /=
qh num_points;
1498 *(coord++)= maxboloid * 1.1;
1500 trace0((
qh ferr, 9,
"qh_projectinput: projected points to paraboloid for Delaunay\n"));
1501 }
else if (
qh DELAUNAY)
1532 int numpoints,
int dim,
realT *newpoints,
int newdim) {
1533 int testdim=
dim, oldk=0, newk=0, i,j=0,k;
1536 for (k=0; k < n; k++)
1537 testdim += project[k];
1538 if (testdim != newdim) {
1539 qh_fprintf(
qh ferr, 6018,
"qhull internal error (qh_projectpoints): newdim %d should be %d after projection\n",
1543 for (j=0; j<n; j++) {
1544 if (project[j] == -1)
1547 newp= newpoints+newk++;
1548 if (project[j] == +1) {
1553 oldp= points+oldk++;
1554 for (i=numpoints; i--; ) {
1563 trace1((
qh ferr, 1004,
"qh_projectpoints: projected %d points from dim %d to dim %d\n",
1564 numpoints,
dim, newdim));
1586 if (!
qh POINTSmalloc) {
1611 realT *point, *rowi, *coord= NULL, sum, *newval;
1614 if (
qh IStracing >= 1)
1616 for (point= points, j= numpoints; j--; point +=
dim) {
1618 for (i=0; i <
dim; i++) {
1621 for (sum= 0.0, k=
dim; k--; )
1622 sum += *rowi++ * *coord++;
1626 *(--coord)= *(--newval);
1648 if (!
qh POINTSmalloc) {
1653 qh lower_bound,
qh upper_bound);
1682 trace4((
qh ferr, 4013,
"qh_scalelast: scale last coordinate from [%2.2g, %2.2g] to [0,%2.2g]\n",
1683 low, high, newhigh));
1686 qh last_newhigh= newhigh;
1688 qh MINdenom_1, &nearzero);
1691 qh_fprintf(
qh ferr, 6019,
"qhull input error: can not scale last coordinate. Input is cocircular\n or cospherical. Use option 'Qz' to add a point at infinity.\n");
1693 qh_fprintf(
qh ferr, 6020,
"qhull input error: can not scale last coordinate. New bounds [0, %2.2g] are too wide for\nexisting bounds [%2.2g, %2.2g] (width %2.2g)\n",
1694 newhigh, low, high, high-low);
1697 shift= - low * newhigh / (high-low);
1698 coord= points +
dim - 1;
1699 for (i=numpoints; i--; coord +=
dim)
1700 *coord= *coord * scale + shift;
1724 realT shift, scale, *coord, low, high, newlow, newhigh, mincoord, maxcoord;
1727 for (k=0; k <
dim; k++) {
1728 newhigh= newhighs[k];
1734 for (i=numpoints, coord=points+k; i--; coord +=
dim) {
1742 if (
qh DELAUNAY && k ==
dim-1 && newhigh < newlow) {
1743 qh_fprintf(
qh ferr, 6021,
"qhull input error: 'Qb%d' or 'QB%d' inverts paraboloid since high bound %.2g < low bound %.2g\n",
1744 k, k, newhigh, newlow);
1747 scale=
qh_divzero(newhigh - newlow, high - low,
1748 qh MINdenom_1, &nearzero);
1750 qh_fprintf(
qh ferr, 6022,
"qhull input error: %d'th dimension's new bounds [%2.2g, %2.2g] too wide for\nexisting bounds [%2.2g, %2.2g]\n",
1751 k, newlow, newhigh, low, high);
1754 shift= (newlow * high - low * newhigh)/(high-low);
1756 for (i=numpoints; i--; coord +=
dim)
1757 *coord= *coord * scale + shift;
1759 if (newlow < newhigh) {
1766 for (i=numpoints; i--; coord +=
dim) {
1770 trace0((
qh ferr, 10,
"qh_scalepoints: scaled %d'th coordinate [%2.2g, %2.2g] to [%.2g, %.2g] for %d points by %2.2g and shifted %2.2g\n",
1771 k, low, high, newlow, newhigh, numpoints, scale, shift));
1811 trace0((
qh ferr, 11,
"qh_setdelaunay: project %d points to paraboloid for Delaunay triangulation\n", count));
1813 for (i=0; i < count; i++) {
1815 paraboloid= coord*coord;
1816 for (k=
dim-2; k--; ) {
1818 paraboloid += coord*coord;
1820 *coordp++ = paraboloid;
1846 coordT *normp= normal, *feasiblep= feasible, *coordp= coords;
1854 dist += *(normp++) * *(feasiblep++);
1856 goto LABELerroroutside;
1858 if (dist < -
qh MINdenom) {
1860 *(coordp++)= *(normp++) / -dist;
1862 for (k=
dim; k--; ) {
1863 *(coordp++)=
qh_divzero(*(normp++), -dist,
qh MINdenom_1, &zerodiv);
1865 goto LABELerroroutside;
1869 if (
qh IStracing >= 4) {
1870 qh_fprintf(
qh ferr, 8021,
"qh_sethalfspace: halfspace at offset %6.2g to point: ", *offset);
1871 for (k=
dim, coordp=coords; k--; ) {
1879 feasiblep= feasible;
1881 qh_fprintf(
qh ferr, 6023,
"qhull input error: feasible point is not clearly inside halfspace\nfeasible point: ");
1921 coordT *coordp, *normalp, *offsetp;
1923 trace0((
qh ferr, 12,
"qh_sethalfspace_all: compute dual for halfspace intersection\n"));
1926 qh_fprintf(
qh ferr, 6024,
"qhull error: insufficient memory to compute dual of %d halfspaces\n",
1931 normalp= halfspaces;
1932 for (i=0; i < count; i++) {
1933 offsetp= normalp + newdim;
1934 if (!
qh_sethalfspace(newdim, coordp, &coordp, normalp, offsetp, feasible)) {
1936 qh_fprintf(
qh ferr, 8032,
"The halfspace was at index %d\n", i);
1939 normalp= offsetp + 1;
1968 if (facet ==
qh newfacet_list) {
1969 for (k=
qh hull_dim; k--; )
1970 quadrant[ k]= (facet->
normal[ k] > 0);
1972 for (k=
qh hull_dim; k--; ) {
1973 if (quadrant[ k] != (facet->
normal[ k] > 0)) {
1983 trace3((
qh ferr, 3001,
"qh_sharpnewfacets: %d\n", issharp));
2013 pointT *point, **pointp, *point0;
2018 realT *diffp, sum2, *sum2row, *sum2p, det, factor;
2019 boolT nearzero, infinite;
2023 else if (size <
dim+1) {
2025 qh_fprintf(
qh ferr, 6025,
"qhull internal error (qh_voronoi_center):\n need at least %d points to construct a Voronoi center\n",
2034 gmcoord=
qh gm_matrix;
2035 for (k=0; k <
dim; k++) {
2036 qh gm_row[k]= gmcoord;
2038 if (point != point0)
2039 *(gmcoord++)= point[k] - point0[k];
2043 for (i=0; i <
dim; i++) {
2045 for (k=0; k <
dim; k++) {
2046 diffp=
qh gm_row[k] + i;
2047 sum2 += *diffp * *diffp;
2059 for (i=0; i <
dim; i++) {
2060 gmcoord=
qh gm_matrix;
2062 for (k=0; k <
dim; k++) {
2063 qh gm_row[k]= gmcoord;
2066 *(gmcoord++)= *sum2p++;
2069 if (point != point0)
2070 *(gmcoord++)= point[k] - point0[k];
2077 if (
qh IStracing >= 3) {
2078 qh_fprintf(
qh ferr, 8033,
"qh_voronoi_center: det %2.2g factor %2.2g ", det, factor);
2080 if (
qh IStracing >= 5) {
2090 if (simplex != points)