geom.h 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. /* geom.h -- header file for geometric routines
  2. see README and geom.c
  3. copyright (c) 1993, 1997 The Geometry Center
  4. */
  5. #ifndef qhDEFgeom
  6. #define qhDEFgeom 1
  7. /* ============ -macros- ======================== */
  8. /*----------------------------------------------
  9. -fabs_(a) returns the absolute value of a
  10. -fmax_(a,b) returns the maximum value of a and b
  11. -fmin_(a,b) returns the minimum value of a and b
  12. -maximize_(maxval, val) sets maxval to val if greater
  13. -minimize_(minval, val) sets minval to val if less
  14. */
  15. #define fabs_(a) (((a) < 0) ? -(a):(a))
  16. #define fmax_(a,b) ( (a) < (b) ? (b) : (a) )
  17. #define fmin_(a,b) ( (a) > (b) ? (b) : (a) )
  18. #define maximize_(maxval, val) {if ((maxval) < (val)) (maxval)= (val);}
  19. #define minimize_(minval, val) {if ((minval) > (val)) (minval)= (val);}
  20. /*-----------------------------------------------
  21. -det2_(a1, a2, 2-d determinate
  22. b1, b2)
  23. -det3_(a1, a2, a3, 3-d determinate
  24. b1, b2, b3,
  25. c1, c2, c3)
  26. */
  27. #define det2_(a1,a2,b1,b2) ((a1)*(b2) - (a2)*(b1))
  28. #define det3_(a1,a2,a3,b1,b2,b3,c1,c2,c3) ( (a1)*det2_(b2,b3,c2,c3) \
  29. - (b1)*det2_(a2,a3,c2,c3) + (c1)*det2_(a2,a3,b2,b3) )
  30. /*-----------------------------------------------
  31. -dX, dY, dZ- coordinate differences given row pointers rows[]
  32. */
  33. #define dX(p1,p2) (*(rows[p1]) - *(rows[p2]))
  34. #define dY(p1,p2) (*(rows[p1]+1) - *(rows[p2]+1))
  35. #define dZ(p1,p2) (*(rows[p1]+2) - *(rows[p2]+2))
  36. #define dW(p1,p2) (*(rows[p1]+3) - *(rows[p2]+3))
  37. /* ======= -functions ===========
  38. see geom.c for definitions
  39. Geometric functions
  40. -crossproduct compute the cross product of 2 3-d vectors
  41. -determinant compute the determinant of a square matrix
  42. -detsimplex return determinate of a simplex of points
  43. -divzero divide by a number that's nearly zero
  44. -facetarea_simplex return area for a simplex defined by an apex, base, orient, normal
  45. -gausselim Gaussian elimination with partial pivoting
  46. -getangle return cosine of angle (dot product of two qh hull_dim vectors)
  47. -gram_schmidt implements Gram-Schmidt orthogonalization by rows
  48. -inthresholds return True if normal within qh lower_/upper_threshold
  49. -maxabsval return max absolute value of a vector
  50. -maxsimplex determines maximum simplex for a set of points
  51. -minabsval return min absolute value of a dim vector
  52. -mindiff return index of min abs. difference of two vectors
  53. -normalize normalize a vector
  54. -normalize2 normalize a vector and report if too small
  55. -pointdist return distance between two points
  56. -printmatrix print matrix given by row vectors
  57. -printpoints print pointids for a set of points starting at index
  58. -projectpoints project points along one or more dimensions
  59. -rand/srand generate random numbers
  60. -randomfactor return a random factor within qh RANDOMdistmax of 1.0
  61. -randommatrix generate a random dimXdim matrix in range (-1,1)
  62. -rotatepoints rotate numpoints points by a row matrix
  63. -scalelast scale last coordinate to [0,m] for Delaunay triangulations
  64. -scalepoints scale points to new lowbound and highbound
  65. -sethalfspace_all generate dual for halfspace intersection with feasible point
  66. -sethyperplane_det return hyperplane for oriented simplex, uses determinates
  67. -sethyperplane_gauss return hyperplane for oriented simplex, uses Gaussian elimination
  68. -voronoi_center return Voronoi center for a set of points
  69. Qhull's geometric functions
  70. -backnormal solve for normal x using back substitution over rows U
  71. -distplane return distance from point to facet (>0 if point is above facet)
  72. -facetarea return area for a facet
  73. -facetcenter return Voronoi center for a facet's vertices
  74. -findbest find visible facet for a point starting at a facet
  75. -findbestnew find best newfacet for point
  76. -findgooddist find best good facet visible for point from facet
  77. -getarea get area of all facets in facetlist, collect statistics
  78. -getcenter return arithmetic center of a set of vertices
  79. -getcentrum return centrum for a facet
  80. -getdistance returns the max and min distance of any vertex from neighbor
  81. -maxmin return max/min points for each dim., sets max roundoff errors
  82. -orientoutside make facet outside oriented via qh interior_point
  83. -projectinput project input using qh DELAUNAY and qh low_bound/high_bound
  84. -projectpoint project point onto a facet by distance
  85. -rotateinput rotate input using row matrix
  86. -scaleinput scale input using qh low_bound/high_bound
  87. -setfacetplane sets the hyperplane for a facet
  88. -sethalfspace set coords to dual of halfspace relative to feasible point
  89. */
  90. /*---------- -prototypes in alphabetical order, infrequent at end -----------*/
  91. void qh_backnormal (realT **rows, int numrow, int numcol, boolT sign, coordT *normal, boolT *nearzero);
  92. void qh_distplane (pointT *point, facetT *facet, realT *dist);
  93. facetT *qh_findbest (pointT *point, facetT *facet,
  94. boolT bestoutside, boolT newfacets, boolT noupper,
  95. realT *dist, boolT *isoutside, int *numpart);
  96. facetT *qh_findbestnew (pointT *point, facetT *startfacet,
  97. realT *dist, boolT *isoutside, int *numpart);
  98. void qh_gausselim(realT **rows, int numrow, int numcol, boolT *sign, boolT *nearzero);
  99. realT qh_getangle(pointT *vect1, pointT *vect2);
  100. pointT *qh_getcenter(setT *vertices);
  101. pointT *qh_getcentrum(facetT *facet);
  102. realT qh_getdistance(facetT *facet, facetT *neighbor, realT *mindist, realT *maxdist);
  103. void qh_normalize (coordT *normal, int dim, boolT toporient);
  104. void qh_normalize2 (coordT *normal, int dim, boolT toporient,
  105. realT *minnorm, boolT *ismin);
  106. pointT *qh_projectpoint(pointT *point, facetT *facet, realT dist);
  107. void qh_setfacetplane(facetT *newfacets);
  108. void qh_sethyperplane_det (int dim, coordT **rows, coordT *point0,
  109. boolT toporient, coordT *normal, realT *offset, boolT *nearzero);
  110. void qh_sethyperplane_gauss (int dim, coordT **rows, pointT *point0,
  111. boolT toporient, coordT *normal, coordT *offset, boolT *nearzero);
  112. /* ======= infrequently used code in geom2.c =========== */
  113. void qh_crossproduct (int dim, realT vecA[3], realT vecB[3], realT vecC[3]);
  114. realT qh_determinant (realT **rows, int dim, boolT *nearzero);
  115. realT qh_detsimplex(pointT *apex, setT *points, int dim, boolT *nearzero);
  116. realT qh_divzero(realT numer, realT denom, realT mindenom1, boolT *zerodiv);
  117. realT qh_facetarea (facetT *facet);
  118. realT qh_facetarea_simplex (int dim, coordT *apex, setT *vertices,
  119. vertexT *notvertex, boolT toporient, coordT *normal, realT *offset);
  120. pointT *qh_facetcenter (setT *vertices);
  121. boolT qh_findbestsharp (pointT *point, facetT **bestfacet,
  122. realT *bestdist, int *numpart);
  123. facetT *qh_findgooddist (pointT *point, facetT *facetA, realT *distp, facetT **facetlist);
  124. void qh_getarea (facetT *facetlist);
  125. boolT qh_gram_schmidt(int dim, realT **rows);
  126. boolT qh_inthresholds (coordT *normal, realT *angle);
  127. realT *qh_maxabsval (realT *normal, int dim);
  128. setT *qh_maxmin(pointT *points, int numpoints, int dimension);
  129. void qh_maxsimplex (int dim, setT *maxpoints, pointT *points, int numpoints, setT **simplex);
  130. realT qh_minabsval (realT *normal, int dim);
  131. int qh_mindiff (realT *vecA, realT *vecB, int dim);
  132. boolT qh_orientoutside (facetT *facet);
  133. coordT qh_pointdist(pointT *point1, pointT *point2, int dim);
  134. void qh_printmatrix (FILE *fp, char *string, realT **rows, int numrow, int numcol);
  135. void qh_printpoints (FILE *fp, char *string, setT *points);
  136. void qh_projectinput (void);
  137. void qh_projectpoints (signed char *project, int n, realT *points,
  138. int numpoints, int dim, realT *newpoints, int newdim);
  139. int qh_rand( void);
  140. void qh_srand( int seed);
  141. realT qh_randomfactor (void);
  142. void qh_randommatrix (realT *buffer, int dim, realT **row);
  143. void qh_rotateinput (realT **rows);
  144. void qh_rotatepoints (realT *points, int numpoints, int dim, realT **rows);
  145. void qh_scaleinput (void);
  146. void qh_scalelast (coordT *points, int numpoints, int dim, coordT low,
  147. coordT high, coordT newhigh);
  148. void qh_scalepoints (pointT *points, int numpoints, int dim,
  149. realT *newlows, realT *newhighs);
  150. boolT qh_sethalfspace (int dim, coordT *coords, coordT **nextp,
  151. coordT *normal, coordT *offset, coordT *feasible);
  152. coordT *qh_sethalfspace_all (int dim, int count, coordT *halfspaces, pointT *feasible);
  153. pointT *qh_voronoi_center (int dim, setT *points);
  154. #endif /* qhDEFgeom */