triangle.c
上传用户:yflamps
上传日期:2010-04-01
资源大小:155k
文件大小:636k
源码类别:

3D图形编程

开发平台:

C/C++

  1. /*****************************************************************************/
  2. /*                                                                           */
  3. /*      888888888        ,o,                          / 888                  */
  4. /*         888    88o88o  "    o8888o  88o8888o o88888o 888  o88888o         */
  5. /*         888    888    888       88b 888  888 888 888 888 d888  88b        */
  6. /*         888    888    888  o88^o888 888  888 "88888" 888 8888oo888        */
  7. /*         888    888    888 C888  888 888  888  /      888 q888             */
  8. /*         888    888    888  "88o^888 888  888 Cb      888  "88oooo"        */
  9. /*                                              "8oo8D                       */
  10. /*                                                                           */
  11. /*  A Two-Dimensional Quality Mesh Generator and Delaunay Triangulator.      */
  12. /*  (triangle.c)                                                             */
  13. /*                                                                           */
  14. /*  Version 1.6                                                              */
  15. /*  July 28, 2005                                                            */
  16. /*                                                                           */
  17. /*  Copyright 1993, 1995, 1997, 1998, 2002, 2005                             */
  18. /*  Jonathan Richard Shewchuk                                                */
  19. /*  2360 Woolsey #H                                                          */
  20. /*  Berkeley, California  94705-1927                                         */
  21. /*  jrs@cs.berkeley.edu                                                      */
  22. /*                                                                           */
  23. /*  This program may be freely redistributed under the condition that the    */
  24. /*    copyright notices (including this entire header and the copyright      */
  25. /*    notice printed when the `-h' switch is selected) are not removed, and  */
  26. /*    no compensation is received.  Private, research, and institutional     */
  27. /*    use is free.  You may distribute modified versions of this code UNDER  */
  28. /*    THE CONDITION THAT THIS CODE AND ANY MODIFICATIONS MADE TO IT IN THE   */
  29. /*    SAME FILE REMAIN UNDER COPYRIGHT OF THE ORIGINAL AUTHOR, BOTH SOURCE   */
  30. /*    AND OBJECT CODE ARE MADE FREELY AVAILABLE WITHOUT CHARGE, AND CLEAR    */
  31. /*    NOTICE IS GIVEN OF THE MODIFICATIONS.  Distribution of this code as    */
  32. /*    part of a commercial system is permissible ONLY BY DIRECT ARRANGEMENT  */
  33. /*    WITH THE AUTHOR.  (If you are not directly supplying this code to a    */
  34. /*    customer, and you are instead telling them how they can obtain it for  */
  35. /*    free, then you are not required to make any arrangement with me.)      */
  36. /*                                                                           */
  37. /*  Hypertext instructions for Triangle are available on the Web at          */
  38. /*                                                                           */
  39. /*      http://www.cs.cmu.edu/~quake/triangle.html                           */
  40. /*                                                                           */
  41. /*  Disclaimer:  Neither I nor Carnegie Mellon warrant this code in any way  */
  42. /*    whatsoever.  This code is provided "as-is".  Use at your own risk.     */
  43. /*                                                                           */
  44. /*  Some of the references listed below are marked with an asterisk.  [*]    */
  45. /*    These references are available for downloading from the Web page       */
  46. /*                                                                           */
  47. /*      http://www.cs.cmu.edu/~quake/triangle.research.html                  */
  48. /*                                                                           */
  49. /*  Three papers discussing aspects of Triangle are available.  A short      */
  50. /*    overview appears in "Triangle:  Engineering a 2D Quality Mesh          */
  51. /*    Generator and Delaunay Triangulator," in Applied Computational         */
  52. /*    Geometry:  Towards Geometric Engineering, Ming C. Lin and Dinesh       */
  53. /*    Manocha, editors, Lecture Notes in Computer Science volume 1148,       */
  54. /*    pages 203-222, Springer-Verlag, Berlin, May 1996 (from the First ACM   */
  55. /*    Workshop on Applied Computational Geometry).  [*]                      */
  56. /*                                                                           */
  57. /*    The algorithms are discussed in the greatest detail in "Delaunay       */
  58. /*    Refinement Algorithms for Triangular Mesh Generation," Computational   */
  59. /*    Geometry:  Theory and Applications 22(1-3):21-74, May 2002.  [*]       */
  60. /*                                                                           */
  61. /*    More detail about the data structures may be found in my dissertation: */
  62. /*    "Delaunay Refinement Mesh Generation," Ph.D. thesis, Technical Report  */
  63. /*    CMU-CS-97-137, School of Computer Science, Carnegie Mellon University, */
  64. /*    Pittsburgh, Pennsylvania, 18 May 1997.  [*]                            */
  65. /*                                                                           */
  66. /*  Triangle was created as part of the Quake Project in the School of       */
  67. /*    Computer Science at Carnegie Mellon University.  For further           */
  68. /*    information, see Hesheng Bao, Jacobo Bielak, Omar Ghattas, Loukas F.   */
  69. /*    Kallivokas, David R. O'Hallaron, Jonathan R. Shewchuk, and Jifeng Xu,  */
  70. /*    "Large-scale Simulation of Elastic Wave Propagation in Heterogeneous   */
  71. /*    Media on Parallel Computers," Computer Methods in Applied Mechanics    */
  72. /*    and Engineering 152(1-2):85-102, 22 January 1998.                      */
  73. /*                                                                           */
  74. /*  Triangle's Delaunay refinement algorithm for quality mesh generation is  */
  75. /*    a hybrid of one due to Jim Ruppert, "A Delaunay Refinement Algorithm   */
  76. /*    for Quality 2-Dimensional Mesh Generation," Journal of Algorithms      */
  77. /*    18(3):548-585, May 1995 [*], and one due to L. Paul Chew, "Guaranteed- */
  78. /*    Quality Mesh Generation for Curved Surfaces," Proceedings of the Ninth */
  79. /*    Annual Symposium on Computational Geometry (San Diego, California),    */
  80. /*    pages 274-280, Association for Computing Machinery, May 1993,          */
  81. /*    http://portal.acm.org/citation.cfm?id=161150 .                         */
  82. /*                                                                           */
  83. /*  The Delaunay refinement algorithm has been modified so that it meshes    */
  84. /*    domains with small input angles well, as described in Gary L. Miller,  */
  85. /*    Steven E. Pav, and Noel J. Walkington, "When and Why Ruppert's         */
  86. /*    Algorithm Works," Twelfth International Meshing Roundtable, pages      */
  87. /*    91-102, Sandia National Laboratories, September 2003.  [*]             */
  88. /*                                                                           */
  89. /*  My implementation of the divide-and-conquer and incremental Delaunay     */
  90. /*    triangulation algorithms follows closely the presentation of Guibas    */
  91. /*    and Stolfi, even though I use a triangle-based data structure instead  */
  92. /*    of their quad-edge data structure.  (In fact, I originally implemented */
  93. /*    Triangle using the quad-edge data structure, but the switch to a       */
  94. /*    triangle-based data structure sped Triangle by a factor of two.)  The  */
  95. /*    mesh manipulation primitives and the two aforementioned Delaunay       */
  96. /*    triangulation algorithms are described by Leonidas J. Guibas and Jorge */
  97. /*    Stolfi, "Primitives for the Manipulation of General Subdivisions and   */
  98. /*    the Computation of Voronoi Diagrams," ACM Transactions on Graphics     */
  99. /*    4(2):74-123, April 1985, http://portal.acm.org/citation.cfm?id=282923 .*/
  100. /*                                                                           */
  101. /*  Their O(n log n) divide-and-conquer algorithm is adapted from Der-Tsai   */
  102. /*    Lee and Bruce J. Schachter, "Two Algorithms for Constructing the       */
  103. /*    Delaunay Triangulation," International Journal of Computer and         */
  104. /*    Information Science 9(3):219-242, 1980.  Triangle's improvement of the */
  105. /*    divide-and-conquer algorithm by alternating between vertical and       */
  106. /*    horizontal cuts was introduced by Rex A. Dwyer, "A Faster Divide-and-  */
  107. /*    Conquer Algorithm for Constructing Delaunay Triangulations,"           */
  108. /*    Algorithmica 2(2):137-151, 1987.                                       */
  109. /*                                                                           */
  110. /*  The incremental insertion algorithm was first proposed by C. L. Lawson,  */
  111. /*    "Software for C1 Surface Interpolation," in Mathematical Software III, */
  112. /*    John R. Rice, editor, Academic Press, New York, pp. 161-194, 1977.     */
  113. /*    For point location, I use the algorithm of Ernst P. Mucke, Isaac       */
  114. /*    Saias, and Binhai Zhu, "Fast Randomized Point Location Without         */
  115. /*    Preprocessing in Two- and Three-Dimensional Delaunay Triangulations,"  */
  116. /*    Proceedings of the Twelfth Annual Symposium on Computational Geometry, */
  117. /*    ACM, May 1996.  [*]  If I were to randomize the order of vertex        */
  118. /*    insertion (I currently don't bother), their result combined with the   */
  119. /*    result of Kenneth L. Clarkson and Peter W. Shor, "Applications of      */
  120. /*    Random Sampling in Computational Geometry II," Discrete &              */
  121. /*    Computational Geometry 4(1):387-421, 1989, would yield an expected     */
  122. /*    O(n^{4/3}) bound on running time.                                      */
  123. /*                                                                           */
  124. /*  The O(n log n) sweepline Delaunay triangulation algorithm is taken from  */
  125. /*    Steven Fortune, "A Sweepline Algorithm for Voronoi Diagrams",          */
  126. /*    Algorithmica 2(2):153-174, 1987.  A random sample of edges on the      */
  127. /*    boundary of the triangulation are maintained in a splay tree for the   */
  128. /*    purpose of point location.  Splay trees are described by Daniel        */
  129. /*    Dominic Sleator and Robert Endre Tarjan, "Self-Adjusting Binary Search */
  130. /*    Trees," Journal of the ACM 32(3):652-686, July 1985,                   */
  131. /*    http://portal.acm.org/citation.cfm?id=3835 .                           */
  132. /*                                                                           */
  133. /*  The algorithms for exact computation of the signs of determinants are    */
  134. /*    described in Jonathan Richard Shewchuk, "Adaptive Precision Floating-  */
  135. /*    Point Arithmetic and Fast Robust Geometric Predicates," Discrete &     */
  136. /*    Computational Geometry 18(3):305-363, October 1997.  (Also available   */
  137. /*    as Technical Report CMU-CS-96-140, School of Computer Science,         */
  138. /*    Carnegie Mellon University, Pittsburgh, Pennsylvania, May 1996.)  [*]  */
  139. /*    An abbreviated version appears as Jonathan Richard Shewchuk, "Robust   */
  140. /*    Adaptive Floating-Point Geometric Predicates," Proceedings of the      */
  141. /*    Twelfth Annual Symposium on Computational Geometry, ACM, May 1996. [*] */
  142. /*    Many of the ideas for my exact arithmetic routines originate with      */
  143. /*    Douglas M. Priest, "Algorithms for Arbitrary Precision Floating Point  */
  144. /*    Arithmetic," Tenth Symposium on Computer Arithmetic, pp. 132-143, IEEE */
  145. /*    Computer Society Press, 1991.  [*]  Many of the ideas for the correct  */
  146. /*    evaluation of the signs of determinants are taken from Steven Fortune  */
  147. /*    and Christopher J. Van Wyk, "Efficient Exact Arithmetic for Computa-   */
  148. /*    tional Geometry," Proceedings of the Ninth Annual Symposium on         */
  149. /*    Computational Geometry, ACM, pp. 163-172, May 1993, and from Steven    */
  150. /*    Fortune, "Numerical Stability of Algorithms for 2D Delaunay Triangu-   */
  151. /*    lations," International Journal of Computational Geometry & Applica-   */
  152. /*    tions 5(1-2):193-213, March-June 1995.                                 */
  153. /*                                                                           */
  154. /*  The method of inserting new vertices off-center (not precisely at the    */
  155. /*    circumcenter of every poor-quality triangle) is from Alper Ungor,      */
  156. /*    "Off-centers:  A New Type of Steiner Points for Computing Size-Optimal */
  157. /*    Quality-Guaranteed Delaunay Triangulations," Proceedings of LATIN      */
  158. /*    2004 (Buenos Aires, Argentina), April 2004.                            */
  159. /*                                                                           */
  160. /*  For definitions of and results involving Delaunay triangulations,        */
  161. /*    constrained and conforming versions thereof, and other aspects of      */
  162. /*    triangular mesh generation, see the excellent survey by Marshall Bern  */
  163. /*    and David Eppstein, "Mesh Generation and Optimal Triangulation," in    */
  164. /*    Computing and Euclidean Geometry, Ding-Zhu Du and Frank Hwang,         */
  165. /*    editors, World Scientific, Singapore, pp. 23-90, 1992.  [*]            */
  166. /*                                                                           */
  167. /*  The time for incrementally adding PSLG (planar straight line graph)      */
  168. /*    segments to create a constrained Delaunay triangulation is probably    */
  169. /*    O(t^2) per segment in the worst case and O(t) per segment in the       */
  170. /*    common case, where t is the number of triangles that intersect the     */
  171. /*    segment before it is inserted.  This doesn't count point location,     */
  172. /*    which can be much more expensive.  I could improve this to O(d log d)  */
  173. /*    time, but d is usually quite small, so it's not worth the bother.      */
  174. /*    (This note does not apply when the -s switch is used, invoking a       */
  175. /*    different method is used to insert segments.)                          */
  176. /*                                                                           */
  177. /*  The time for deleting a vertex from a Delaunay triangulation is O(d^2)   */
  178. /*    in the worst case and O(d) in the common case, where d is the degree   */
  179. /*    of the vertex being deleted.  I could improve this to O(d log d) time, */
  180. /*    but d is usually quite small, so it's not worth the bother.            */
  181. /*                                                                           */
  182. /*  Ruppert's Delaunay refinement algorithm typically generates triangles    */
  183. /*    at a linear rate (constant time per triangle) after the initial        */
  184. /*    triangulation is formed.  There may be pathological cases where        */
  185. /*    quadratic time is required, but these never arise in practice.         */
  186. /*                                                                           */
  187. /*  The geometric predicates (circumcenter calculations, segment             */
  188. /*    intersection formulae, etc.) appear in my "Lecture Notes on Geometric  */
  189. /*    Robustness" at http://www.cs.berkeley.edu/~jrs/mesh .                  */
  190. /*                                                                           */
  191. /*  If you make any improvements to this code, please please please let me   */
  192. /*    know, so that I may obtain the improvements.  Even if you don't change */
  193. /*    the code, I'd still love to hear what it's being used for.             */
  194. /*                                                                           */
  195. /*****************************************************************************/
  196. /* For single precision (which will save some memory and reduce paging),     */
  197. /*   define the symbol SINGLE by using the -DSINGLE compiler switch or by    */
  198. /*   writing "#define SINGLE" below.                                         */
  199. /*                                                                           */
  200. /* For double precision (which will allow you to refine meshes to a smaller  */
  201. /*   edge length), leave SINGLE undefined.                                   */
  202. /*                                                                           */
  203. /* Double precision uses more memory, but improves the resolution of the     */
  204. /*   meshes you can generate with Triangle.  It also reduces the likelihood  */
  205. /*   of a floating exception due to overflow.  Finally, it is much faster    */
  206. /*   than single precision on 64-bit architectures like the DEC Alpha.  I    */
  207. /*   recommend double precision unless you want to generate a mesh for which */
  208. /*   you do not have enough memory.                                          */
  209. /* #define SINGLE */
  210. #ifdef SINGLE
  211. #define REAL float
  212. #else /* not SINGLE */
  213. #define REAL double
  214. #endif /* not SINGLE */
  215. /* If yours is not a Unix system, define the NO_TIMER compiler switch to     */
  216. /*   remove the Unix-specific timing code.                                   */
  217. /* #define NO_TIMER */
  218. /* To insert lots of self-checks for internal errors, define the SELF_CHECK  */
  219. /*   symbol.  This will slow down the program significantly.  It is best to  */
  220. /*   define the symbol using the -DSELF_CHECK compiler switch, but you could */
  221. /*   write "#define SELF_CHECK" below.  If you are modifying this code, I    */
  222. /*   recommend you turn self-checks on until your work is debugged.          */
  223. /* #define SELF_CHECK */
  224. /* To compile Triangle as a callable object library (triangle.o), define the */
  225. /*   TRILIBRARY symbol.  Read the file triangle.h for details on how to call */
  226. /*   the procedure triangulate() that results.                               */
  227. /* #define TRILIBRARY */
  228. /* It is possible to generate a smaller version of Triangle using one or     */
  229. /*   both of the following symbols.  Define the REDUCED symbol to eliminate  */
  230. /*   all features that are primarily of research interest; specifically, the */
  231. /*   -i, -F, -s, and -C switches.  Define the CDT_ONLY symbol to eliminate   */
  232. /*   all meshing algorithms above and beyond constrained Delaunay            */
  233. /*   triangulation; specifically, the -r, -q, -a, -u, -D, -S, and -s         */
  234. /*   switches.  These reductions are most likely to be useful when           */
  235. /*   generating an object library (triangle.o) by defining the TRILIBRARY    */
  236. /*   symbol.                                                                 */
  237. /* #define REDUCED */
  238. /* #define CDT_ONLY */
  239. /* On some machines, my exact arithmetic routines might be defeated by the   */
  240. /*   use of internal extended precision floating-point registers.  The best  */
  241. /*   way to solve this problem is to set the floating-point registers to use */
  242. /*   single or double precision internally.  On 80x86 processors, this may   */
  243. /*   be accomplished by setting the CPU86 symbol for the Microsoft C         */
  244. /*   compiler, or the LINUX symbol for the gcc compiler running on Linux.    */
  245. /*                                                                           */
  246. /* An inferior solution is to declare certain values as `volatile', thus     */
  247. /*   forcing them to be stored to memory and rounded off.  Unfortunately,    */
  248. /*   this solution might slow Triangle down quite a bit.  To use volatile    */
  249. /*   values, write "#define INEXACT volatile" below.  Normally, however,     */
  250. /*   INEXACT should be defined to be nothing.  ("#define INEXACT".)          */
  251. /*                                                                           */
  252. /* For more discussion, see http://www.cs.cmu.edu/~quake/robust.pc.html .    */
  253. /*   For yet more discussion, see Section 5 of my paper, "Adaptive Precision */
  254. /*   Floating-Point Arithmetic and Fast Robust Geometric Predicates" (also   */
  255. /*   available as Section 6.6 of my dissertation).                           */
  256. /* #define CPU86 */
  257. /* #define LINUX */
  258. #define INEXACT /* Nothing */
  259. /* #define INEXACT volatile */
  260. /* Maximum number of characters in a file name (including the null).         */
  261. #define FILENAMESIZE 2048
  262. /* Maximum number of characters in a line read from a file (including the    */
  263. /*   null).                                                                  */
  264. #define INPUTLINESIZE 1024
  265. /* For efficiency, a variety of data structures are allocated in bulk.  The  */
  266. /*   following constants determine how many of each structure is allocated   */
  267. /*   at once.                                                                */
  268. #define TRIPERBLOCK 4092           /* Number of triangles allocated at once. */
  269. #define SUBSEGPERBLOCK 508       /* Number of subsegments allocated at once. */
  270. #define VERTEXPERBLOCK 4092         /* Number of vertices allocated at once. */
  271. #define VIRUSPERBLOCK 1020   /* Number of virus triangles allocated at once. */
  272. /* Number of encroached subsegments allocated at once. */
  273. #define BADSUBSEGPERBLOCK 252
  274. /* Number of skinny triangles allocated at once. */
  275. #define BADTRIPERBLOCK 4092
  276. /* Number of flipped triangles allocated at once. */
  277. #define FLIPSTACKERPERBLOCK 252
  278. /* Number of splay tree nodes allocated at once. */
  279. #define SPLAYNODEPERBLOCK 508
  280. /* The vertex types.   A DEADVERTEX has been deleted entirely.  An           */
  281. /*   UNDEADVERTEX is not part of the mesh, but is written to the output      */
  282. /*   .node file and affects the node indexing in the other output files.     */
  283. #define INPUTVERTEX 0
  284. #define SEGMENTVERTEX 1
  285. #define FREEVERTEX 2
  286. #define DEADVERTEX -32768
  287. #define UNDEADVERTEX -32767
  288. /* The next line is used to outsmart some very stupid compilers.  If your    */
  289. /*   compiler is smarter, feel free to replace the "int" with "void".        */
  290. /*   Not that it matters.                                                    */
  291. #define VOID int
  292. /* Two constants for algorithms based on random sampling.  Both constants    */
  293. /*   have been chosen empirically to optimize their respective algorithms.   */
  294. /* Used for the point location scheme of Mucke, Saias, and Zhu, to decide    */
  295. /*   how large a random sample of triangles to inspect.                      */
  296. #define SAMPLEFACTOR 11
  297. /* Used in Fortune's sweepline Delaunay algorithm to determine what fraction */
  298. /*   of boundary edges should be maintained in the splay tree for point      */
  299. /*   location on the front.                                                  */
  300. #define SAMPLERATE 10
  301. /* A number that speaks for itself, every kissable digit.                    */
  302. #define PI 3.141592653589793238462643383279502884197169399375105820974944592308
  303. /* Another fave.                                                             */
  304. #define SQUAREROOTTWO 1.4142135623730950488016887242096980785696718753769480732
  305. /* And here's one for those of you who are intimidated by math.              */
  306. #define ONETHIRD 0.333333333333333333333333333333333333333333333333333333333333
  307. #include <stdio.h>
  308. #include <stdlib.h>
  309. #include <string.h>
  310. #include <math.h>
  311. #ifndef NO_TIMER
  312. #include <sys/time.h>
  313. #endif /* not NO_TIMER */
  314. #ifdef CPU86
  315. #include <float.h>
  316. #endif /* CPU86 */
  317. #ifdef LINUX
  318. #include <fpu_control.h>
  319. #endif /* LINUX */
  320. #ifdef TRILIBRARY
  321. #include "triangle.h"
  322. #endif /* TRILIBRARY */
  323. /* A few forward declarations.                                               */
  324. #ifndef TRILIBRARY
  325. char *readline();
  326. char *findfield();
  327. #endif /* not TRILIBRARY */
  328. /* Labels that signify the result of point location.  The result of a        */
  329. /*   search indicates that the point falls in the interior of a triangle, on */
  330. /*   an edge, on a vertex, or outside the mesh.                              */
  331. enum locateresult {INTRIANGLE, ONEDGE, ONVERTEX, OUTSIDE};
  332. /* Labels that signify the result of vertex insertion.  The result indicates */
  333. /*   that the vertex was inserted with complete success, was inserted but    */
  334. /*   encroaches upon a subsegment, was not inserted because it lies on a     */
  335. /*   segment, or was not inserted because another vertex occupies the same   */
  336. /*   location.                                                               */
  337. enum insertvertexresult {SUCCESSFULVERTEX, ENCROACHINGVERTEX, VIOLATINGVERTEX,
  338.                          DUPLICATEVERTEX};
  339. /* Labels that signify the result of direction finding.  The result          */
  340. /*   indicates that a segment connecting the two query points falls within   */
  341. /*   the direction triangle, along the left edge of the direction triangle,  */
  342. /*   or along the right edge of the direction triangle.                      */
  343. enum finddirectionresult {WITHIN, LEFTCOLLINEAR, RIGHTCOLLINEAR};
  344. /*****************************************************************************/
  345. /*                                                                           */
  346. /*  The basic mesh data structures                                           */
  347. /*                                                                           */
  348. /*  There are three:  vertices, triangles, and subsegments (abbreviated      */
  349. /*  `subseg').  These three data structures, linked by pointers, comprise    */
  350. /*  the mesh.  A vertex simply represents a mesh vertex and its properties.  */
  351. /*  A triangle is a triangle.  A subsegment is a special data structure used */
  352. /*  to represent an impenetrable edge of the mesh (perhaps on the outer      */
  353. /*  boundary, on the boundary of a hole, or part of an internal boundary     */
  354. /*  separating two triangulated regions).  Subsegments represent boundaries, */
  355. /*  defined by the user, that triangles may not lie across.                  */
  356. /*                                                                           */
  357. /*  A triangle consists of a list of three vertices, a list of three         */
  358. /*  adjoining triangles, a list of three adjoining subsegments (when         */
  359. /*  segments exist), an arbitrary number of optional user-defined            */
  360. /*  floating-point attributes, and an optional area constraint.  The latter  */
  361. /*  is an upper bound on the permissible area of each triangle in a region,  */
  362. /*  used for mesh refinement.                                                */
  363. /*                                                                           */
  364. /*  For a triangle on a boundary of the mesh, some or all of the neighboring */
  365. /*  triangles may not be present.  For a triangle in the interior of the     */
  366. /*  mesh, often no neighboring subsegments are present.  Such absent         */
  367. /*  triangles and subsegments are never represented by NULL pointers; they   */
  368. /*  are represented by two special records:  `dummytri', the triangle that   */
  369. /*  fills "outer space", and `dummysub', the omnipresent subsegment.         */
  370. /*  `dummytri' and `dummysub' are used for several reasons; for instance,    */
  371. /*  they can be dereferenced and their contents examined without violating   */
  372. /*  protected memory.                                                        */
  373. /*                                                                           */
  374. /*  However, it is important to understand that a triangle includes other    */
  375. /*  information as well.  The pointers to adjoining vertices, triangles, and */
  376. /*  subsegments are ordered in a way that indicates their geometric relation */
  377. /*  to each other.  Furthermore, each of these pointers contains orientation */
  378. /*  information.  Each pointer to an adjoining triangle indicates which face */
  379. /*  of that triangle is contacted.  Similarly, each pointer to an adjoining  */
  380. /*  subsegment indicates which side of that subsegment is contacted, and how */
  381. /*  the subsegment is oriented relative to the triangle.                     */
  382. /*                                                                           */
  383. /*  The data structure representing a subsegment may be thought to be        */
  384. /*  abutting the edge of one or two triangle data structures:  either        */
  385. /*  sandwiched between two triangles, or resting against one triangle on an  */
  386. /*  exterior boundary or hole boundary.                                      */
  387. /*                                                                           */
  388. /*  A subsegment consists of a list of four vertices--the vertices of the    */
  389. /*  subsegment, and the vertices of the segment it is a part of--a list of   */
  390. /*  two adjoining subsegments, and a list of two adjoining triangles.  One   */
  391. /*  of the two adjoining triangles may not be present (though there should   */
  392. /*  always be one), and neighboring subsegments might not be present.        */
  393. /*  Subsegments also store a user-defined integer "boundary marker".         */
  394. /*  Typically, this integer is used to indicate what boundary conditions are */
  395. /*  to be applied at that location in a finite element simulation.           */
  396. /*                                                                           */
  397. /*  Like triangles, subsegments maintain information about the relative      */
  398. /*  orientation of neighboring objects.                                      */
  399. /*                                                                           */
  400. /*  Vertices are relatively simple.  A vertex is a list of floating-point    */
  401. /*  numbers, starting with the x, and y coordinates, followed by an          */
  402. /*  arbitrary number of optional user-defined floating-point attributes,     */
  403. /*  followed by an integer boundary marker.  During the segment insertion    */
  404. /*  phase, there is also a pointer from each vertex to a triangle that may   */
  405. /*  contain it.  Each pointer is not always correct, but when one is, it     */
  406. /*  speeds up segment insertion.  These pointers are assigned values once    */
  407. /*  at the beginning of the segment insertion phase, and are not used or     */
  408. /*  updated except during this phase.  Edge flipping during segment          */
  409. /*  insertion will render some of them incorrect.  Hence, don't rely upon    */
  410. /*  them for anything.                                                       */
  411. /*                                                                           */
  412. /*  Other than the exception mentioned above, vertices have no information   */
  413. /*  about what triangles, subfacets, or subsegments they are linked to.      */
  414. /*                                                                           */
  415. /*****************************************************************************/
  416. /*****************************************************************************/
  417. /*                                                                           */
  418. /*  Handles                                                                  */
  419. /*                                                                           */
  420. /*  The oriented triangle (`otri') and oriented subsegment (`osub') data     */
  421. /*  structures defined below do not themselves store any part of the mesh.   */
  422. /*  The mesh itself is made of `triangle's, `subseg's, and `vertex's.        */
  423. /*                                                                           */
  424. /*  Oriented triangles and oriented subsegments will usually be referred to  */
  425. /*  as "handles."  A handle is essentially a pointer into the mesh; it       */
  426. /*  allows you to "hold" one particular part of the mesh.  Handles are used  */
  427. /*  to specify the regions in which one is traversing and modifying the mesh.*/
  428. /*  A single `triangle' may be held by many handles, or none at all.  (The   */
  429. /*  latter case is not a memory leak, because the triangle is still          */
  430. /*  connected to other triangles in the mesh.)                               */
  431. /*                                                                           */
  432. /*  An `otri' is a handle that holds a triangle.  It holds a specific edge   */
  433. /*  of the triangle.  An `osub' is a handle that holds a subsegment.  It     */
  434. /*  holds either the left or right side of the subsegment.                   */
  435. /*                                                                           */
  436. /*  Navigation about the mesh is accomplished through a set of mesh          */
  437. /*  manipulation primitives, further below.  Many of these primitives take   */
  438. /*  a handle and produce a new handle that holds the mesh near the first     */
  439. /*  handle.  Other primitives take two handles and glue the corresponding    */
  440. /*  parts of the mesh together.  The orientation of the handles is           */
  441. /*  important.  For instance, when two triangles are glued together by the   */
  442. /*  bond() primitive, they are glued at the edges on which the handles lie.  */
  443. /*                                                                           */
  444. /*  Because vertices have no information about which triangles they are      */
  445. /*  attached to, I commonly represent a vertex by use of a handle whose      */
  446. /*  origin is the vertex.  A single handle can simultaneously represent a    */
  447. /*  triangle, an edge, and a vertex.                                         */
  448. /*                                                                           */
  449. /*****************************************************************************/
  450. /* The triangle data structure.  Each triangle contains three pointers to    */
  451. /*   adjoining triangles, plus three pointers to vertices, plus three        */
  452. /*   pointers to subsegments (declared below; these pointers are usually     */
  453. /*   `dummysub').  It may or may not also contain user-defined attributes    */
  454. /*   and/or a floating-point "area constraint."  It may also contain extra   */
  455. /*   pointers for nodes, when the user asks for high-order elements.         */
  456. /*   Because the size and structure of a `triangle' is not decided until     */
  457. /*   runtime, I haven't simply declared the type `triangle' as a struct.     */
  458. typedef REAL **triangle;            /* Really:  typedef triangle *triangle   */
  459. /* An oriented triangle:  includes a pointer to a triangle and orientation.  */
  460. /*   The orientation denotes an edge of the triangle.  Hence, there are      */
  461. /*   three possible orientations.  By convention, each edge always points    */
  462. /*   counterclockwise about the corresponding triangle.                      */
  463. struct otri {
  464.   triangle *tri;
  465.   int orient;                                         /* Ranges from 0 to 2. */
  466. };
  467. /* The subsegment data structure.  Each subsegment contains two pointers to  */
  468. /*   adjoining subsegments, plus four pointers to vertices, plus two         */
  469. /*   pointers to adjoining triangles, plus one boundary marker, plus one     */
  470. /*   segment number.                                                         */
  471. typedef REAL **subseg;                  /* Really:  typedef subseg *subseg   */
  472. /* An oriented subsegment:  includes a pointer to a subsegment and an        */
  473. /*   orientation.  The orientation denotes a side of the edge.  Hence, there */
  474. /*   are two possible orientations.  By convention, the edge is always       */
  475. /*   directed so that the "side" denoted is the right side of the edge.      */
  476. struct osub {
  477.   subseg *ss;
  478.   int ssorient;                                       /* Ranges from 0 to 1. */
  479. };
  480. /* The vertex data structure.  Each vertex is actually an array of REALs.    */
  481. /*   The number of REALs is unknown until runtime.  An integer boundary      */
  482. /*   marker, and sometimes a pointer to a triangle, is appended after the    */
  483. /*   REALs.                                                                  */
  484. typedef REAL *vertex;
  485. /* A queue used to store encroached subsegments.  Each subsegment's vertices */
  486. /*   are stored so that we can check whether a subsegment is still the same. */
  487. struct badsubseg {
  488.   subseg encsubseg;                             /* An encroached subsegment. */
  489.   vertex subsegorg, subsegdest;                         /* Its two vertices. */
  490. };
  491. /* A queue used to store bad triangles.  The key is the square of the cosine */
  492. /*   of the smallest angle of the triangle.  Each triangle's vertices are    */
  493. /*   stored so that one can check whether a triangle is still the same.      */
  494. struct badtriang {
  495.   triangle poortri;                       /* A skinny or too-large triangle. */
  496.   REAL key;                             /* cos^2 of smallest (apical) angle. */
  497.   vertex triangorg, triangdest, triangapex;           /* Its three vertices. */
  498.   struct badtriang *nexttriang;             /* Pointer to next bad triangle. */
  499. };
  500. /* A stack of triangles flipped during the most recent vertex insertion.     */
  501. /*   The stack is used to undo the vertex insertion if the vertex encroaches */
  502. /*   upon a subsegment.                                                      */
  503. struct flipstacker {
  504.   triangle flippedtri;                       /* A recently flipped triangle. */
  505.   struct flipstacker *prevflip;               /* Previous flip in the stack. */
  506. };
  507. /* A node in a heap used to store events for the sweepline Delaunay          */
  508. /*   algorithm.  Nodes do not point directly to their parents or children in */
  509. /*   the heap.  Instead, each node knows its position in the heap, and can   */
  510. /*   look up its parent and children in a separate array.  The `eventptr'    */
  511. /*   points either to a `vertex' or to a triangle (in encoded format, so     */
  512. /*   that an orientation is included).  In the latter case, the origin of    */
  513. /*   the oriented triangle is the apex of a "circle event" of the sweepline  */
  514. /*   algorithm.  To distinguish site events from circle events, all circle   */
  515. /*   events are given an invalid (smaller than `xmin') x-coordinate `xkey'.  */
  516. struct event {
  517.   REAL xkey, ykey;                              /* Coordinates of the event. */
  518.   VOID *eventptr;      /* Can be a vertex or the location of a circle event. */
  519.   int heapposition;              /* Marks this event's position in the heap. */
  520. };
  521. /* A node in the splay tree.  Each node holds an oriented ghost triangle     */
  522. /*   that represents a boundary edge of the growing triangulation.  When a   */
  523. /*   circle event covers two boundary edges with a triangle, so that they    */
  524. /*   are no longer boundary edges, those edges are not immediately deleted   */
  525. /*   from the tree; rather, they are lazily deleted when they are next       */
  526. /*   encountered.  (Since only a random sample of boundary edges are kept    */
  527. /*   in the tree, lazy deletion is faster.)  `keydest' is used to verify     */
  528. /*   that a triangle is still the same as when it entered the splay tree; if */
  529. /*   it has been rotated (due to a circle event), it no longer represents a  */
  530. /*   boundary edge and should be deleted.                                    */
  531. struct splaynode {
  532.   struct otri keyedge;                     /* Lprev of an edge on the front. */
  533.   vertex keydest;           /* Used to verify that splay node is still live. */
  534.   struct splaynode *lchild, *rchild;              /* Children in splay tree. */
  535. };
  536. /* A type used to allocate memory.  firstblock is the first block of items.  */
  537. /*   nowblock is the block from which items are currently being allocated.   */
  538. /*   nextitem points to the next slab of free memory for an item.            */
  539. /*   deaditemstack is the head of a linked list (stack) of deallocated items */
  540. /*   that can be recycled.  unallocateditems is the number of items that     */
  541. /*   remain to be allocated from nowblock.                                   */
  542. /*                                                                           */
  543. /* Traversal is the process of walking through the entire list of items, and */
  544. /*   is separate from allocation.  Note that a traversal will visit items on */
  545. /*   the "deaditemstack" stack as well as live items.  pathblock points to   */
  546. /*   the block currently being traversed.  pathitem points to the next item  */
  547. /*   to be traversed.  pathitemsleft is the number of items that remain to   */
  548. /*   be traversed in pathblock.                                              */
  549. /*                                                                           */
  550. /* alignbytes determines how new records should be aligned in memory.        */
  551. /*   itembytes is the length of a record in bytes (after rounding up).       */
  552. /*   itemsperblock is the number of items allocated at once in a single      */
  553. /*   block.  itemsfirstblock is the number of items in the first block,      */
  554. /*   which can vary from the others.  items is the number of currently       */
  555. /*   allocated items.  maxitems is the maximum number of items that have     */
  556. /*   been allocated at once; it is the current number of items plus the      */
  557. /*   number of records kept on deaditemstack.                                */
  558. struct memorypool {
  559.   VOID **firstblock, **nowblock;
  560.   VOID *nextitem;
  561.   VOID *deaditemstack;
  562.   VOID **pathblock;
  563.   VOID *pathitem;
  564.   int alignbytes;
  565.   int itembytes;
  566.   int itemsperblock;
  567.   int itemsfirstblock;
  568.   long items, maxitems;
  569.   int unallocateditems;
  570.   int pathitemsleft;
  571. };
  572. /* Global constants.                                                         */
  573. REAL splitter;       /* Used to split REAL factors for exact multiplication. */
  574. REAL epsilon;                             /* Floating-point machine epsilon. */
  575. REAL resulterrbound;
  576. REAL ccwerrboundA, ccwerrboundB, ccwerrboundC;
  577. REAL iccerrboundA, iccerrboundB, iccerrboundC;
  578. REAL o3derrboundA, o3derrboundB, o3derrboundC;
  579. /* Random number seed is not constant, but I've made it global anyway.       */
  580. unsigned long randomseed;                     /* Current random number seed. */
  581. /* Mesh data structure.  Triangle operates on only one mesh, but the mesh    */
  582. /*   structure is used (instead of global variables) to allow reentrancy.    */
  583. struct mesh {
  584. /* Variables used to allocate memory for triangles, subsegments, vertices,   */
  585. /*   viri (triangles being eaten), encroached segments, bad (skinny or too   */
  586. /*   large) triangles, and splay tree nodes.                                 */
  587.   struct memorypool triangles;
  588.   struct memorypool subsegs;
  589.   struct memorypool vertices;
  590.   struct memorypool viri;
  591.   struct memorypool badsubsegs;
  592.   struct memorypool badtriangles;
  593.   struct memorypool flipstackers;
  594.   struct memorypool splaynodes;
  595. /* Variables that maintain the bad triangle queues.  The queues are          */
  596. /*   ordered from 4095 (highest priority) to 0 (lowest priority).            */
  597.   struct badtriang *queuefront[4096];
  598.   struct badtriang *queuetail[4096];
  599.   int nextnonemptyq[4096];
  600.   int firstnonemptyq;
  601. /* Variable that maintains the stack of recently flipped triangles.          */
  602.   struct flipstacker *lastflip;
  603. /* Other variables. */
  604.   REAL xmin, xmax, ymin, ymax;                            /* x and y bounds. */
  605.   REAL xminextreme;      /* Nonexistent x value used as a flag in sweepline. */
  606.   int invertices;                               /* Number of input vertices. */
  607.   int inelements;                              /* Number of input triangles. */
  608.   int insegments;                               /* Number of input segments. */
  609.   int holes;                                       /* Number of input holes. */
  610.   int regions;                                   /* Number of input regions. */
  611.   int undeads;    /* Number of input vertices that don't appear in the mesh. */
  612.   long edges;                                     /* Number of output edges. */
  613.   int mesh_dim;                                /* Dimension (ought to be 2). */
  614.   int nextras;                           /* Number of attributes per vertex. */
  615.   int eextras;                         /* Number of attributes per triangle. */
  616.   long hullsize;                          /* Number of edges in convex hull. */
  617.   int steinerleft;                 /* Number of Steiner points not yet used. */
  618.   int vertexmarkindex;         /* Index to find boundary marker of a vertex. */
  619.   int vertex2triindex;     /* Index to find a triangle adjacent to a vertex. */
  620.   int highorderindex;  /* Index to find extra nodes for high-order elements. */
  621.   int elemattribindex;            /* Index to find attributes of a triangle. */
  622.   int areaboundindex;             /* Index to find area bound of a triangle. */
  623.   int checksegments;         /* Are there segments in the triangulation yet? */
  624.   int checkquality;                  /* Has quality triangulation begun yet? */
  625.   int readnodefile;                           /* Has a .node file been read? */
  626.   long samples;              /* Number of random samples for point location. */
  627.   long incirclecount;                 /* Number of incircle tests performed. */
  628.   long counterclockcount;     /* Number of counterclockwise tests performed. */
  629.   long orient3dcount;           /* Number of 3D orientation tests performed. */
  630.   long hyperbolacount;      /* Number of right-of-hyperbola tests performed. */
  631.   long circumcentercount;  /* Number of circumcenter calculations performed. */
  632.   long circletopcount;       /* Number of circle top calculations performed. */
  633. /* Triangular bounding box vertices.                                         */
  634.   vertex infvertex1, infvertex2, infvertex3;
  635. /* Pointer to the `triangle' that occupies all of "outer space."             */
  636.   triangle *dummytri;
  637.   triangle *dummytribase;    /* Keep base address so we can free() it later. */
  638. /* Pointer to the omnipresent subsegment.  Referenced by any triangle or     */
  639. /*   subsegment that isn't really connected to a subsegment at that          */
  640. /*   location.                                                               */
  641.   subseg *dummysub;
  642.   subseg *dummysubbase;      /* Keep base address so we can free() it later. */
  643. /* Pointer to a recently visited triangle.  Improves point location if       */
  644. /*   proximate vertices are inserted sequentially.                           */
  645.   struct otri recenttri;
  646. };                                                  /* End of `struct mesh'. */
  647. /* Data structure for command line switches and file names.  This structure  */
  648. /*   is used (instead of global variables) to allow reentrancy.              */
  649. struct behavior {
  650. /* Switches for the triangulator.                                            */
  651. /*   poly: -p switch.  refine: -r switch.                                    */
  652. /*   quality: -q switch.                                                     */
  653. /*     minangle: minimum angle bound, specified after -q switch.             */
  654. /*     goodangle: cosine squared of minangle.                                */
  655. /*     offconstant: constant used to place off-center Steiner points.        */
  656. /*   vararea: -a switch without number.                                      */
  657. /*   fixedarea: -a switch with number.                                       */
  658. /*     maxarea: maximum area bound, specified after -a switch.               */
  659. /*   usertest: -u switch.                                                    */
  660. /*   regionattrib: -A switch.  convex: -c switch.                            */
  661. /*   weighted: 1 for -w switch, 2 for -W switch.  jettison: -j switch        */
  662. /*   firstnumber: inverse of -z switch.  All items are numbered starting     */
  663. /*     from `firstnumber'.                                                   */
  664. /*   edgesout: -e switch.  voronoi: -v switch.                               */
  665. /*   neighbors: -n switch.  geomview: -g switch.                             */
  666. /*   nobound: -B switch.  nopolywritten: -P switch.                          */
  667. /*   nonodewritten: -N switch.  noelewritten: -E switch.                     */
  668. /*   noiterationnum: -I switch.  noholes: -O switch.                         */
  669. /*   noexact: -X switch.                                                     */
  670. /*   order: element order, specified after -o switch.                        */
  671. /*   nobisect: count of how often -Y switch is selected.                     */
  672. /*   steiner: maximum number of Steiner points, specified after -S switch.   */
  673. /*   incremental: -i switch.  sweepline: -F switch.                          */
  674. /*   dwyer: inverse of -l switch.                                            */
  675. /*   splitseg: -s switch.                                                    */
  676. /*   conformdel: -D switch.  docheck: -C switch.                             */
  677. /*   quiet: -Q switch.  verbose: count of how often -V switch is selected.   */
  678. /*   usesegments: -p, -r, -q, or -c switch; determines whether segments are  */
  679. /*     used at all.                                                          */
  680. /*                                                                           */
  681. /* Read the instructions to find out the meaning of these switches.          */
  682.   int poly, refine, quality, vararea, fixedarea, usertest;
  683.   int regionattrib, convex, weighted, jettison;
  684.   int firstnumber;
  685.   int edgesout, voronoi, neighbors, geomview;
  686.   int nobound, nopolywritten, nonodewritten, noelewritten, noiterationnum;
  687.   int noholes, noexact, conformdel;
  688.   int incremental, sweepline, dwyer;
  689.   int splitseg;
  690.   int docheck;
  691.   int quiet, verbose;
  692.   int usesegments;
  693.   int order;
  694.   int nobisect;
  695.   int steiner;
  696.   REAL minangle, goodangle, offconstant;
  697.   REAL maxarea;
  698. /* Variables for file names.                                                 */
  699. #ifndef TRILIBRARY
  700.   char innodefilename[FILENAMESIZE];
  701.   char inelefilename[FILENAMESIZE];
  702.   char inpolyfilename[FILENAMESIZE];
  703.   char areafilename[FILENAMESIZE];
  704.   char outnodefilename[FILENAMESIZE];
  705.   char outelefilename[FILENAMESIZE];
  706.   char outpolyfilename[FILENAMESIZE];
  707.   char edgefilename[FILENAMESIZE];
  708.   char vnodefilename[FILENAMESIZE];
  709.   char vedgefilename[FILENAMESIZE];
  710.   char neighborfilename[FILENAMESIZE];
  711.   char offfilename[FILENAMESIZE];
  712. #endif /* not TRILIBRARY */
  713. };                                              /* End of `struct behavior'. */
  714. /*****************************************************************************/
  715. /*                                                                           */
  716. /*  Mesh manipulation primitives.  Each triangle contains three pointers to  */
  717. /*  other triangles, with orientations.  Each pointer points not to the      */
  718. /*  first byte of a triangle, but to one of the first three bytes of a       */
  719. /*  triangle.  It is necessary to extract both the triangle itself and the   */
  720. /*  orientation.  To save memory, I keep both pieces of information in one   */
  721. /*  pointer.  To make this possible, I assume that all triangles are aligned */
  722. /*  to four-byte boundaries.  The decode() routine below decodes a pointer,  */
  723. /*  extracting an orientation (in the range 0 to 2) and a pointer to the     */
  724. /*  beginning of a triangle.  The encode() routine compresses a pointer to a */
  725. /*  triangle and an orientation into a single pointer.  My assumptions that  */
  726. /*  triangles are four-byte-aligned and that the `unsigned long' type is     */
  727. /*  long enough to hold a pointer are two of the few kludges in this program.*/
  728. /*                                                                           */
  729. /*  Subsegments are manipulated similarly.  A pointer to a subsegment        */
  730. /*  carries both an address and an orientation in the range 0 to 1.          */
  731. /*                                                                           */
  732. /*  The other primitives take an oriented triangle or oriented subsegment,   */
  733. /*  and return an oriented triangle or oriented subsegment or vertex; or     */
  734. /*  they change the connections in the data structure.                       */
  735. /*                                                                           */
  736. /*  Below, triangles and subsegments are denoted by their vertices.  The     */
  737. /*  triangle abc has origin (org) a, destination (dest) b, and apex (apex)   */
  738. /*  c.  These vertices occur in counterclockwise order about the triangle.   */
  739. /*  The handle abc may simultaneously denote vertex a, edge ab, and triangle */
  740. /*  abc.                                                                     */
  741. /*                                                                           */
  742. /*  Similarly, the subsegment ab has origin (sorg) a and destination (sdest) */
  743. /*  b.  If ab is thought to be directed upward (with b directly above a),    */
  744. /*  then the handle ab is thought to grasp the right side of ab, and may     */
  745. /*  simultaneously denote vertex a and edge ab.                              */
  746. /*                                                                           */
  747. /*  An asterisk (*) denotes a vertex whose identity is unknown.              */
  748. /*                                                                           */
  749. /*  Given this notation, a partial list of mesh manipulation primitives      */
  750. /*  follows.                                                                 */
  751. /*                                                                           */
  752. /*                                                                           */
  753. /*  For triangles:                                                           */
  754. /*                                                                           */
  755. /*  sym:  Find the abutting triangle; same edge.                             */
  756. /*  sym(abc) -> ba*                                                          */
  757. /*                                                                           */
  758. /*  lnext:  Find the next edge (counterclockwise) of a triangle.             */
  759. /*  lnext(abc) -> bca                                                        */
  760. /*                                                                           */
  761. /*  lprev:  Find the previous edge (clockwise) of a triangle.                */
  762. /*  lprev(abc) -> cab                                                        */
  763. /*                                                                           */
  764. /*  onext:  Find the next edge counterclockwise with the same origin.        */
  765. /*  onext(abc) -> ac*                                                        */
  766. /*                                                                           */
  767. /*  oprev:  Find the next edge clockwise with the same origin.               */
  768. /*  oprev(abc) -> a*b                                                        */
  769. /*                                                                           */
  770. /*  dnext:  Find the next edge counterclockwise with the same destination.   */
  771. /*  dnext(abc) -> *ba                                                        */
  772. /*                                                                           */
  773. /*  dprev:  Find the next edge clockwise with the same destination.          */
  774. /*  dprev(abc) -> cb*                                                        */
  775. /*                                                                           */
  776. /*  rnext:  Find the next edge (counterclockwise) of the adjacent triangle.  */
  777. /*  rnext(abc) -> *a*                                                        */
  778. /*                                                                           */
  779. /*  rprev:  Find the previous edge (clockwise) of the adjacent triangle.     */
  780. /*  rprev(abc) -> b**                                                        */
  781. /*                                                                           */
  782. /*  org:  Origin          dest:  Destination          apex:  Apex            */
  783. /*  org(abc) -> a         dest(abc) -> b              apex(abc) -> c         */
  784. /*                                                                           */
  785. /*  bond:  Bond two triangles together at the resepective handles.           */
  786. /*  bond(abc, bad)                                                           */
  787. /*                                                                           */
  788. /*                                                                           */
  789. /*  For subsegments:                                                         */
  790. /*                                                                           */
  791. /*  ssym:  Reverse the orientation of a subsegment.                          */
  792. /*  ssym(ab) -> ba                                                           */
  793. /*                                                                           */
  794. /*  spivot:  Find adjoining subsegment with the same origin.                 */
  795. /*  spivot(ab) -> a*                                                         */
  796. /*                                                                           */
  797. /*  snext:  Find next subsegment in sequence.                                */
  798. /*  snext(ab) -> b*                                                          */
  799. /*                                                                           */
  800. /*  sorg:  Origin                      sdest:  Destination                   */
  801. /*  sorg(ab) -> a                      sdest(ab) -> b                        */
  802. /*                                                                           */
  803. /*  sbond:  Bond two subsegments together at the respective origins.         */
  804. /*  sbond(ab, ac)                                                            */
  805. /*                                                                           */
  806. /*                                                                           */
  807. /*  For interacting tetrahedra and subfacets:                                */
  808. /*                                                                           */
  809. /*  tspivot:  Find a subsegment abutting a triangle.                         */
  810. /*  tspivot(abc) -> ba                                                       */
  811. /*                                                                           */
  812. /*  stpivot:  Find a triangle abutting a subsegment.                         */
  813. /*  stpivot(ab) -> ba*                                                       */
  814. /*                                                                           */
  815. /*  tsbond:  Bond a triangle to a subsegment.                                */
  816. /*  tsbond(abc, ba)                                                          */
  817. /*                                                                           */
  818. /*****************************************************************************/
  819. /********* Mesh manipulation primitives begin here                   *********/
  820. /**                                                                         **/
  821. /**                                                                         **/
  822. /* Fast lookup arrays to speed some of the mesh manipulation primitives.     */
  823. int plus1mod3[3] = {1, 2, 0};
  824. int minus1mod3[3] = {2, 0, 1};
  825. /********* Primitives for triangles                                  *********/
  826. /*                                                                           */
  827. /*                                                                           */
  828. /* decode() converts a pointer to an oriented triangle.  The orientation is  */
  829. /*   extracted from the two least significant bits of the pointer.           */
  830. #define decode(ptr, otri)                                                     
  831.   (otri).orient = (int) ((unsigned long) (ptr) & (unsigned long) 3l);         
  832.   (otri).tri = (triangle *)                                                   
  833.                   ((unsigned long) (ptr) ^ (unsigned long) (otri).orient)
  834. /* encode() compresses an oriented triangle into a single pointer.  It       */
  835. /*   relies on the assumption that all triangles are aligned to four-byte    */
  836. /*   boundaries, so the two least significant bits of (otri).tri are zero.   */
  837. #define encode(otri)                                                          
  838.   (triangle) ((unsigned long) (otri).tri | (unsigned long) (otri).orient)
  839. /* The following handle manipulation primitives are all described by Guibas  */
  840. /*   and Stolfi.  However, Guibas and Stolfi use an edge-based data          */
  841. /*   structure, whereas I use a triangle-based data structure.               */
  842. /* sym() finds the abutting triangle, on the same edge.  Note that the edge  */
  843. /*   direction is necessarily reversed, because the handle specified by an   */
  844. /*   oriented triangle is directed counterclockwise around the triangle.     */
  845. #define sym(otri1, otri2)                                                     
  846.   ptr = (otri1).tri[(otri1).orient];                                          
  847.   decode(ptr, otri2);
  848. #define symself(otri)                                                         
  849.   ptr = (otri).tri[(otri).orient];                                            
  850.   decode(ptr, otri);
  851. /* lnext() finds the next edge (counterclockwise) of a triangle.             */
  852. #define lnext(otri1, otri2)                                                   
  853.   (otri2).tri = (otri1).tri;                                                  
  854.   (otri2).orient = plus1mod3[(otri1).orient]
  855. #define lnextself(otri)                                                       
  856.   (otri).orient = plus1mod3[(otri).orient]
  857. /* lprev() finds the previous edge (clockwise) of a triangle.                */
  858. #define lprev(otri1, otri2)                                                   
  859.   (otri2).tri = (otri1).tri;                                                  
  860.   (otri2).orient = minus1mod3[(otri1).orient]
  861. #define lprevself(otri)                                                       
  862.   (otri).orient = minus1mod3[(otri).orient]
  863. /* onext() spins counterclockwise around a vertex; that is, it finds the     */
  864. /*   next edge with the same origin in the counterclockwise direction.  This */
  865. /*   edge is part of a different triangle.                                   */
  866. #define onext(otri1, otri2)                                                   
  867.   lprev(otri1, otri2);                                                        
  868.   symself(otri2);
  869. #define onextself(otri)                                                       
  870.   lprevself(otri);                                                            
  871.   symself(otri);
  872. /* oprev() spins clockwise around a vertex; that is, it finds the next edge  */
  873. /*   with the same origin in the clockwise direction.  This edge is part of  */
  874. /*   a different triangle.                                                   */
  875. #define oprev(otri1, otri2)                                                   
  876.   sym(otri1, otri2);                                                          
  877.   lnextself(otri2);
  878. #define oprevself(otri)                                                       
  879.   symself(otri);                                                              
  880.   lnextself(otri);
  881. /* dnext() spins counterclockwise around a vertex; that is, it finds the     */
  882. /*   next edge with the same destination in the counterclockwise direction.  */
  883. /*   This edge is part of a different triangle.                              */
  884. #define dnext(otri1, otri2)                                                   
  885.   sym(otri1, otri2);                                                          
  886.   lprevself(otri2);
  887. #define dnextself(otri)                                                       
  888.   symself(otri);                                                              
  889.   lprevself(otri);
  890. /* dprev() spins clockwise around a vertex; that is, it finds the next edge  */
  891. /*   with the same destination in the clockwise direction.  This edge is     */
  892. /*   part of a different triangle.                                           */
  893. #define dprev(otri1, otri2)                                                   
  894.   lnext(otri1, otri2);                                                        
  895.   symself(otri2);
  896. #define dprevself(otri)                                                       
  897.   lnextself(otri);                                                            
  898.   symself(otri);
  899. /* rnext() moves one edge counterclockwise about the adjacent triangle.      */
  900. /*   (It's best understood by reading Guibas and Stolfi.  It involves        */
  901. /*   changing triangles twice.)                                              */
  902. #define rnext(otri1, otri2)                                                   
  903.   sym(otri1, otri2);                                                          
  904.   lnextself(otri2);                                                           
  905.   symself(otri2);
  906. #define rnextself(otri)                                                       
  907.   symself(otri);                                                              
  908.   lnextself(otri);                                                            
  909.   symself(otri);
  910. /* rprev() moves one edge clockwise about the adjacent triangle.             */
  911. /*   (It's best understood by reading Guibas and Stolfi.  It involves        */
  912. /*   changing triangles twice.)                                              */
  913. #define rprev(otri1, otri2)                                                   
  914.   sym(otri1, otri2);                                                          
  915.   lprevself(otri2);                                                           
  916.   symself(otri2);
  917. #define rprevself(otri)                                                       
  918.   symself(otri);                                                              
  919.   lprevself(otri);                                                            
  920.   symself(otri);
  921. /* These primitives determine or set the origin, destination, or apex of a   */
  922. /* triangle.                                                                 */
  923. #define org(otri, vertexptr)                                                  
  924.   vertexptr = (vertex) (otri).tri[plus1mod3[(otri).orient] + 3]
  925. #define dest(otri, vertexptr)                                                 
  926.   vertexptr = (vertex) (otri).tri[minus1mod3[(otri).orient] + 3]
  927. #define apex(otri, vertexptr)                                                 
  928.   vertexptr = (vertex) (otri).tri[(otri).orient + 3]
  929. #define setorg(otri, vertexptr)                                               
  930.   (otri).tri[plus1mod3[(otri).orient] + 3] = (triangle) vertexptr
  931. #define setdest(otri, vertexptr)                                              
  932.   (otri).tri[minus1mod3[(otri).orient] + 3] = (triangle) vertexptr
  933. #define setapex(otri, vertexptr)                                              
  934.   (otri).tri[(otri).orient + 3] = (triangle) vertexptr
  935. /* Bond two triangles together.                                              */
  936. #define bond(otri1, otri2)                                                    
  937.   (otri1).tri[(otri1).orient] = encode(otri2);                                
  938.   (otri2).tri[(otri2).orient] = encode(otri1)
  939. /* Dissolve a bond (from one side).  Note that the other triangle will still */
  940. /*   think it's connected to this triangle.  Usually, however, the other     */
  941. /*   triangle is being deleted entirely, or bonded to another triangle, so   */
  942. /*   it doesn't matter.                                                      */
  943. #define dissolve(otri)                                                        
  944.   (otri).tri[(otri).orient] = (triangle) m->dummytri
  945. /* Copy an oriented triangle.                                                */
  946. #define otricopy(otri1, otri2)                                                
  947.   (otri2).tri = (otri1).tri;                                                  
  948.   (otri2).orient = (otri1).orient
  949. /* Test for equality of oriented triangles.                                  */
  950. #define otriequal(otri1, otri2)                                               
  951.   (((otri1).tri == (otri2).tri) &&                                            
  952.    ((otri1).orient == (otri2).orient))
  953. /* Primitives to infect or cure a triangle with the virus.  These rely on    */
  954. /*   the assumption that all subsegments are aligned to four-byte boundaries.*/
  955. #define infect(otri)                                                          
  956.   (otri).tri[6] = (triangle)                                                  
  957.                     ((unsigned long) (otri).tri[6] | (unsigned long) 2l)
  958. #define uninfect(otri)                                                        
  959.   (otri).tri[6] = (triangle)                                                  
  960.                     ((unsigned long) (otri).tri[6] & ~ (unsigned long) 2l)
  961. /* Test a triangle for viral infection.                                      */
  962. #define infected(otri)                                                        
  963.   (((unsigned long) (otri).tri[6] & (unsigned long) 2l) != 0l)
  964. /* Check or set a triangle's attributes.                                     */
  965. #define elemattribute(otri, attnum)                                           
  966.   ((REAL *) (otri).tri)[m->elemattribindex + (attnum)]
  967. #define setelemattribute(otri, attnum, value)                                 
  968.   ((REAL *) (otri).tri)[m->elemattribindex + (attnum)] = value
  969. /* Check or set a triangle's maximum area bound.                             */
  970. #define areabound(otri)  ((REAL *) (otri).tri)[m->areaboundindex]
  971. #define setareabound(otri, value)                                             
  972.   ((REAL *) (otri).tri)[m->areaboundindex] = value
  973. /* Check or set a triangle's deallocation.  Its second pointer is set to     */
  974. /*   NULL to indicate that it is not allocated.  (Its first pointer is used  */
  975. /*   for the stack of dead items.)  Its fourth pointer (its first vertex)    */
  976. /*   is set to NULL in case a `badtriang' structure points to it.            */
  977. #define deadtri(tria)  ((tria)[1] == (triangle) NULL)
  978. #define killtri(tria)                                                         
  979.   (tria)[1] = (triangle) NULL;                                                
  980.   (tria)[3] = (triangle) NULL
  981. /********* Primitives for subsegments                                *********/
  982. /*                                                                           */
  983. /*                                                                           */
  984. /* sdecode() converts a pointer to an oriented subsegment.  The orientation  */
  985. /*   is extracted from the least significant bit of the pointer.  The two    */
  986. /*   least significant bits (one for orientation, one for viral infection)   */
  987. /*   are masked out to produce the real pointer.                             */
  988. #define sdecode(sptr, osub)                                                   
  989.   (osub).ssorient = (int) ((unsigned long) (sptr) & (unsigned long) 1l);      
  990.   (osub).ss = (subseg *)                                                      
  991.               ((unsigned long) (sptr) & ~ (unsigned long) 3l)
  992. /* sencode() compresses an oriented subsegment into a single pointer.  It    */
  993. /*   relies on the assumption that all subsegments are aligned to two-byte   */
  994. /*   boundaries, so the least significant bit of (osub).ss is zero.          */
  995. #define sencode(osub)                                                         
  996.   (subseg) ((unsigned long) (osub).ss | (unsigned long) (osub).ssorient)
  997. /* ssym() toggles the orientation of a subsegment.                           */
  998. #define ssym(osub1, osub2)                                                    
  999.   (osub2).ss = (osub1).ss;                                                    
  1000.   (osub2).ssorient = 1 - (osub1).ssorient
  1001. #define ssymself(osub)                                                        
  1002.   (osub).ssorient = 1 - (osub).ssorient
  1003. /* spivot() finds the other subsegment (from the same segment) that shares   */
  1004. /*   the same origin.                                                        */
  1005. #define spivot(osub1, osub2)                                                  
  1006.   sptr = (osub1).ss[(osub1).ssorient];                                        
  1007.   sdecode(sptr, osub2)
  1008. #define spivotself(osub)                                                      
  1009.   sptr = (osub).ss[(osub).ssorient];                                          
  1010.   sdecode(sptr, osub)
  1011. /* snext() finds the next subsegment (from the same segment) in sequence;    */
  1012. /*   one whose origin is the input subsegment's destination.                 */
  1013. #define snext(osub1, osub2)                                                   
  1014.   sptr = (osub1).ss[1 - (osub1).ssorient];                                    
  1015.   sdecode(sptr, osub2)
  1016. #define snextself(osub)                                                       
  1017.   sptr = (osub).ss[1 - (osub).ssorient];                                      
  1018.   sdecode(sptr, osub)
  1019. /* These primitives determine or set the origin or destination of a          */
  1020. /*   subsegment or the segment that includes it.                             */
  1021. #define sorg(osub, vertexptr)                                                 
  1022.   vertexptr = (vertex) (osub).ss[2 + (osub).ssorient]
  1023. #define sdest(osub, vertexptr)                                                
  1024.   vertexptr = (vertex) (osub).ss[3 - (osub).ssorient]
  1025. #define setsorg(osub, vertexptr)                                              
  1026.   (osub).ss[2 + (osub).ssorient] = (subseg) vertexptr
  1027. #define setsdest(osub, vertexptr)                                             
  1028.   (osub).ss[3 - (osub).ssorient] = (subseg) vertexptr
  1029. #define segorg(osub, vertexptr)                                               
  1030.   vertexptr = (vertex) (osub).ss[4 + (osub).ssorient]
  1031. #define segdest(osub, vertexptr)                                              
  1032.   vertexptr = (vertex) (osub).ss[5 - (osub).ssorient]
  1033. #define setsegorg(osub, vertexptr)                                            
  1034.   (osub).ss[4 + (osub).ssorient] = (subseg) vertexptr
  1035. #define setsegdest(osub, vertexptr)                                           
  1036.   (osub).ss[5 - (osub).ssorient] = (subseg) vertexptr
  1037. /* These primitives read or set a boundary marker.  Boundary markers are     */
  1038. /*   used to hold user-defined tags for setting boundary conditions in       */
  1039. /*   finite element solvers.                                                 */
  1040. #define mark(osub)  (* (int *) ((osub).ss + 8))
  1041. #define setmark(osub, value)                                                  
  1042.   * (int *) ((osub).ss + 8) = value
  1043. /* Bond two subsegments together.                                            */
  1044. #define sbond(osub1, osub2)                                                   
  1045.   (osub1).ss[(osub1).ssorient] = sencode(osub2);                              
  1046.   (osub2).ss[(osub2).ssorient] = sencode(osub1)
  1047. /* Dissolve a subsegment bond (from one side).  Note that the other          */
  1048. /*   subsegment will still think it's connected to this subsegment.          */
  1049. #define sdissolve(osub)                                                       
  1050.   (osub).ss[(osub).ssorient] = (subseg) m->dummysub
  1051. /* Copy a subsegment.                                                        */
  1052. #define subsegcopy(osub1, osub2)                                              
  1053.   (osub2).ss = (osub1).ss;                                                    
  1054.   (osub2).ssorient = (osub1).ssorient
  1055. /* Test for equality of subsegments.                                         */
  1056. #define subsegequal(osub1, osub2)                                             
  1057.   (((osub1).ss == (osub2).ss) &&                                              
  1058.    ((osub1).ssorient == (osub2).ssorient))
  1059. /* Check or set a subsegment's deallocation.  Its second pointer is set to   */
  1060. /*   NULL to indicate that it is not allocated.  (Its first pointer is used  */
  1061. /*   for the stack of dead items.)  Its third pointer (its first vertex)     */
  1062. /*   is set to NULL in case a `badsubseg' structure points to it.            */
  1063. #define deadsubseg(sub)  ((sub)[1] == (subseg) NULL)
  1064. #define killsubseg(sub)                                                       
  1065.   (sub)[1] = (subseg) NULL;                                                   
  1066.   (sub)[2] = (subseg) NULL
  1067. /********* Primitives for interacting triangles and subsegments      *********/
  1068. /*                                                                           */
  1069. /*                                                                           */
  1070. /* tspivot() finds a subsegment abutting a triangle.                         */
  1071. #define tspivot(otri, osub)                                                   
  1072.   sptr = (subseg) (otri).tri[6 + (otri).orient];                              
  1073.   sdecode(sptr, osub)
  1074. /* stpivot() finds a triangle abutting a subsegment.  It requires that the   */
  1075. /*   variable `ptr' of type `triangle' be defined.                           */
  1076. #define stpivot(osub, otri)                                                   
  1077.   ptr = (triangle) (osub).ss[6 + (osub).ssorient];                            
  1078.   decode(ptr, otri)
  1079. /* Bond a triangle to a subsegment.                                          */
  1080. #define tsbond(otri, osub)                                                    
  1081.   (otri).tri[6 + (otri).orient] = (triangle) sencode(osub);                   
  1082.   (osub).ss[6 + (osub).ssorient] = (subseg) encode(otri)
  1083. /* Dissolve a bond (from the triangle side).                                 */
  1084. #define tsdissolve(otri)                                                      
  1085.   (otri).tri[6 + (otri).orient] = (triangle) m->dummysub
  1086. /* Dissolve a bond (from the subsegment side).                               */
  1087. #define stdissolve(osub)                                                      
  1088.   (osub).ss[6 + (osub).ssorient] = (subseg) m->dummytri
  1089. /********* Primitives for vertices                                   *********/
  1090. /*                                                                           */
  1091. /*                                                                           */
  1092. #define vertexmark(vx)  ((int *) (vx))[m->vertexmarkindex]
  1093. #define setvertexmark(vx, value)                                              
  1094.   ((int *) (vx))[m->vertexmarkindex] = value
  1095. #define vertextype(vx)  ((int *) (vx))[m->vertexmarkindex + 1]
  1096. #define setvertextype(vx, value)                                              
  1097.   ((int *) (vx))[m->vertexmarkindex + 1] = value
  1098. #define vertex2tri(vx)  ((triangle *) (vx))[m->vertex2triindex]
  1099. #define setvertex2tri(vx, value)                                              
  1100.   ((triangle *) (vx))[m->vertex2triindex] = value
  1101. /**                                                                         **/
  1102. /**                                                                         **/
  1103. /********* Mesh manipulation primitives end here                     *********/
  1104. /********* User-defined triangle evaluation routine begins here      *********/
  1105. /**                                                                         **/
  1106. /**                                                                         **/
  1107. /*****************************************************************************/
  1108. /*                                                                           */
  1109. /*  triunsuitable()   Determine if a triangle is unsuitable, and thus must   */
  1110. /*                    be further refined.                                    */
  1111. /*                                                                           */
  1112. /*  You may write your own procedure that decides whether or not a selected  */
  1113. /*  triangle is too big (and needs to be refined).  There are two ways to do */
  1114. /*  this.                                                                    */
  1115. /*                                                                           */
  1116. /*  (1)  Modify the procedure `triunsuitable' below, then recompile          */
  1117. /*  Triangle.                                                                */
  1118. /*                                                                           */
  1119. /*  (2)  Define the symbol EXTERNAL_TEST (either by adding the definition    */
  1120. /*  to this file, or by using the appropriate compiler switch).  This way,   */
  1121. /*  you can compile triangle.c separately from your test.  Write your own    */
  1122. /*  `triunsuitable' procedure in a separate C file (using the same prototype */
  1123. /*  as below).  Compile it and link the object code with triangle.o.         */
  1124. /*                                                                           */
  1125. /*  This procedure returns 1 if the triangle is too large and should be      */
  1126. /*  refined; 0 otherwise.                                                    */
  1127. /*                                                                           */
  1128. /*****************************************************************************/
  1129. #ifdef EXTERNAL_TEST
  1130. int triunsuitable();
  1131. #else /* not EXTERNAL_TEST */
  1132. #ifdef ANSI_DECLARATORS
  1133. int triunsuitable(vertex triorg, vertex tridest, vertex triapex, REAL area)
  1134. #else /* not ANSI_DECLARATORS */
  1135. int triunsuitable(triorg, tridest, triapex, area)
  1136. vertex triorg;                              /* The triangle's origin vertex. */
  1137. vertex tridest;                        /* The triangle's destination vertex. */
  1138. vertex triapex;                               /* The triangle's apex vertex. */
  1139. REAL area;                                      /* The area of the triangle. */
  1140. #endif /* not ANSI_DECLARATORS */
  1141. {
  1142.   REAL dxoa, dxda, dxod;
  1143.   REAL dyoa, dyda, dyod;
  1144.   REAL oalen, dalen, odlen;
  1145.   REAL maxlen;
  1146.   dxoa = triorg[0] - triapex[0];
  1147.   dyoa = triorg[1] - triapex[1];
  1148.   dxda = tridest[0] - triapex[0];
  1149.   dyda = tridest[1] - triapex[1];
  1150.   dxod = triorg[0] - tridest[0];
  1151.   dyod = triorg[1] - tridest[1];
  1152.   /* Find the squares of the lengths of the triangle's three edges. */
  1153.   oalen = dxoa * dxoa + dyoa * dyoa;
  1154.   dalen = dxda * dxda + dyda * dyda;
  1155.   odlen = dxod * dxod + dyod * dyod;
  1156.   /* Find the square of the length of the longest edge. */
  1157.   maxlen = (dalen > oalen) ? dalen : oalen;
  1158.   maxlen = (odlen > maxlen) ? odlen : maxlen;
  1159.   if (maxlen > 0.05 * (triorg[0] * triorg[0] + triorg[1] * triorg[1]) + 0.02) {
  1160.     return 1;
  1161.   } else {
  1162.     return 0;
  1163.   }
  1164. }
  1165. #endif /* not EXTERNAL_TEST */
  1166. /**                                                                         **/
  1167. /**                                                                         **/
  1168. /********* User-defined triangle evaluation routine ends here        *********/
  1169. /********* Memory allocation and program exit wrappers begin here    *********/
  1170. /**                                                                         **/
  1171. /**                                                                         **/
  1172. #ifdef ANSI_DECLARATORS
  1173. void triexit(int status)
  1174. #else /* not ANSI_DECLARATORS */
  1175. void triexit(status)
  1176. int status;
  1177. #endif /* not ANSI_DECLARATORS */
  1178. {
  1179.   exit(status);
  1180. }
  1181. #ifdef ANSI_DECLARATORS
  1182. VOID *trimalloc(int size)
  1183. #else /* not ANSI_DECLARATORS */
  1184. VOID *trimalloc(size)
  1185. int size;
  1186. #endif /* not ANSI_DECLARATORS */
  1187. {
  1188.   VOID *memptr;
  1189.   memptr = (VOID *) malloc((unsigned int) size);
  1190.   if (memptr == (VOID *) NULL) {
  1191.     printf("Error:  Out of memory.n");
  1192.     triexit(1);
  1193.   }
  1194.   return(memptr);
  1195. }
  1196. #ifdef ANSI_DECLARATORS
  1197. void trifree(VOID *memptr)
  1198. #else /* not ANSI_DECLARATORS */
  1199. void trifree(memptr)
  1200. VOID *memptr;
  1201. #endif /* not ANSI_DECLARATORS */
  1202. {
  1203.   free(memptr);
  1204. }
  1205. /**                                                                         **/
  1206. /**                                                                         **/
  1207. /********* Memory allocation and program exit wrappers end here      *********/
  1208. /********* User interaction routines begin here                      *********/
  1209. /**                                                                         **/
  1210. /**                                                                         **/
  1211. /*****************************************************************************/
  1212. /*                                                                           */
  1213. /*  syntax()   Print list of command line switches.                          */
  1214. /*                                                                           */
  1215. /*****************************************************************************/
  1216. #ifndef TRILIBRARY
  1217. void syntax()
  1218. {
  1219. #ifdef CDT_ONLY
  1220. #ifdef REDUCED
  1221.   printf("triangle [-pAcjevngBPNEIOXzo_lQVh] input_filen");
  1222. #else /* not REDUCED */
  1223.   printf("triangle [-pAcjevngBPNEIOXzo_iFlCQVh] input_filen");
  1224. #endif /* not REDUCED */
  1225. #else /* not CDT_ONLY */
  1226. #ifdef REDUCED
  1227.   printf("triangle [-prq__a__uAcDjevngBPNEIOXzo_YS__lQVh] input_filen");
  1228. #else /* not REDUCED */
  1229.   printf("triangle [-prq__a__uAcDjevngBPNEIOXzo_YS__iFlsCQVh] input_filen");
  1230. #endif /* not REDUCED */
  1231. #endif /* not CDT_ONLY */
  1232.   printf("    -p  Triangulates a Planar Straight Line Graph (.poly file).n");
  1233. #ifndef CDT_ONLY
  1234.   printf("    -r  Refines a previously generated mesh.n");
  1235.   printf(
  1236.     "    -q  Quality mesh generation.  A minimum angle may be specified.n");
  1237.   printf("    -a  Applies a maximum triangle area constraint.n");
  1238.   printf("    -u  Applies a user-defined triangle constraint.n");
  1239. #endif /* not CDT_ONLY */
  1240.   printf(
  1241.     "    -A  Applies attributes to identify triangles in certain regions.n");
  1242.   printf("    -c  Encloses the convex hull with segments.n");
  1243. #ifndef CDT_ONLY
  1244.   printf("    -D  Conforming Delaunay:  all triangles are truly Delaunay.n");
  1245. #endif /* not CDT_ONLY */
  1246. /*
  1247.   printf("    -w  Weighted Delaunay triangulation.n");
  1248.   printf("    -W  Regular triangulation (lower hull of a height field).n");
  1249. */
  1250.   printf("    -j  Jettison unused vertices from output .node file.n");
  1251.   printf("    -e  Generates an edge list.n");
  1252.   printf("    -v  Generates a Voronoi diagram.n");
  1253.   printf("    -n  Generates a list of triangle neighbors.n");
  1254.   printf("    -g  Generates an .off file for Geomview.n");
  1255.   printf("    -B  Suppresses output of boundary information.n");
  1256.   printf("    -P  Suppresses output of .poly file.n");
  1257.   printf("    -N  Suppresses output of .node file.n");
  1258.   printf("    -E  Suppresses output of .ele file.n");
  1259.   printf("    -I  Suppresses mesh iteration numbers.n");
  1260.   printf("    -O  Ignores holes in .poly file.n");
  1261.   printf("    -X  Suppresses use of exact arithmetic.n");
  1262.   printf("    -z  Numbers all items starting from zero (rather than one).n");
  1263.   printf("    -o2 Generates second-order subparametric elements.n");
  1264. #ifndef CDT_ONLY
  1265.   printf("    -Y  Suppresses boundary segment splitting.n");
  1266.   printf("    -S  Specifies maximum number of added Steiner points.n");
  1267. #endif /* not CDT_ONLY */
  1268. #ifndef REDUCED
  1269.   printf("    -i  Uses incremental method, rather than divide-and-conquer.n");
  1270.   printf("    -F  Uses Fortune's sweepline algorithm, rather than d-and-c.n");
  1271. #endif /* not REDUCED */
  1272.   printf("    -l  Uses vertical cuts only, rather than alternating cuts.n");
  1273. #ifndef REDUCED
  1274. #ifndef CDT_ONLY
  1275.   printf(
  1276.     "    -s  Force segments into mesh by splitting (instead of using CDT).n");
  1277. #endif /* not CDT_ONLY */
  1278.   printf("    -C  Check consistency of final mesh.n");
  1279. #endif /* not REDUCED */
  1280.   printf("    -Q  Quiet:  No terminal output except errors.n");
  1281.   printf("    -V  Verbose:  Detailed information on what I'm doing.n");
  1282.   printf("    -h  Help:  Detailed instructions for Triangle.n");
  1283.   triexit(0);
  1284. }
  1285. #endif /* not TRILIBRARY */
  1286. /*****************************************************************************/
  1287. /*                                                                           */
  1288. /*  info()   Print out complete instructions.                                */
  1289. /*                                                                           */
  1290. /*****************************************************************************/
  1291. #ifndef TRILIBRARY
  1292. void info()
  1293. {
  1294.   printf("Trianglen");
  1295.   printf(
  1296. "A Two-Dimensional Quality Mesh Generator and Delaunay Triangulator.n");
  1297.   printf("Version 1.6nn");
  1298.   printf(
  1299. "Copyright 1993, 1995, 1997, 1998, 2002, 2005 Jonathan Richard Shewchukn");
  1300.   printf("2360 Woolsey #H / Berkeley, California 94705-1927n");
  1301.   printf("Bugs/comments to jrs@cs.berkeley.edun");
  1302.   printf(
  1303. "Created as part of the Quake project (tools for earthquake simulation).n");
  1304.   printf(
  1305. "Supported in part by NSF Grant CMS-9318163 and an NSERC 1967 Scholarship.n");
  1306.   printf("There is no warranty whatsoever.  Use at your own risk.n");
  1307. #ifdef SINGLE
  1308.   printf("This executable is compiled for single precision arithmetic.nnn");
  1309. #else /* not SINGLE */
  1310.   printf("This executable is compiled for double precision arithmetic.nnn");
  1311. #endif /* not SINGLE */
  1312.   printf(
  1313. "Triangle generates exact Delaunay triangulations, constrained Delaunayn");
  1314.   printf(
  1315. "triangulations, conforming Delaunay triangulations, Voronoi diagrams, andn");
  1316.   printf(
  1317. "high-quality triangular meshes.  The latter can be generated with no smalln"
  1318. );
  1319.   printf(
  1320. "or large angles, and are thus suitable for finite element analysis.  If non"
  1321. );
  1322.   printf(
  1323. "command line switch is specified, your .node input file is read, and then");
  1324.   printf(
  1325. "Delaunay triangulation is returned in .node and .ele output files.  Then");
  1326.   printf("command syntax is:nn");
  1327.   printf("triangle [-prq__a__uAcDjevngBPNEIOXzo_YS__iFlsCQVh] input_filenn");
  1328.   printf(
  1329. "Underscores indicate that numbers may optionally follow certain switches.n");
  1330.   printf(
  1331. "Do not leave any space between a switch and its numeric parameter.n");
  1332.   printf(
  1333. "input_file must be a file with extension .node, or extension .poly if then");
  1334.   printf(
  1335. "-p switch is used.  If -r is used, you must supply .node and .ele files,n");
  1336.   printf(
  1337. "and possibly a .poly file and an .area file as well.  The formats of thesen"
  1338. );
  1339.   printf("files are described below.nn");
  1340.   printf("Command Line Switches:nn");
  1341.   printf(
  1342. "    -p  Reads a Planar Straight Line Graph (.poly file), which can specifyn"
  1343. );
  1344.   printf(
  1345. "        vertices, segments, holes, regional attributes, and regional arean");
  1346.   printf(
  1347. "        constraints.  Generates a constrained Delaunay triangulation (CDT)n"
  1348. );
  1349.   printf(
  1350. "        fitting the input; or, if -s, -q, -a, or -u is used, a conformingn");
  1351.   printf(
  1352. "        constrained Delaunay triangulation (CCDT).  If you want a trulyn");
  1353.   printf(
  1354. "        Delaunay (not just constrained Delaunay) triangulation, use -D asn");
  1355.   printf(
  1356. "        well.  When -p is not used, Triangle reads a .node file by default.n"
  1357. );
  1358.   printf(
  1359. "    -r  Refines a previously generated mesh.  The mesh is read from a .noden"
  1360. );
  1361.   printf(
  1362. "        file and an .ele file.  If -p is also used, a .poly file is readn");
  1363.   printf(
  1364. "        and used to constrain segments in the mesh.  If -a is also usedn");
  1365.   printf(
  1366. "        (with no number following), an .area file is read and used ton");
  1367.   printf(
  1368. "        impose area constraints on the mesh.  Further details on refinementn"
  1369. );
  1370.   printf("        appear below.n");
  1371.   printf(
  1372. "    -q  Quality mesh generation by Delaunay refinement (a hybrid of Pauln");
  1373.   printf(
  1374. "        Chew's and Jim Ruppert's algorithms).  Adds vertices to the mesh ton"
  1375. );
  1376.   printf(
  1377. "        ensure that all angles are between 20 and 140 degrees.  Ann");
  1378.   printf(
  1379. "        alternative bound on the minimum angle, replacing 20 degrees, mayn");
  1380.   printf(
  1381. "        be specified after the `q'.  The specified angle may include an");
  1382.   printf(
  1383. "        decimal point, but not exponential notation.  Note that a bound ofn"
  1384. );
  1385.   printf(
  1386. "        theta degrees on the smallest angle also implies a bound ofn");
  1387.   printf(
  1388. "        (180 - 2 theta) on the largest angle.  If the minimum angle is 28.6n"
  1389. );
  1390.   printf(
  1391. "        degrees or smaller, Triangle is mathematically guaranteed ton");
  1392.   printf(
  1393. "        terminate (assuming infinite precision arithmetic--Triangle mayn");
  1394.   printf(
  1395. "        fail to terminate if you run out of precision).  In practice,n");
  1396.   printf(
  1397. "        Triangle often succeeds for minimum angles up to 34 degrees.  Forn");
  1398.   printf(
  1399. "        some meshes, however, you might need to reduce the minimum angle ton"
  1400. );
  1401.   printf(
  1402. "        avoid problems associated with insufficient floating-pointn");
  1403.   printf("        precision.n");
  1404.   printf(
  1405. "    -a  Imposes a maximum triangle area.  If a number follows the `a', non");
  1406.   printf(
  1407. "        triangle is generated whose area is larger than that number.  If non"
  1408. );
  1409.   printf(
  1410. "        number is specified, an .area file (if -r is used) or .poly filen");
  1411.   printf(
  1412. "        (if -r is not used) specifies a set of maximum area constraints.n");
  1413.   printf(
  1414. "        An .area file contains a separate area constraint for eachn");
  1415.   printf(
  1416. "        triangle, and is useful for refining a finite element mesh based onn"
  1417. );
  1418.   printf(
  1419. "        a posteriori error estimates.  A .poly file can optionally containn"
  1420. );
  1421.   printf(
  1422. "        an area constraint for each segment-bounded region, therebyn");
  1423.   printf(
  1424. "        controlling triangle densities in a first triangulation of a PSLG.n"
  1425. );
  1426.   printf(
  1427. "        You can impose both a fixed area constraint and a varying arean");
  1428.   printf(
  1429. "        constraint by invoking the -a switch twice, once with and oncen");
  1430.   printf(
  1431. "        without a number following.  Each area specified may include an");
  1432.   printf("        decimal point.n");
  1433.   printf(
  1434. "    -u  Imposes a user-defined constraint on triangle size.  There are twon"
  1435. );
  1436.   printf(
  1437. "        ways to use this feature.  One is to edit the triunsuitable()n");
  1438.   printf(
  1439. "        procedure in triangle.c to encode any constraint you like, thenn");
  1440.   printf(
  1441. "        recompile Triangle.  The other is to compile triangle.c with then");
  1442.   printf(
  1443. "        EXTERNAL_TEST symbol set (compiler switch -DEXTERNAL_TEST), thenn");
  1444.   printf(
  1445. "        link Triangle with a separate object file that implementsn");
  1446.   printf(
  1447. "        triunsuitable().  In either case, the -u switch causes the user-n");
  1448.   printf("        defined test to be applied to every triangle.n");
  1449.   printf(
  1450. "    -A  Assigns an additional floating-point attribute to each trianglen");
  1451.   printf(
  1452. "        that identifies what segment-bounded region each triangle belongsn");
  1453.   printf(
  1454. "        to.  Attributes are assigned to regions by the .poly file.  If an");
  1455.   printf(
  1456. "        region is not explicitly marked by the .poly file, triangles inn");
  1457.   printf(
  1458. "        that region are assigned an attribute of zero.  The -A switch hasn");
  1459.   printf(
  1460. "        an effect only when the -p switch is used and the -r switch is not.n"
  1461. );
  1462.   printf(
  1463. "    -c  Creates segments on the convex hull of the triangulation.  If youn");
  1464.   printf(
  1465. "        are triangulating a vertex set, this switch causes a .poly file ton"
  1466. );
  1467.   printf(
  1468. "        be written, containing all edges of the convex hull.  If you aren");
  1469.   printf(
  1470. "        triangulating a PSLG, this switch specifies that the whole convexn");
  1471.   printf(
  1472. "        hull of the PSLG should be triangulated, regardless of whatn");
  1473.   printf(
  1474. "        segments the PSLG has.  If you do not use this switch whenn");
  1475.   printf(
  1476. "        triangulating a PSLG, Triangle assumes that you have identified then"
  1477. );
  1478.   printf(
  1479. "        region to be triangulated by surrounding it with segments of then");
  1480.   printf(
  1481. "        input PSLG.  Beware:  if you are not careful, this switch can causen"
  1482. );
  1483.   printf(
  1484. "        the introduction of an extremely thin angle between a PSLG segmentn"
  1485. );
  1486.   printf(
  1487. "        and a convex hull segment, which can cause overrefinement (andn");
  1488.   printf(
  1489. "        possibly failure if Triangle runs out of precision).  If you aren");
  1490.   printf(
  1491. "        refining a mesh, the -c switch works differently:  it causes an");
  1492.   printf(
  1493. "        .poly file to be written containing the boundary edges of the meshn"
  1494. );
  1495.   printf("        (useful if no .poly file was read).n");
  1496.   printf(
  1497. "    -D  Conforming Delaunay triangulation:  use this switch if you want ton"
  1498. );
  1499.   printf(
  1500. "        ensure that all the triangles in the mesh are Delaunay, and notn");
  1501.   printf(
  1502. "        merely constrained Delaunay; or if you want to ensure that all then"
  1503. );
  1504.   printf(
  1505. "        Voronoi vertices lie within the triangulation.  (Some finite volumen"
  1506. );
  1507.   printf(
  1508. "        methods have this requirement.)  This switch invokes Ruppert'sn");
  1509.   printf(
  1510. "        original algorithm, which splits every subsegment whose diametraln");
  1511.   printf(
  1512. "        circle is encroached.  It usually increases the number of verticesn"
  1513. );
  1514.   printf("        and triangles.n");
  1515.   printf(
  1516. "    -j  Jettisons vertices that are not part of the final triangulationn");
  1517.   printf(
  1518. "        from the output .node file.  By default, Triangle copies alln");
  1519.   printf(
  1520. "        vertices in the input .node file to the output .node file, in then");
  1521.   printf(
  1522. "        same order, so their indices do not change.  The -j switch preventsn"
  1523. );
  1524.   printf(
  1525. "        duplicated input vertices, or vertices `eaten' by holes, fromn");
  1526.   printf(
  1527. "        appearing in the output .node file.  Thus, if two input verticesn");
  1528.   printf(
  1529. "        have exactly the same coordinates, only the first appears in then");
  1530.   printf(
  1531. "        output.  If any vertices are jettisoned, the vertex numbering inn");
  1532.   printf(
  1533. "        the output .node file differs from that of the input .node file.n");
  1534.   printf(
  1535. "    -e  Outputs (to an .edge file) a list of edges of the triangulation.n");
  1536.   printf(
  1537. "    -v  Outputs the Voronoi diagram associated with the triangulation.n");
  1538.   printf(
  1539. "        Does not attempt to detect degeneracies, so some Voronoi verticesn");
  1540.   printf(
  1541. "        may be duplicated.  See the discussion of Voronoi diagrams below.n");
  1542.   printf(
  1543. "    -n  Outputs (to a .neigh file) a list of triangles neighboring eachn");
  1544.   printf("        triangle.n");
  1545.   printf(
  1546. "    -g  Outputs the mesh to an Object File Format (.off) file, suitable forn"
  1547. );
  1548.   printf("        viewing with the Geometry Center's Geomview package.n");
  1549.   printf(
  1550. "    -B  No boundary markers in the output .node, .poly, and .edge outputn");
  1551.   printf(
  1552. "        files.  See the detailed discussion of boundary markers below.n");
  1553.   printf(
  1554. "    -P  No output .poly file.  Saves disk space, but you lose the abilityn");
  1555.   printf(
  1556. "        to maintain constraining segments on later refinements of the mesh.n"
  1557. );
  1558.   printf("    -N  No output .node file.n");
  1559.   printf("    -E  No output .ele file.n");
  1560.   printf(
  1561. "    -I  No iteration numbers.  Suppresses the output of .node and .polyn");
  1562.   printf(
  1563. "        files, so your input files won't be overwritten.  (If your input isn"
  1564. );
  1565.   printf(
  1566. "        a .poly file only, a .node file is written.)  Cannot be used withn");
  1567.   printf(
  1568. "        the -r switch, because that would overwrite your input .ele file.n");
  1569.   printf(
  1570. "        Shouldn't be used with the -q, -a, -u, or -s switch if you aren");
  1571.   printf(
  1572. "        using a .node file for input, because no .node file is written, son"
  1573. );
  1574.   printf("        there is no record of any added Steiner points.n");
  1575.   printf("    -O  No holes.  Ignores the holes in the .poly file.n");
  1576.   printf(
  1577. "    -X  No exact arithmetic.  Normally, Triangle uses exact floating-pointn"
  1578. );
  1579.   printf(
  1580. "        arithmetic for certain tests if it thinks the inexact tests are notn"
  1581. );
  1582.   printf(
  1583. "        accurate enough.  Exact arithmetic ensures the robustness of then");
  1584.   printf(
  1585. "        triangulation algorithms, despite floating-point roundoff error.n");
  1586.   printf(
  1587. "        Disabling exact arithmetic with the -X switch causes a smalln");
  1588.   printf(
  1589. "        improvement in speed and creates the possibility that Triangle willn"
  1590. );
  1591.   printf("        fail to produce a valid mesh.  Not recommended.n");
  1592.   printf(
  1593. "    -z  Numbers all items starting from zero (rather than one).  Note thatn"
  1594. );
  1595.   printf(
  1596. "        this switch is normally overridden by the value used to number then"
  1597. );
  1598.   printf(
  1599. "        first vertex of the input .node or .poly file.  However, thisn");
  1600.   printf(
  1601. "        switch is useful when calling Triangle from another program.n");
  1602.   printf(
  1603. "    -o2 Generates second-order subparametric elements with six nodes each.n"
  1604. );
  1605.   printf(
  1606. "    -Y  No new vertices on the boundary.  This switch is useful when then");
  1607.   printf(
  1608. "        mesh boundary must be preserved so that it conforms to somen");
  1609.   printf(
  1610. "        adjacent mesh.  Be forewarned that you will probably sacrifice muchn"
  1611. );
  1612.   printf(
  1613. "        of the quality of the mesh; Triangle will try, but the resultingn");
  1614.   printf(
  1615. "        mesh may contain poorly shaped triangles.  Works well if all then");
  1616.   printf(
  1617. "        boundary vertices are closely spaced.  Specify this switch twicen");
  1618.   printf(
  1619. "        (`-YY') to prevent all segment splitting, including internaln");
  1620.   printf("        boundaries.n");
  1621.   printf(
  1622. "    -S  Specifies the maximum number of Steiner points (vertices that aren");
  1623.   printf(
  1624. "        not in the input, but are added to meet the constraints on minimumn"
  1625. );
  1626.   printf(
  1627. "        angle and maximum area).  The default is to allow an unlimitedn");
  1628.   printf(
  1629. "        number.  If you specify this switch with no number after it,n");
  1630.   printf(
  1631. "        the limit is set to zero.  Triangle always adds vertices at segmentn"
  1632. );
  1633.   printf(
  1634. "        intersections, even if it needs to use more vertices than the limitn"
  1635. );
  1636.   printf(
  1637. "        you set.  When Triangle inserts segments by splitting (-s), itn");
  1638.   printf(
  1639. "        always adds enough vertices to ensure that all the segments of then"
  1640. );
  1641.   printf("        PLSG are recovered, ignoring the limit if necessary.n");
  1642.   printf(
  1643. "    -i  Uses an incremental rather than a divide-and-conquer algorithm ton");
  1644.   printf(
  1645. "        construct a Delaunay triangulation.  Try it if the divide-and-n");
  1646.   printf("        conquer algorithm fails.n");
  1647.   printf(
  1648. "    -F  Uses Steven Fortune's sweepline algorithm to construct a Delaunayn");
  1649.   printf(
  1650. "        triangulation.  Warning:  does not use exact arithmetic for alln");
  1651.   printf("        calculations.  An exact result is not guaranteed.n");
  1652.   printf(
  1653. "    -l  Uses only vertical cuts in the divide-and-conquer algorithm.  Byn");
  1654.   printf(
  1655. "        default, Triangle alternates between vertical and horizontal cuts,n"
  1656. );
  1657.   printf(
  1658. "        which usually improve the speed except with vertex sets that aren");
  1659.   printf(
  1660. "        small or short and wide.  This switch is primarily of theoreticaln");
  1661.   printf("        interest.n");
  1662.   printf(
  1663. "    -s  Specifies that segments should be forced into the triangulation byn"
  1664. );
  1665.   printf(
  1666. "        recursively splitting them at their midpoints, rather than byn");
  1667.   printf(
  1668. "        generating a constrained Delaunay triangulation.  Segment splittingn"
  1669. );
  1670.   printf(
  1671. "        is true to Ruppert's original algorithm, but can create needlesslyn"
  1672. );
  1673.   printf(
  1674. "        small triangles.  This switch is primarily of theoretical interest.n"
  1675. );
  1676.   printf(
  1677. "    -C  Check the consistency of the final mesh.  Uses exact arithmetic forn"
  1678. );
  1679.   printf(
  1680. "        checking, even if the -X switch is used.  Useful if you suspectn");
  1681.   printf("        Triangle is buggy.n");
  1682.   printf(
  1683. "    -Q  Quiet:  Suppresses all explanation of what Triangle is doing,n");
  1684.   printf("        unless an error occurs.n");
  1685.   printf(
  1686. "    -V  Verbose:  Gives detailed information about what Triangle is doing.n"
  1687. );
  1688.   printf(
  1689. "        Add more `V's for increasing amount of detail.  `-V' is mostn");
  1690.   printf(
  1691. "        useful; itgives information on algorithmic progress and much moren");
  1692.   printf(
  1693. "        detailed statistics.  `-VV' gives vertex-by-vertex details, andn");
  1694.   printf(
  1695. "        prints so much that Triangle runs much more slowly.  `-VVVV' givesn"
  1696. );
  1697.   printf("        information only a debugger could love.n");
  1698.   printf("    -h  Help:  Displays these instructions.n");
  1699.   printf("n");
  1700.   printf("Definitions:n");
  1701.   printf("n");
  1702.   printf(
  1703. "  A Delaunay triangulation of a vertex set is a triangulation whosen");
  1704.   printf(
  1705. "  vertices are the vertex set, that covers the convex hull of the vertexn");
  1706.   printf(
  1707. "  set.  A Delaunay triangulation has the property that no vertex liesn");
  1708.   printf(
  1709. "  inside the circumscribing circle (circle that passes through all threen");
  1710.   printf("  vertices) of any triangle in the triangulation.nn");
  1711.   printf(
  1712. "  A Voronoi diagram of a vertex set is a subdivision of the plane inton");
  1713.   printf(
  1714. "  polygonal cells (some of which may be unbounded, meaning infinitelyn");
  1715.   printf(
  1716. "  large), where each cell is the set of points in the plane that are closern"
  1717. );
  1718.   printf(
  1719. "  to some input vertex than to any other input vertex.  The Voronoi diagramn"
  1720. );
  1721.   printf("  is a geometric dual of the Delaunay triangulation.nn");
  1722.   printf(
  1723. "  A Planar Straight Line Graph (PSLG) is a set of vertices and segments.n");
  1724.   printf(
  1725. "  Segments are simply edges, whose endpoints are all vertices in the PSLG.n"
  1726. );
  1727.   printf(
  1728. "  Segments may intersect each other only at their endpoints.  The filen");
  1729.   printf("  format for PSLGs (.poly files) is described below.nn");
  1730.   printf(
  1731. "  A constrained Delaunay triangulation (CDT) of a PSLG is similar to an");
  1732.   printf(
  1733. "  Delaunay triangulation, but each PSLG segment is present as a single edgen"
  1734. );
  1735.   printf(
  1736. "  of the CDT.  (A constrained Delaunay triangulation is not truly an");
  1737.   printf(
  1738. "  Delaunay triangulation, because some of its triangles might not ben");
  1739.   printf(
  1740. "  Delaunay.)  By definition, a CDT does not have any vertices other thann");
  1741.   printf(
  1742. "  those specified in the input PSLG.  Depending on context, a CDT mightn");
  1743.   printf(
  1744. "  cover the convex hull of the PSLG, or it might cover only a segment-n");
  1745.   printf("  bounded region (e.g. a polygon).nn");
  1746.   printf(
  1747. "  A conforming Delaunay triangulation of a PSLG is a triangulation in whichn"
  1748. );
  1749.   printf(
  1750. "  each triangle is truly Delaunay, and each PSLG segment is represented byn"
  1751. );
  1752.   printf(
  1753. "  a linear contiguous sequence of edges of the triangulation.  New verticesn"
  1754. );
  1755.   printf(
  1756. "  (not part of the PSLG) may appear, and each input segment may have beenn");
  1757.   printf(
  1758. "  subdivided into shorter edges (subsegments) by these additional vertices.n"
  1759. );
  1760.   printf(
  1761. "  The new vertices are frequently necessary to maintain the Delaunayn");
  1762.   printf("  property while ensuring that every segment is represented.nn");
  1763.   printf(
  1764. "  A conforming constrained Delaunay triangulation (CCDT) of a PSLG is an");
  1765.   printf(
  1766. "  triangulation of a PSLG whose triangles are constrained Delaunay.  Newn");
  1767.   printf("  vertices may appear, and input segments may be subdivided inton");
  1768.   printf(
  1769. "  subsegments, but not to guarantee that segments are respected; rather, ton"
  1770. );
  1771.   printf(
  1772. "  improve the quality of the triangles.  The high-quality meshes producedn");
  1773.   printf(
  1774. "  by the -q switch are usually CCDTs, but can be made conforming Delaunayn");
  1775.   printf("  with the -D switch.nn");
  1776.   printf("File Formats:nn");
  1777.   printf(
  1778. "  All files may contain comments prefixed by the character '#'.  Vertices,n"
  1779. );
  1780.   printf(
  1781. "  triangles, edges, holes, and maximum area constraints must be numberedn");
  1782.   printf(
  1783. "  consecutively, starting from either 1 or 0.  Whichever you choose, alln");
  1784.   printf(
  1785. "  input files must be consistent; if the vertices are numbered from 1, son");
  1786.   printf(
  1787. "  must be all other objects.  Triangle automatically detects your choicen");
  1788.   printf(
  1789. "  while reading the .node (or .poly) file.  (When calling Triangle fromn");
  1790.   printf(
  1791. "  another program, use the -z switch if you wish to number objects fromn");
  1792.   printf("  zero.)  Examples of these file formats are given below.nn");
  1793.   printf("  .node files:n");
  1794.   printf(
  1795. "    First line:  <# of vertices> <dimension (must be 2)> <# of attributes>n"
  1796. );
  1797.   printf(
  1798. "                                           <# of boundary markers (0 or 1)>n"
  1799. );
  1800.   printf(
  1801. "    Remaining lines:  <vertex #> <x> <y> [attributes] [boundary marker]n");
  1802.   printf("n");
  1803.   printf(
  1804. "    The attributes, which are typically floating-point values of physicaln");
  1805.   printf(
  1806. "    quantities (such as mass or conductivity) associated with the nodes ofn"
  1807. );
  1808.   printf(
  1809. "    a finite element mesh, are copied unchanged to the output mesh.  If -q,n"
  1810. );
  1811.   printf(
  1812. "    -a, -u, -D, or -s is selected, each new Steiner point added to the meshn"
  1813. );
  1814.   printf("    has attributes assigned to it by linear interpolation.nn");
  1815.   printf(
  1816. "    If the fourth entry of the first line is `1', the last column of then");
  1817.   printf(
  1818. "    remainder of the file is assumed to contain boundary markers.  Boundaryn"
  1819. );
  1820.   printf(
  1821. "    markers are used to identify boundary vertices and vertices resting onn"
  1822. );
  1823.   printf(
  1824. "    PSLG segments; a complete description appears in a section below.  Then"
  1825. );
  1826.   printf(
  1827. "    .node file produced by Triangle contains boundary markers in the lastn");
  1828.   printf("    column unless they are suppressed by the -B switch.nn");
  1829.   printf("  .ele files:n");
  1830.   printf(
  1831. "    First line:  <# of triangles> <nodes per triangle> <# of attributes>n");
  1832.   printf(
  1833. "    Remaining lines:  <triangle #> <node> <node> <node> ... [attributes]n");
  1834.   printf("n");
  1835.   printf(
  1836. "    Nodes are indices into the corresponding .node file.  The first threen");
  1837.   printf(
  1838. "    nodes are the corner vertices, and are listed in counterclockwise ordern"
  1839. );
  1840.   printf(
  1841. "    around each triangle.  (The remaining nodes, if any, depend on the typen"
  1842. );
  1843.   printf("    of finite element used.)nn");
  1844.   printf(
  1845. "    The attributes are just like those of .node files.  Because there is non"
  1846. );
  1847.   printf(
  1848. "    simple mapping from input to output triangles, Triangle attempts ton");
  1849.   printf(
  1850. "    interpolate attributes, and may cause a lot of diffusion of attributesn"
  1851. );
  1852.   printf(
  1853. "    among nearby triangles as the triangulation is refined.  Attributes don"
  1854. );
  1855.   printf("    not diffuse across segments, so attributes used to identifyn");
  1856.   printf("    segment-bounded regions remain intact.nn");
  1857.   printf(
  1858. "    In .ele files produced by Triangle, each triangular element has threen");
  1859.   printf(
  1860. "    nodes (vertices) unless the -o2 switch is used, in which casen");
  1861.   printf(
  1862. "    subparametric quadratic elements with six nodes each are generated.n");
  1863.   printf(
  1864. "    The first three nodes are the corners in counterclockwise order, andn");
  1865.   printf(
  1866. "    the fourth, fifth, and sixth nodes lie on the midpoints of the edgesn");
  1867.   printf(
  1868. "    opposite the first, second, and third vertices, respectively.n");
  1869.   printf("n");
  1870.   printf("  .poly files:n");
  1871.   printf(
  1872. "    First line:  <# of vertices> <dimension (must be 2)> <# of attributes>n"
  1873. );
  1874.   printf(
  1875. "                                           <# of boundary markers (0 or 1)>n"
  1876. );
  1877.   printf(
  1878. "    Following lines:  <vertex #> <x> <y> [attributes] [boundary marker]n");
  1879.   printf("    One line:  <# of segments> <# of boundary markers (0 or 1)>n");
  1880.   printf(
  1881. "    Following lines:  <segment #> <endpoint> <endpoint> [boundary marker]n");
  1882.   printf("    One line:  <# of holes>n");
  1883.   printf("    Following lines:  <hole #> <x> <y>n");
  1884.   printf(
  1885. "    Optional line:  <# of regional attributes and/or area constraints>n");
  1886.   printf(
  1887. "    Optional following lines:  <region #> <x> <y> <attribute> <max area>n");
  1888.   printf("n");
  1889.   printf(
  1890. "    A .poly file represents a PSLG, as well as some additional information.n"
  1891. );
  1892.   printf(
  1893. "    The first section lists all the vertices, and is identical to then");
  1894.   printf(
  1895. "    format of .node files.  <# of vertices> may be set to zero to indicaten"
  1896. );
  1897.   printf(
  1898. "    that the vertices are listed in a separate .node file; .poly filesn");
  1899.   printf(
  1900. "    produced by Triangle always have this format.  A vertex set representedn"
  1901. );
  1902.   printf(
  1903. "    this way has the advantage that it may easily be triangulated with orn");
  1904.   printf(
  1905. "    without segments (depending on whether the -p switch is invoked).n");
  1906.   printf("n");
  1907.   printf(
  1908. "    The second section lists the segments.  Segments are edges whosen");
  1909.   printf(
  1910. "    presence in the triangulation is enforced.  (Depending on the choice ofn"
  1911. );
  1912.   printf(
  1913. "    switches, segment might be subdivided into smaller edges).  Eachn");
  1914.   printf(
  1915. "    segment is specified by listing the indices of its two endpoints.  Thisn"
  1916. );
  1917.   printf(
  1918. "    means that you must include its endpoints in the vertex list.  Eachn");
  1919.   printf("    segment, like each point, may have a boundary marker.nn");
  1920.   printf(
  1921. "    If -q, -a, -u, and -s are not selected, Triangle produces a constrainedn"
  1922. );
  1923.   printf(
  1924. "    Delaunay triangulation (CDT), in which each segment appears as a singlen"
  1925. );
  1926.   printf(
  1927. "    edge in the triangulation.  If -q, -a, -u, or -s is selected, Trianglen"
  1928. );
  1929.   printf(
  1930. "    produces a conforming constrained Delaunay triangulation (CCDT), inn");
  1931.   printf(
  1932. "    which segments may be subdivided into smaller edges.  If -D isn");
  1933.   printf(
  1934. "    selected, Triangle produces a conforming Delaunay triangulation, son");
  1935.   printf(
  1936. "    that every triangle is Delaunay, and not just constrained Delaunay.n");
  1937.   printf("n");
  1938.   printf(
  1939. "    The third section lists holes (and concavities, if -c is selected) inn");
  1940.   printf(
  1941. "    the triangulation.  Holes are specified by identifying a point insiden");
  1942.   printf(
  1943. "    each hole.  After the triangulation is formed, Triangle creates holesn");
  1944.   printf(
  1945. "    by eating triangles, spreading out from each hole point until itsn");
  1946.   printf(
  1947. "    progress is blocked by segments in the PSLG.  You must be careful ton");
  1948.   printf(
  1949. "    enclose each hole in segments, or your whole triangulation might ben");
  1950.   printf(
  1951. "    eaten away.  If the two triangles abutting a segment are eaten, then");
  1952.   printf(
  1953. "    segment itself is also eaten.  Do not place a hole directly on an");
  1954.   printf("    segment; if you do, Triangle chooses one side of the segmentn");
  1955.   printf("    arbitrarily.nn");
  1956.   printf(
  1957. "    The optional fourth section lists regional attributes (to be assignedn");
  1958.   printf(
  1959. "    to all triangles in a region) and regional constraints on the maximumn");
  1960.   printf(
  1961. "    triangle area.  Triangle reads this section only if the -A switch isn");
  1962.   printf(
  1963. "    used or the -a switch is used without a number following it, and the -rn"
  1964. );
  1965.   printf(
  1966. "    switch is not used.  Regional attributes and area constraints aren");
  1967.   printf(
  1968. "    propagated in the same manner as holes:  you specify a point for eachn");
  1969.   printf(
  1970. "    attribute and/or constraint, and the attribute and/or constraintn");
  1971.   printf(
  1972. "    affects the whole region (bounded by segments) containing the point.n");
  1973.   printf(
  1974. "    If two values are written on a line after the x and y coordinate, then");
  1975.   printf(
  1976. "    first such value is assumed to be a regional attribute (but is onlyn");
  1977.   printf(
  1978. "    applied if the -A switch is selected), and the second value is assumedn"
  1979. );
  1980.   printf(
  1981. "    to be a regional area constraint (but is only applied if the -a switchn"
  1982. );
  1983.   printf(
  1984. "    is selected).  You may specify just one value after the coordinates,n");
  1985.   printf(
  1986. "    which can serve as both an attribute and an area constraint, dependingn"
  1987. );
  1988.   printf(
  1989. "    on the choice of switches.  If you are using the -A and -a switchesn");
  1990.   printf(
  1991. "    simultaneously and wish to assign an attribute to some region withoutn");
  1992.   printf("    imposing an area constraint, use a negative maximum area.nn");
  1993.   printf(
  1994. "    When a triangulation is created from a .poly file, you must eithern");
  1995.   printf(
  1996. "    enclose the entire region to be triangulated in PSLG segments, orn");
  1997.   printf(
  1998. "    use the -c switch, which automatically creates extra segments thatn");
  1999.   printf(
  2000. "    enclose the convex hull of the PSLG.  If you do not use the -c switch,n"
  2001. );
  2002.   printf(
  2003. "    Triangle eats all triangles that are not enclosed by segments; if youn");
  2004.   printf(
  2005. "    are not careful, your whole triangulation may be eaten away.  If you don"
  2006. );
  2007.   printf(
  2008. "    use the -c switch, you can still produce concavities by the appropriaten"
  2009. );
  2010.   printf(
  2011. "    placement of holes just inside the boundary of the convex hull.n");
  2012.   printf("n");
  2013.   printf(
  2014. "    An ideal PSLG has no intersecting segments, nor any vertices that lien");
  2015.   printf(
  2016. "    upon segments (except, of course, the endpoints of each segment).  Youn"
  2017. );
  2018.   printf(
  2019. "    aren't required to make your .poly files ideal, but you should be awaren"
  2020. );
  2021.   printf(
  2022. "    of what can go wrong.  Segment intersections are relatively safe--n");
  2023.   printf(
  2024. "    Triangle calculates the intersection points for you and adds them ton");
  2025.   printf(
  2026. "    the triangulation--as long as your machine's floating-point precisionn");
  2027.   printf(
  2028. "    doesn't become a problem.  You are tempting the fates if you have threen"
  2029. );
  2030.   printf(
  2031. "    segments that cross at the same location, and expect Triangle to figuren"
  2032. );
  2033.   printf(
  2034. "    out where the intersection point is.  Thanks to floating-point roundoffn"
  2035. );
  2036.   printf(
  2037. "    error, Triangle will probably decide that the three segments intersectn"
  2038. );
  2039.   printf(
  2040. "    at three different points, and you will find a minuscule triangle inn");
  2041.   printf(
  2042. "    your output--unless Triangle tries to refine the tiny triangle, usesn");
  2043.   printf(
  2044. "    up the last bit of machine precision, and fails to terminate at all.n");
  2045.   printf(
  2046. "    You're better off putting the intersection point in the input files,n");
  2047.   printf(
  2048. "    and manually breaking up each segment into two.  Similarly, if youn");
  2049.   printf(
  2050. "    place a vertex at the middle of a segment, and hope that Triangle willn"
  2051. );
  2052.   printf(
  2053. "    break up the segment at that vertex, you might get lucky.  On the othern"
  2054. );
  2055.   printf(
  2056. "    hand, Triangle might decide that the vertex doesn't lie precisely onn");
  2057.   printf(
  2058. "    the segment, and you'll have a needle-sharp triangle in your output--orn"
  2059. );
  2060.   printf("    a lot of tiny triangles if you're generating a quality mesh.n");
  2061.   printf("n");
  2062.   printf(
  2063. "    When Triangle reads a .poly file, it also writes a .poly file, whichn");
  2064.   printf(
  2065. "    includes all the subsegments--the edges that are parts of inputn");
  2066.   printf(
  2067. "    segments.  If the -c switch is used, the output .poly file alson");
  2068.   printf(
  2069. "    includes all of the edges on the convex hull.  Hence, the output .polyn"
  2070. );
  2071.   printf(
  2072. "    file is useful for finding edges associated with input segments and forn"
  2073. );
  2074.   printf(
  2075. "    setting boundary conditions in finite element simulations.  Moreover,n");
  2076.   printf(
  2077. "    you will need the output .poly file if you plan to refine the outputn");
  2078.   printf(
  2079. "    mesh, and don't want segments to be missing in later triangulations.n");
  2080.   printf("n");
  2081.   printf("  .area files:n");
  2082.   printf("    First line:  <# of triangles>n");
  2083.   printf("    Following lines:  <triangle #> <maximum area>n");
  2084.   printf("n");
  2085.   printf(
  2086. "    An .area file associates with each triangle a maximum area that is usedn"
  2087. );
  2088.   printf(
  2089. "    for mesh refinement.  As with other file formats, every triangle mustn");
  2090.   printf(
  2091. "    be represented, and the triangles must be numbered consecutively.  An");
  2092.   printf(
  2093. "    triangle may be left unconstrained by assigning it a negative maximumn");
  2094.   printf("    area.nn");
  2095.   printf("  .edge files:n");
  2096.   printf("    First line:  <# of edges> <# of boundary markers (0 or 1)>n");
  2097.   printf(
  2098. "    Following lines:  <edge #> <endpoint> <endpoint> [boundary marker]n");
  2099.   printf("n");
  2100.   printf(
  2101. "    Endpoints are indices into the corresponding .node file.  Triangle cann"
  2102. );
  2103.   printf(
  2104. "    produce .edge files (use the -e switch), but cannot read them.  Then");
  2105.   printf(
  2106. "    optional column of boundary markers is suppressed by the -B switch.n");
  2107.   printf("n");
  2108.   printf(
  2109. "    In Voronoi diagrams, one also finds a special kind of edge that is ann");
  2110.   printf(
  2111. "    infinite ray with only one endpoint.  For these edges, a differentn");
  2112.   printf("    format is used:nn");
  2113.   printf("        <edge #> <endpoint> -1 <direction x> <direction y>nn");
  2114.   printf(
  2115. "    The `direction' is a floating-point vector that indicates the directionn"
  2116. );
  2117.   printf("    of the infinite ray.nn");
  2118.   printf("  .neigh files:n");
  2119.   printf(
  2120. "    First line:  <# of triangles> <# of neighbors per triangle (always 3)>n"
  2121. );
  2122.   printf(
  2123. "    Following lines:  <triangle #> <neighbor> <neighbor> <neighbor>n");
  2124.   printf("n");
  2125.   printf(
  2126. "    Neighbors are indices into the corresponding .ele file.  An index of -1n"
  2127. );
  2128.   printf(
  2129. "    indicates no neighbor (because the triangle is on an exteriorn");
  2130.   printf(
  2131. "    boundary).  The first neighbor of triangle i is opposite the firstn");
  2132.   printf("    corner of triangle i, and so on.nn");
  2133.   printf(
  2134. "    Triangle can produce .neigh files (use the -n switch), but cannot readn"
  2135. );
  2136.   printf("    them.nn");
  2137.   printf("Boundary Markers:nn");
  2138.   printf(
  2139. "  Boundary markers are tags used mainly to identify which output verticesn");
  2140.   printf(
  2141. "  and edges are associated with which PSLG segment, and to identify whichn");
  2142.   printf(
  2143. "  vertices and edges occur on a boundary of the triangulation.  A commonn");
  2144.   printf(
  2145. "  use is to determine where boundary conditions should be applied to an");
  2146.   printf(
  2147. "  finite element mesh.  You can prevent boundary markers from being writtenn"
  2148. );
  2149.   printf("  into files produced by Triangle by using the -B switch.nn");
  2150.   printf(
  2151. "  The boundary marker associated with each segment in an output .poly filen"
  2152. );
  2153.   printf("  and each edge in an output .edge file is chosen as follows:n");
  2154.   printf(
  2155. "    - If an output edge is part or all of a PSLG segment with a nonzeron");
  2156.   printf(
  2157. "      boundary marker, then the edge is assigned the same marker.n");
  2158.   printf(
  2159. "    - Otherwise, if the edge lies on a boundary of the triangulationn");
  2160.   printf(
  2161. "      (even the boundary of a hole), then the edge is assigned the markern");
  2162.   printf("      one (1).n");
  2163.   printf("    - Otherwise, the edge is assigned the marker zero (0).n");
  2164.   printf(
  2165. "  The boundary marker associated with each vertex in an output .node filen");
  2166.   printf("  is chosen as follows:n");
  2167.   printf(
  2168. "    - If a vertex is assigned a nonzero boundary marker in the input file,n"
  2169. );
  2170.   printf(
  2171. "      then it is assigned the same marker in the output .node file.n");
  2172.   printf(
  2173. "    - Otherwise, if the vertex lies on a PSLG segment (even if it is ann");
  2174.   printf(
  2175. "      endpoint of the segment) with a nonzero boundary marker, then then");
  2176.   printf(
  2177. "      vertex is assigned the same marker.  If the vertex lies on severaln");
  2178.   printf("      such segments, one of the markers is chosen arbitrarily.n");
  2179.   printf(
  2180. "    - Otherwise, if the vertex occurs on a boundary of the triangulation,n");
  2181.   printf("      then the vertex is assigned the marker one (1).n");
  2182.   printf("    - Otherwise, the vertex is assigned the marker zero (0).n");
  2183.   printf("n");
  2184.   printf(
  2185. "  If you want Triangle to determine for you which vertices and edges are onn"
  2186. );
  2187.   printf(
  2188. "  the boundary, assign them the boundary marker zero (or use no markers atn"
  2189. );
  2190.   printf(
  2191. "  all) in your input files.  In the output files, all boundary vertices,n");
  2192.   printf("  edges, and segments will be assigned the value one.nn");
  2193.   printf("Triangulation Iteration Numbers:nn");
  2194.   printf(
  2195. "  Because Triangle can read and refine its own triangulations, inputn");
  2196.   printf(
  2197. "  and output files have iteration numbers.  For instance, Triangle mightn");
  2198.   printf(
  2199. "  read the files mesh.3.node, mesh.3.ele, and mesh.3.poly, refine then");
  2200.   printf(
  2201. "  triangulation, and output the files mesh.4.node, mesh.4.ele, andn");
  2202.   printf("  mesh.4.poly.  Files with no iteration number are treated as ifn");
  2203.   printf(
  2204. "  their iteration number is zero; hence, Triangle might read the filen");
  2205.   printf(
  2206. "  points.node, triangulate it, and produce the files points.1.node andn");
  2207.   printf("  points.1.ele.nn");
  2208.   printf(
  2209. "  Iteration numbers allow you to create a sequence of successively finern");
  2210.   printf(
  2211. "  meshes suitable for multigrid methods.  They also allow you to produce an"
  2212. );
  2213.   printf(
  2214. "  sequence of meshes using error estimate-driven mesh refinement.n");
  2215.   printf("n");
  2216.   printf(
  2217. "  If you're not using refinement or quality meshing, and you don't liken");
  2218.   printf(
  2219. "  iteration numbers, use the -I switch to disable them.  This switch alson");
  2220.   printf(
  2221. "  disables output of .node and .poly files to prevent your input files fromn"
  2222. );
  2223.   printf(
  2224. "  being overwritten.  (If the input is a .poly file that contains its ownn");
  2225.   printf(
  2226. "  points, a .node file is written.  This can be quite convenient forn");
  2227.   printf("  computing CDTs or quality meshes.)nn");
  2228.   printf("Examples of How to Use Triangle:nn");
  2229.   printf(
  2230. "  `triangle dots' reads vertices from dots.node, and writes their Delaunayn"
  2231. );
  2232.   printf(
  2233. "  triangulation to dots.1.node and dots.1.ele.  (dots.1.node is identicaln");
  2234.   printf(
  2235. "  to dots.node.)  `triangle -I dots' writes the triangulation to dots.elen");
  2236.   printf(
  2237. "  instead.  (No additional .node file is needed, so none is written.)n");
  2238.   printf("n");
  2239.   printf(
  2240. "  `triangle -pe object.1' reads a PSLG from object.1.poly (and possiblyn");
  2241.   printf(
  2242. "  object.1.node, if the vertices are omitted from object.1.poly) and writesn"
  2243. );
  2244.   printf(
  2245. "  its constrained Delaunay triangulation to object.2.node and object.2.ele.n"
  2246. );
  2247.   printf(
  2248. "  The segments are copied to object.2.poly, and all edges are written ton");
  2249.   printf("  object.2.edge.nn");
  2250.   printf(
  2251. "  `triangle -pq31.5a.1 object' reads a PSLG from object.poly (and possiblyn"
  2252. );
  2253.   printf(
  2254. "  object.node), generates a mesh whose angles are all between 31.5 and 117n"
  2255. );
  2256.   printf(
  2257. "  degrees and whose triangles all have areas of 0.1 or less, and writes then"
  2258. );
  2259.   printf(
  2260. "  mesh to object.1.node and object.1.ele.  Each segment may be broken upn");
  2261.   printf("  into multiple subsegments; these are written to object.1.poly.n");
  2262.   printf("n");
  2263.   printf(
  2264. "  Here is a sample file `box.poly' describing a square with a square hole:n"
  2265. );
  2266.   printf("n");
  2267.   printf(
  2268. "    # A box with eight vertices in 2D, no attributes, one boundary marker.n"
  2269. );
  2270.   printf("    8 2 0 1n");
  2271.   printf("     # Outer box has these vertices:n");
  2272.   printf("     1   0 0   0n");
  2273.   printf("     2   0 3   0n");
  2274.   printf("     3   3 0   0n");
  2275.   printf("     4   3 3   33     # A special marker for this vertex.n");
  2276.   printf("     # Inner square has these vertices:n");
  2277.   printf("     5   1 1   0n");
  2278.   printf("     6   1 2   0n");
  2279.   printf("     7   2 1   0n");
  2280.   printf("     8   2 2   0n");
  2281.   printf("    # Five segments with boundary markers.n");
  2282.   printf("    5 1n");
  2283.   printf("     1   1 2   5      # Left side of outer box.n");
  2284.   printf("     # Square hole has these segments:n");
  2285.   printf("     2   5 7   0n");
  2286.   printf("     3   7 8   0n");
  2287.   printf("     4   8 6   10n");
  2288.   printf("     5   6 5   0n");
  2289.   printf("    # One hole in the middle of the inner square.n");
  2290.   printf("    1n");
  2291.   printf("     1   1.5 1.5n");
  2292.   printf("n");
  2293.   printf(
  2294. "  Note that some segments are missing from the outer square, so you mustn");
  2295.   printf(
  2296. "  use the `-c' switch.  After `triangle -pqc box.poly', here is the outputn"
  2297. );
  2298.   printf(
  2299. "  file `box.1.node', with twelve vertices.  The last four vertices weren");
  2300.   printf(
  2301. "  added to meet the angle constraint.  Vertices 1, 2, and 9 have markersn");
  2302.   printf(
  2303. "  from segment 1.  Vertices 6 and 8 have markers from segment 4.  All then");
  2304.   printf(
  2305. "  other vertices but 4 have been marked to indicate that they lie on an");
  2306.   printf("  boundary.nn");
  2307.   printf("    12  2  0  1n");
  2308.   printf("       1    0   0      5n");
  2309.   printf("       2    0   3      5n");
  2310.   printf("       3    3   0      1n");
  2311.   printf("       4    3   3     33n");
  2312.   printf("       5    1   1      1n");
  2313.   printf("       6    1   2     10n");
  2314.   printf("       7    2   1      1n");
  2315.   printf("       8    2   2     10n");
  2316.   printf("       9    0   1.5    5n");
  2317.   printf("      10    1.5   0    1n");
  2318.   printf("      11    3   1.5    1n");
  2319.   printf("      12    1.5   3    1n");
  2320.   printf("    # Generated by triangle -pqc box.polyn");
  2321.   printf("n");
  2322.   printf("  Here is the output file `box.1.ele', with twelve triangles.n");
  2323.   printf("n");
  2324.   printf("    12  3  0n");
  2325.   printf("       1     5   6   9n");
  2326.   printf("       2    10   3   7n");
  2327.   printf("       3     6   8  12n");
  2328.   printf("       4     9   1   5n");
  2329.   printf("       5     6   2   9n");
  2330.   printf("       6     7   3  11n");
  2331.   printf("       7    11   4   8n");
  2332.   printf("       8     7   5  10n");
  2333.   printf("       9    12   2   6n");
  2334.   printf("      10     8   7  11n");
  2335.   printf("      11     5   1  10n");
  2336.   printf("      12     8   4  12n");
  2337.   printf("    # Generated by triangle -pqc box.polynn");
  2338.   printf(
  2339. "  Here is the output file `box.1.poly'.  Note that segments have been addedn"
  2340. );
  2341.   printf(
  2342. "  to represent the convex hull, and some segments have been subdivided byn");
  2343.   printf(
  2344. "  newly added vertices.  Note also that <# of vertices> is set to zero ton");
  2345.   printf("  indicate that the vertices should be read from the .node file.n");
  2346.   printf("n");
  2347.   printf("    0  2  0  1n");
  2348.   printf("    12  1n");
  2349.   printf("       1     1   9     5n");
  2350.   printf("       2     5   7     1n");
  2351.   printf("       3     8   7     1n");
  2352.   printf("       4     6   8    10n");
  2353.   printf("       5     5   6     1n");
  2354.   printf("       6     3  10     1n");
  2355.   printf("       7     4  11     1n");
  2356.   printf("       8     2  12     1n");
  2357.   printf("       9     9   2     5n");
  2358.   printf("      10    10   1     1n");
  2359.   printf("      11    11   3     1n");
  2360.   printf("      12    12   4     1n");
  2361.   printf("    1n");
  2362.   printf("       1   1.5 1.5n");
  2363.   printf("    # Generated by triangle -pqc box.polyn");
  2364.   printf("n");
  2365.   printf("Refinement and Area Constraints:n");
  2366.   printf("n");
  2367.   printf(
  2368. "  The -r switch causes a mesh (.node and .ele files) to be read andn");
  2369.   printf(
  2370. "  refined.  If the -p switch is also used, a .poly file is read and used ton"
  2371. );
  2372.   printf(
  2373. "  specify edges that are constrained and cannot be eliminated (althoughn");
  2374.   printf(
  2375. "  they can be subdivided into smaller edges) by the refinement process.n");
  2376.   printf("n");
  2377.   printf(
  2378. "  When you refine a mesh, you generally want to impose tighter constraints.n"
  2379. );
  2380.   printf(
  2381. "  One way to accomplish this is to use -q with a larger angle, or -an");
  2382.   printf(
  2383. "  followed by a smaller area than you used to generate the mesh you aren");
  2384.   printf(
  2385. "  refining.  Another way to do this is to create an .area file, whichn");
  2386.   printf(
  2387. "  specifies a maximum area for each triangle, and use the -a switchn");
  2388.   printf(
  2389. "  (without a number following).  Each triangle's area constraint is appliedn"
  2390. );
  2391.   printf(
  2392. "  to that triangle.  Area constraints tend to diffuse as the mesh isn");
  2393.   printf(
  2394. "  refined, so if there are large variations in area constraint betweenn");
  2395.   printf(
  2396. "  adjacent triangles, you may not get the results you want.  In that case,n"
  2397. );
  2398.   printf(
  2399. "  consider instead using the -u switch and writing a C procedure thatn");
  2400.   printf("  determines which triangles are too large.nn");
  2401.   printf(
  2402. "  If you are refining a mesh composed of linear (three-node) elements, then"
  2403. );
  2404.   printf(
  2405. "  output mesh contains all the nodes present in the input mesh, in the samen"
  2406. );
  2407.   printf(
  2408. "  order, with new nodes added at the end of the .node file.  However, then");
  2409.   printf(
  2410. "  refinement is not hierarchical: there is no guarantee that each outputn");
  2411.   printf(
  2412. "  element is contained in a single input element.  Often, an output elementn"
  2413. );
  2414.   printf(
  2415. "  can overlap two or three input elements, and some input edges are notn");
  2416.   printf(
  2417. "  present in the output mesh.  Hence, a sequence of refined meshes forms an"
  2418. );
  2419.   printf(
  2420. "  hierarchy of nodes, but not a hierarchy of elements.  If you refine an");
  2421.   printf(
  2422. "  mesh of higher-order elements, the hierarchical property applies only ton"
  2423. );
  2424.   printf(
  2425. "  the nodes at the corners of an element; the midpoint nodes on each edgen");
  2426.   printf("  are discarded before the mesh is refined.nn");
  2427.   printf(
  2428. "  Maximum area constraints in .poly files operate differently from those inn"
  2429. );
  2430.   printf(
  2431. "  .area files.  A maximum area in a .poly file applies to the wholen");
  2432.   printf(
  2433. "  (segment-bounded) region in which a point falls, whereas a maximum arean");
  2434.   printf(
  2435. "  in an .area file applies to only one triangle.  Area constraints in .polyn"
  2436. );
  2437.   printf(
  2438. "  files are used only when a mesh is first generated, whereas arean");
  2439.   printf(
  2440. "  constraints in .area files are used only to refine an existing mesh, andn"
  2441. );
  2442.   printf(
  2443. "  are typically based on a posteriori error estimates resulting from an");
  2444.   printf("  finite element simulation on that mesh.nn");
  2445.   printf(
  2446. "  `triangle -rq25 object.1' reads object.1.node and object.1.ele, thenn");
  2447.   printf(
  2448. "  refines the triangulation to enforce a 25 degree minimum angle, and thenn"
  2449. );
  2450.   printf(
  2451. "  writes the refined triangulation to object.2.node and object.2.ele.n");
  2452.   printf("n");
  2453.   printf(
  2454. "  `triangle -rpaa6.2 z.3' reads z.3.node, z.3.ele, z.3.poly, and z.3.area.n"
  2455. );
  2456.   printf(
  2457. "  After reconstructing the mesh and its subsegments, Triangle refines then");
  2458.   printf(
  2459. "  mesh so that no triangle has area greater than 6.2, and furthermore then");
  2460.   printf(
  2461. "  triangles satisfy the maximum area constraints in z.3.area.  No anglen");
  2462.   printf(
  2463. "  bound is imposed at all.  The output is written to z.4.node, z.4.ele, andn"
  2464. );
  2465.   printf("  z.4.poly.nn");
  2466.   printf(
  2467. "  The sequence `triangle -qa1 x', `triangle -rqa.3 x.1', `triangle -rqa.1n");
  2468.   printf(
  2469. "  x.2' creates a sequence of successively finer meshes x.1, x.2, and x.3,n");
  2470.   printf("  suitable for multigrid.nn");
  2471.   printf("Convex Hulls and Mesh Boundaries:nn");
  2472.   printf(
  2473. "  If the input is a vertex set (not a PSLG), Triangle produces its convexn");
  2474.   printf(
  2475. "  hull as a by-product in the output .poly file if you use the -c switch.n");
  2476.   printf(
  2477. "  There are faster algorithms for finding a two-dimensional convex hulln");
  2478.   printf("  than triangulation, of course, but this one comes for free.nn");
  2479.   printf(
  2480. "  If the input is an unconstrained mesh (you are using the -r switch butn");
  2481.   printf(
  2482. "  not the -p switch), Triangle produces a list of its boundary edgesn");
  2483.   printf(
  2484. "  (including hole boundaries) as a by-product when you use the -c switch.n");
  2485.   printf(
  2486. "  If you also use the -p switch, the output .poly file contains all then");
  2487.   printf("  segments from the input .poly file as well.nn");
  2488.   printf("Voronoi Diagrams:nn");
  2489.   printf(
  2490. "  The -v switch produces a Voronoi diagram, in files suffixed .v.node andn");
  2491.   printf(
  2492. "  .v.edge.  For example, `triangle -v points' reads points.node, producesn");
  2493.   printf(
  2494. "  its Delaunay triangulation in points.1.node and points.1.ele, andn");
  2495.   printf(
  2496. "  produces its Voronoi diagram in points.1.v.node and points.1.v.edge.  Then"
  2497. );
  2498.   printf(
  2499. "  .v.node file contains a list of all Voronoi vertices, and the .v.edgen");
  2500.   printf(
  2501. "  file contains a list of all Voronoi edges, some of which may be infiniten"
  2502. );
  2503.   printf(
  2504. "  rays.  (The choice of filenames makes it easy to run the set of Voronoin");
  2505.   printf("  vertices through Triangle, if so desired.)nn");
  2506.   printf(
  2507. "  This implementation does not use exact arithmetic to compute the Voronoin"
  2508. );
  2509.   printf(
  2510. "  vertices, and does not check whether neighboring vertices are identical.n"
  2511. );
  2512.   printf(
  2513. "  Be forewarned that if the Delaunay triangulation is degenerate orn");
  2514.   printf(
  2515. "  near-degenerate, the Voronoi diagram may have duplicate vertices orn");
  2516.   printf("  crossing edges.nn");
  2517.   printf(
  2518. "  The result is a valid Voronoi diagram only if Triangle's output is a truen"
  2519. );
  2520.   printf(
  2521. "  Delaunay triangulation.  The Voronoi output is usually meaningless (andn");
  2522.   printf(
  2523. "  may contain crossing edges and other pathology) if the output is a CDT orn"
  2524. );
  2525.   printf(
  2526. "  CCDT, or if it has holes or concavities.  If the triangulated domain isn");
  2527.   printf(
  2528. "  convex and has no holes, you can use -D switch to force Triangle ton");
  2529.   printf(
  2530. "  construct a conforming Delaunay triangulation instead of a CCDT, so then");
  2531.   printf("  Voronoi diagram will be valid.nn");
  2532.   printf("Mesh Topology:nn");
  2533.   printf(
  2534. "  You may wish to know which triangles are adjacent to a certain Delaunayn");
  2535.   printf(
  2536. "  edge in an .edge file, which Voronoi cells are adjacent to a certainn");
  2537.   printf(
  2538. "  Voronoi edge in a .v.edge file, or which Voronoi cells are adjacent ton");
  2539.   printf(
  2540. "  each other.  All of this information can be found by cross-referencingn");
  2541.   printf(
  2542. "  output files with the recollection that the Delaunay triangulation andn");
  2543.   printf("  the Voronoi diagram are planar duals.nn");
  2544.   printf(
  2545. "  Specifically, edge i of an .edge file is the dual of Voronoi edge i ofn");
  2546.   printf(
  2547. "  the corresponding .v.edge file, and is rotated 90 degrees counterclock-n");
  2548.   printf(
  2549. "  wise from the Voronoi edge.  Triangle j of an .ele file is the dual ofn");
  2550.   printf(
  2551. "  vertex j of the corresponding .v.node file.  Voronoi cell k is the dualn");
  2552.   printf("  of vertex k of the corresponding .node file.nn");
  2553.   printf(
  2554. "  Hence, to find the triangles adjacent to a Delaunay edge, look at then");
  2555.   printf(
  2556. "  vertices of the corresponding Voronoi edge.  If the endpoints of an");
  2557.   printf(
  2558. "  Voronoi edge are Voronoi vertices 2 and 6 respectively, then triangles 2n"
  2559. );
  2560.   printf(
  2561. "  and 6 adjoin the left and right sides of the corresponding Delaunay edge,n"
  2562. );
  2563.   printf(
  2564. "  respectively.  To find the Voronoi cells adjacent to a Voronoi edge, lookn"
  2565. );
  2566.   printf(
  2567. "  at the endpoints of the corresponding Delaunay edge.  If the endpoints ofn"
  2568. );
  2569.   printf(
  2570. "  a Delaunay edge are input vertices 7 and 12, then Voronoi cells 7 and 12n"
  2571. );
  2572.   printf(
  2573. "  adjoin the right and left sides of the corresponding Voronoi edge,n");
  2574.   printf(
  2575. "  respectively.  To find which Voronoi cells are adjacent to each other,n");
  2576.   printf("  just read the list of Delaunay edges.nn");
  2577.   printf(
  2578. "  Triangle does not write a list of the edges adjoining each Voronoi cell,n"
  2579. );
  2580.   printf(
  2581. "  but you can reconstructed it straightforwardly.  For instance, to findn");
  2582.   printf(
  2583. "  all the edges of Voronoi cell 1, search the output .edge file for everyn");
  2584.   printf(
  2585. "  edge that has input vertex 1 as an endpoint.  The corresponding dualn");
  2586.   printf(
  2587. "  edges in the output .v.edge file form the boundary of Voronoi cell 1.n");
  2588.   printf("n");
  2589.   printf(
  2590. "  For each Voronoi vertex, the .neigh file gives a list of the threen");
  2591.   printf(
  2592. "  Voronoi vertices attached to it.  You might find this more convenientn");
  2593.   printf("  than the .v.edge file.nn");
  2594.   printf("Quadratic Elements:nn");
  2595.   printf(
  2596. "  Triangle generates meshes with subparametric quadratic elements if then");
  2597.   printf(
  2598. "  -o2 switch is specified.  Quadratic elements have six nodes per element,n"
  2599. );
  2600.   printf(
  2601. "  rather than three.  `Subparametric' means that the edges of the trianglesn"
  2602. );
  2603.   printf(
  2604. "  are always straight, so that subparametric quadratic elements aren");
  2605.   printf(
  2606. "  geometrically identical to linear elements, even though they can be usedn"
  2607. );
  2608.   printf(
  2609. "  with quadratic interpolating functions.  The three extra nodes of ann");
  2610.   printf(
  2611. "  element fall at the midpoints of the three edges, with the fourth, fifth,n"
  2612. );
  2613.   printf(
  2614. "  and sixth nodes appearing opposite the first, second, and third cornersn");
  2615.   printf("  respectively.nn");
  2616.   printf("Domains with Small Angles:nn");
  2617.   printf(
  2618. "  If two input segments adjoin each other at a small angle, clearly the -qn"
  2619. );
  2620.   printf(
  2621. "  switch cannot remove the small angle.  Moreover, Triangle may have non");
  2622.   printf(
  2623. "  choice but to generate additional triangles whose smallest angles aren");
  2624.   printf(
  2625. "  smaller than the specified bound.  However, these triangles only appearn");
  2626.   printf(
  2627. "  between input segments separated by small angles.  Moreover, if youn");
  2628.   printf(
  2629. "  request a minimum angle of theta degrees, Triangle will generally producen"
  2630. );
  2631.   printf(
  2632. "  no angle larger than 180 - 2 theta, even if it is forced to compromise onn"
  2633. );
  2634.   printf("  the minimum angle.nn");
  2635.   printf("Statistics:nn");
  2636.   printf(
  2637. "  After generating a mesh, Triangle prints a count of entities in then");
  2638.   printf(
  2639. "  output mesh, including the number of vertices, triangles, edges, exteriorn"
  2640. );
  2641.   printf(
  2642. "  boundary edges (i.e. subsegments on the boundary of the triangulation,n");
  2643.   printf(
  2644. "  including hole boundaries), interior boundary edges (i.e. subsegments ofn"
  2645. );
  2646.   printf(
  2647. "  input segments not on the boundary), and total subsegments.  If you'ven");
  2648.   printf(
  2649. "  forgotten the statistics for an existing mesh, run Triangle on that meshn"
  2650. );
  2651.   printf(
  2652. "  with the -rNEP switches to read the mesh and print the statistics withoutn"
  2653. );
  2654.   printf(
  2655. "  writing any files.  Use -rpNEP if you've got a .poly file for the mesh.n");
  2656.   printf("n");
  2657.   printf(
  2658. "  The -V switch produces extended statistics, including a rough estimaten");
  2659.   printf(
  2660. "  of memory use, the number of calls to geometric predicates, andn");
  2661.   printf(
  2662. "  histograms of the angles and the aspect ratios of the triangles in then");
  2663.   printf("  mesh.nn");
  2664.   printf("Exact Arithmetic:nn");
  2665.   printf(
  2666. "  Triangle uses adaptive exact arithmetic to perform what computationaln");
  2667.   printf(
  2668. "  geometers call the `orientation' and `incircle' tests.  If the floating-n"
  2669. );
  2670.   printf(
  2671. "  point arithmetic of your machine conforms to the IEEE 754 standard (asn");
  2672.   printf(
  2673. "  most workstations do), and does not use extended precision internaln");
  2674.   printf(
  2675. "  floating-point registers, then your output is guaranteed to be ann");
  2676.   printf(
  2677. "  absolutely true Delaunay or constrained Delaunay triangulation, roundoffn"
  2678. );
  2679.   printf(
  2680. "  error notwithstanding.  The word `adaptive' implies that these arithmeticn"
  2681. );
  2682.   printf(
  2683. "  routines compute the result only to the precision necessary to guaranteen"
  2684. );
  2685.   printf(
  2686. "  correctness, so they are usually nearly as fast as their approximaten");
  2687.   printf("  counterparts.nn");
  2688.   printf(
  2689. "  May CPUs, including Intel x86 processors, have extended precisionn");
  2690.   printf(
  2691. "  floating-point registers.  These must be reconfigured so their precisionn"
  2692. );
  2693.   printf(
  2694. "  is reduced to memory precision.  Triangle does this if it is compiledn");
  2695.   printf("  correctly.  See the makefile for details.nn");
  2696.   printf(
  2697. "  The exact tests can be disabled with the -X switch.  On most inputs, thisn"
  2698. );
  2699.   printf(
  2700. "  switch reduces the computation time by about eight percent--it's notn");
  2701.   printf(
  2702. "  worth the risk.  There are rare difficult inputs (having many collinearn");
  2703.   printf(
  2704. "  and cocircular vertices), however, for which the difference in speedn");
  2705.   printf(
  2706. "  could be a factor of two.  Be forewarned that these are precisely then");
  2707.   printf(
  2708. "  inputs most likely to cause errors if you use the -X switch.  Hence, then"
  2709. );
  2710.   printf("  -X switch is not recommended.nn");
  2711.   printf(
  2712. "  Unfortunately, the exact tests don't solve every numerical problem.n");
  2713.   printf(
  2714. "  Exact arithmetic is not used to compute the positions of new vertices,n");
  2715.   printf(
  2716. "  because the bit complexity of vertex coordinates would grow withoutn");
  2717.   printf(
  2718. "  bound.  Hence, segment intersections aren't computed exactly; in veryn");
  2719.   printf(
  2720. "  unusual cases, roundoff error in computing an intersection point mightn");
  2721.   printf(
  2722. "  actually lead to an inverted triangle and an invalid triangulation.n");
  2723.   printf(
  2724. "  (This is one reason to specify your own intersection points in your .polyn"
  2725. );
  2726.   printf(
  2727. "  files.)  Similarly, exact arithmetic is not used to compute the verticesn"
  2728. );
  2729.   printf("  of the Voronoi diagram.nn");
  2730.   printf(
  2731. "  Another pair of problems not solved by the exact arithmetic routines isn");
  2732.   printf(
  2733. "  underflow and overflow.  If Triangle is compiled for double precisionn");
  2734.   printf(
  2735. "  arithmetic, I believe that Triangle's geometric predicates work correctlyn"
  2736. );
  2737.   printf(
  2738. "  if the exponent of every input coordinate falls in the range [-148, 201].n"
  2739. );
  2740.   printf(
  2741. "  Underflow can silently prevent the orientation and incircle tests fromn");
  2742.   printf(
  2743. "  being performed exactly, while overflow typically causes a floatingn");
  2744.   printf("  exception.nn");
  2745.   printf("Calling Triangle from Another Program:nn");
  2746.   printf("  Read the file triangle.h for details.nn");
  2747.   printf("Troubleshooting:nn");
  2748.   printf("  Please read this section before mailing me bugs.nn");
  2749.   printf("  `My output mesh has no triangles!'nn");
  2750.   printf(
  2751. "    If you're using a PSLG, you've probably failed to specify a proper setn"
  2752. );
  2753.   printf(
  2754. "    of bounding segments, or forgotten to use the -c switch.  Or you mayn");
  2755.   printf(
  2756. "    have placed a hole badly, thereby eating all your triangles.  To testn");
  2757.   printf("    these possibilities, try again with the -c and -O switches.n");
  2758.   printf(
  2759. "    Alternatively, all your input vertices may be collinear, in which casen"
  2760. );
  2761.   printf("    you can hardly expect to triangulate them.nn");
  2762.   printf("  `Triangle doesn't terminate, or just crashes.'nn");
  2763.   printf(
  2764. "    Bad things can happen when triangles get so small that the distancen");
  2765.   printf(
  2766. "    between their vertices isn't much larger than the precision of yourn");
  2767.   printf(
  2768. "    machine's arithmetic.  If you've compiled Triangle for single-precisionn"
  2769. );
  2770.   printf(
  2771. "    arithmetic, you might do better by recompiling it for double-precision.n"
  2772. );
  2773.   printf(
  2774. "    Then again, you might just have to settle for more lenient constraintsn"
  2775. );
  2776.   printf(
  2777. "    on the minimum angle and the maximum area than you had planned.n");
  2778.   printf("n");
  2779.   printf(
  2780. "    You can minimize precision problems by ensuring that the origin liesn");
  2781.   printf(
  2782. "    inside your vertex set, or even inside the densest part of yourn");
  2783.   printf(
  2784. "    mesh.  If you're triangulating an object whose x-coordinates all falln");
  2785.   printf(
  2786. "    between 6247133 and 6247134, you're not leaving much floating-pointn");
  2787.   printf("    precision for Triangle to work with.nn");
  2788.   printf(
  2789. "    Precision problems can occur covertly if the input PSLG contains twon");
  2790.   printf(
  2791. "    segments that meet (or intersect) at an extremely small angle, or ifn");
  2792.   printf(
  2793. "    such an angle is introduced by the -c switch.  If you don't realizen");
  2794.   printf(
  2795. "    that a tiny angle is being formed, you might never discover whyn");
  2796.   printf(
  2797. "    Triangle is crashing.  To check for this possibility, use the -S switchn"
  2798. );
  2799.   printf(
  2800. "    (with an appropriate limit on the number of Steiner points, found byn");
  2801.   printf(
  2802. "    trial-and-error) to stop Triangle early, and view the output .poly filen"
  2803. );
  2804.   printf(
  2805. "    with Show Me (described below).  Look carefully for regions where densen"
  2806. );
  2807.   printf(
  2808. "    clusters of vertices are forming and for small angles between segments.n"
  2809. );
  2810.   printf(
  2811. "    Zoom in closely, as such segments might look like a single segment fromn"
  2812. );
  2813.   printf("    a distance.nn");
  2814.   printf(
  2815. "    If some of the input values are too large, Triangle may suffer an");
  2816.   printf(
  2817. "    floating exception due to overflow when attempting to perform ann");
  2818.   printf(
  2819. "    orientation or incircle test.  (Read the section on exact arithmeticn");
  2820.   printf(
  2821. "    above.)  Again, I recommend compiling Triangle for double (rathern");
  2822.   printf("    than single) precision arithmetic.nn");
  2823.   printf(
  2824. "    Unexpected problems can arise if you use quality meshing (-q, -a, orn");
  2825.   printf(
  2826. "    -u) with an input that is not segment-bounded--that is, if your inputn");
  2827.   printf(
  2828. "    is a vertex set, or you're using the -c switch.  If the convex hull ofn"
  2829. );
  2830.   printf(
  2831. "    your input vertices has collinear vertices on its boundary, an inputn");
  2832.   printf(
  2833. "    vertex that you think lies on the convex hull might actually lie justn");
  2834.   printf(
  2835. "    inside the convex hull.  If so, the vertex and the nearby convex hulln");
  2836.   printf(
  2837. "    edge form an extremely thin triangle.  When Triangle tries to refinen");
  2838.   printf(
  2839. "    the mesh to enforce angle and area constraints, Triangle might generaten"
  2840. );
  2841.   printf(
  2842. "    extremely tiny triangles, or it might fail because of insufficientn");
  2843.   printf("    floating-point precision.nn");
  2844.   printf(
  2845. "  `The numbering of the output vertices doesn't match the input vertices.'n"
  2846. );
  2847.   printf("n");
  2848.   printf(
  2849. "    You may have had duplicate input vertices, or you may have eaten somen");
  2850.   printf(
  2851. "    of your input vertices with a hole, or by placing them outside the arean"
  2852. );
  2853.   printf(
  2854. "    enclosed by segments.  In any case, you can solve the problem by notn");
  2855.   printf("    using the -j switch.nn");
  2856.   printf(
  2857. "  `Triangle executes without incident, but when I look at the resultingn");
  2858.   printf(
  2859. "  mesh, it has overlapping triangles or other geometric inconsistencies.'n");
  2860.   printf("n");
  2861.   printf(
  2862. "    If you select the -X switch, Triangle occasionally makes mistakes duen");
  2863.   printf(
  2864. "    to floating-point roundoff error.  Although these errors are rare,n");
  2865.   printf(
  2866. "    don't use the -X switch.  If you still have problems, please report then"
  2867. );
  2868.   printf("    bug.nn");
  2869.   printf(
  2870. "  `Triangle executes without incident, but when I look at the resultingn");
  2871.   printf("  Voronoi diagram, it has overlapping edges or other geometricn");
  2872.   printf("  inconsistencies.'n");
  2873.   printf("n");
  2874.   printf(
  2875. "    If your input is a PSLG (-p), you can only expect a meaningful Voronoin"
  2876. );
  2877.   printf(
  2878. "    diagram if the domain you are triangulating is convex and free ofn");
  2879.   printf(
  2880. "    holes, and you use the -D switch to construct a conforming Delaunayn");
  2881.   printf("    triangulation (instead of a CDT or CCDT).nn");
  2882.   printf(
  2883. "  Strange things can happen if you've taken liberties with your PSLG.  Don");
  2884.   printf(
  2885. "  you have a vertex lying in the middle of a segment?  Triangle sometimesn");
  2886.   printf(
  2887. "  copes poorly with that sort of thing.  Do you want to lay out a collinearn"
  2888. );
  2889.   printf(
  2890. "  row of evenly spaced, segment-connected vertices?  Have you simplyn");
  2891.   printf(
  2892. "  defined one long segment connecting the leftmost vertex to the rightmostn"
  2893. );
  2894.   printf(
  2895. "  vertex, and a bunch of vertices lying along it?  This method occasionallyn"
  2896. );
  2897.   printf(
  2898. "  works, especially with horizontal and vertical lines, but often itn");
  2899.   printf(
  2900. "  doesn't, and you'll have to connect each adjacent pair of vertices with an"
  2901. );
  2902.   printf("  separate segment.  If you don't like it, tough.nn");
  2903.   printf(
  2904. "  Furthermore, if you have segments that intersect other than at theirn");
  2905.   printf(
  2906. "  endpoints, try not to let the intersections fall extremely close to PSLGn"
  2907. );
  2908.   printf("  vertices or each other.nn");
  2909.   printf(
  2910. "  If you have problems refining a triangulation not produced by Triangle:n");
  2911.   printf(
  2912. "  Are you sure the triangulation is geometrically valid?  Is it formattedn");
  2913.   printf(
  2914. "  correctly for Triangle?  Are the triangles all listed so the first threen"
  2915. );
  2916.   printf(
  2917. "  vertices are their corners in counterclockwise order?  Are all of then");
  2918.   printf(
  2919. "  triangles constrained Delaunay?  Triangle's Delaunay refinement algorithmn"
  2920. );
  2921.   printf("  assumes that it starts with a CDT.nn");
  2922.   printf("Show Me:nn");
  2923.   printf(
  2924. "  Triangle comes with a separate program named `Show Me', whose primaryn");
  2925.   printf(
  2926. "  purpose is to draw meshes on your screen or in PostScript.  Its secondaryn"
  2927. );
  2928.   printf(
  2929. "  purpose is to check the validity of your input files, and do so moren");
  2930.   printf(
  2931. "  thoroughly than Triangle does.  Unlike Triangle, Show Me requires thatn");
  2932.   printf(
  2933. "  you have the X Windows system.  Sorry, Microsoft Windows users.n");
  2934.   printf("n");
  2935.   printf("Triangle on the Web:n");
  2936.   printf("n");
  2937.   printf("  To see an illustrated version of these instructions, check outn");
  2938.   printf("n");
  2939.   printf("    http://www.cs.cmu.edu/~quake/triangle.htmln");
  2940.   printf("n");
  2941.   printf("A Brief Plea:n");
  2942.   printf("n");
  2943.   printf(
  2944. "  If you use Triangle, and especially if you use it to accomplish realn");
  2945.   printf(
  2946. "  work, I would like very much to hear from you.  A short letter or emailn");
  2947.   printf(
  2948. "  (to jrs@cs.berkeley.edu) describing how you use Triangle will mean a lotn"