Programming Projects in C
for students of
Engineering, Sciences and Mathematics
Rouben Rostamian
2014

Resources for Project Triangulate

The Triangle library

Triangle is a C library for generating high-quality triangular meshes. You may download the C code from the Triangle's home website if you want, however it won't work out of the box since you need to set a few preprocessor options. I suggest that you use the modified version that I have provided here instead:

Modified triangle:  triangle.h  triangle.c

My modifications amount to setting the preprocessor options that make it into a C module rather than a stand-alone program. The triangulation code itself is not touched.

The file triangle.h is the module's interface. It includes extensive comments on the module's use. The file triangle.c (which is over 16,000 lines long!) contains the module's implementation (and built-in documentation for the stand-alone version). The code implements a few kludges in the interest of minimizing memory usage, therefore you will get warnings when you compile it with gcc's -Wall -pedantic flags. Nevertheless, the compiled program seems to work on the machines I have tried.

You may drop the files triangle.h and triangle.c into your project's directory and treat them like any *.c and *.h file of your own. Although that will work, it's not a good idea—mixing triangle.h and triangle.c with your own files is ugly.

I suggest that you put triangle.h and triangle.c in a directory of their own, let's say ../triangle/ relative to your project's directory. Go to that directory and compile Triangle:

$ cc -Wall -pedantic -std=c89 -O2 triangle.c -c
This will create the object file triangle.o. You will see several warnings due to the kludges noted above. Ignore the warnings.

Now go to your project's directory and establish symbolic links to Triangle:

$ ln -s ../triangle/triangle.[ho] .
(Don't overlook the space and the period at the end of that command.) This makes the files triangle.h and triangle.o available to your project. Compile and link with the rest of your project's files as usual. This technique should work on any operating system that supports symbolic links. These include Unix, MacOS, and Windows.

Aside: If you know how to make libraries on your operating system, you may build a true library out of triangle.o and install it in a standard place in your compiler's search path. Then you may link your program with it by specifying the -ltriangle flag at the linking stage.

Supplementary files

To complete your project, you will need the following files:

mesh-to-eps.h    mesh-to-eps.c    mesh.c
The significance and uses of these files are described in the book, so I won't elaborate on them here.



Programming Projects in C Valid HTML 5 Valid CSS