Triangle Neighbors
in a Triangulation

TRIANGULATION_TRIANGLE_NEIGHBORS is a FORTRAN90 program which computes the three neighboring triangles of each triangle in a triangulation.

The user supplies a node file and a triangle file, containing the coordinates of the nodes, and the indices of the nodes that make up each triangle. Either 3-node or 6-node triangles may be used.

The program reads the data, computes the triangle neighbor information, and writes out the information to a file. In cases where one side of a triangle has no triangle neighbor, a value of -1 is assigned.

The triangle neighbor array is useful if the triangulation has to be searched to find the triangle containing a given point. It is also useful when analyzing the bandwidth of the adjacency matrix, or of a finite element matrix derived from the triangulation.


triangulation_triangle_neighbors prefix
where prefix is the common prefix for the node and triangle files, and will also be used to name the output file:


The computer code and data files described and made available on this web page are distributed under the GNU LGPL license.


TRIANGULATION_TRIANGLE_NEIGHBORS is available in a C version and a C++ version and a FORTRAN90 version and a MATLAB version.

Related Data and Programs:

MESH_BANDWIDTH, a FORTRAN90 program which returns the geometric bandwidth associated with a mesh of elements of any order and in a space of arbitrary dimension.

MESH_TO_XML, a FORTRAN90 program which reads information defining a 1D, 2D or 3D mesh, namely a file of node coordinates and a file of elements defined by node indices, and creates a corresponding XML file for input to DOLFIN or FENICS.

NEIGHBORS_TO_METIS_GRAPH, a FORTRAN90 program which reads a triangle mesh neighbor file created by TRIANGULATION_TRIANGLE_NEIGHBORS and writes a modified version of the same data suitable for input to the mesh partitioning program METIS.

RCM, a FORTRAN90 library which carries out reverse Cuthill-McKee computations.

TABLE_DELAUNAY, a FORTRAN90 program which triangulates a set of nodes whose coordinates are stored in a file.

TET_MESH_RCM, a FORTRAN90 library which applies the reverse Cuthill-McKee reordering to a tetrahedral mesh of nodes in 3D.

TRIANGLE, a C program which computes a triangulation of a geometric region.

TRIANGULATION, a FORTRAN90 library which carries out various operations on order 3 ("linear") or order 6 ("quadratic") triangulations.

TRIANGULATION_BOUNDARY_NODES, a FORTRAN90 program which reads data defining a triangulation, determines which nodes lie on the boundary, and writes their coordinates to a file.

TRIANGULATION_CORNER, a FORTRAN90 program which patches triangulations so that no triangle has two sides on the boundary.

TRIANGULATION_DELAUNAY_DISCREPANCY, a FORTRAN90 program which measures the amount by which a triangulation fails the local Delaunay test;

TRIANGULATION_DISPLAY_OPENGL, a C++ program which reads files defining a triangulation and displays an image using Open GL.

TRIANGULATION_HISTOGRAM, a FORTRAN90 program which computes histograms of data over a triangulation.

TRIANGULATION_L2Q, a FORTRAN90 program which reads data defining a 3-node triangulation and generates midside nodes and writes out the corresponding 6-node triangulation.

TRIANGULATION_MASK, a FORTRAN90 program which takes an existing triangulation and deletes triangles and their corresponding nodes as requested by the user.

TRIANGULATION_ORDER3, a directory which contains a description and examples of order 3 triangulations.

TRIANGULATION_ORDER6, a directory which contains a description and examples of order 6 triangulations.

TRIANGULATION_ORIENT, a FORTRAN90 program which reads data defining a triangulation, makes sure that every triangle has positive orientation, and if not, writes a corrected triangle file.

TRIANGULATION_PLOT, a FORTRAN90 program which reads data defining a triangulation and creates a PostScript image of the nodes and triangles.

TRIANGULATION_Q2L, a FORTRAN90 program which reads data defining a 6-node triangulation, and subdivides each triangle into 4 3-node triangles, writing the resulting triangulation to a file.

TRIANGULATION_QUAD, a FORTRAN90 program which estimates the integral of a function over a triangulated region.

TRIANGULATION_QUALITY, a FORTRAN90 program which reads data defining a triangulation and computes a number of quality measures.

TRIANGULATION_RCM, a FORTRAN90 program which can reorder the nodes of a triangulation so that the bandwidth of the associated adjacency matrix is reduced.

TRIANGULATION_REFINE, a FORTRAN90 program which can be used to refine a triangulation.

TRIG_TO_NEIB, a C program which reads "NODE" and "ELE" files (a format prescribed by triangle) describing a triangulation, and produces a file defining the neighbor triangles of each element; the program can also produce information about the Voronoi diagram. The program is by Lili Ju.


  1. Marc deBerg, Marc Krevald, Mark Overmars, Otfried Schwarzkopf,
    Computational Geometry,
    Springer, 2000,
    ISBN: 3-540-65620-0.
  2. Joseph ORourke,
    Computational Geometry,
    Second Edition,
    Cambridge, 1998,
    ISBN: 0521649765,
    LC: QA448.D38.

Source Code:

Examples and Tests:

Examples and Tests:

BIG_CAVITY is a triangulation using 8,195 nodes and 4,000 elements.

BOX3 is a triangulation of order 3, using 20 nodes and 24 elements:

BOX6 is a triangulation of order 6:

GREENLAND is a triangulation using 33,343 nodes and 64,125 elements.

LAKE_COARSE is an irregular lake with an island.
There are 621 nodes and 974 elements and 1 hole.

LAKE3 is an irregular lake with an island.
The smallest angle is 23.46 degrees.
There are 1552 nodes and 2820 elements and 1 hole.

List of Routines:

You can go up one level to the FORTRAN90 source codes.

Last revised on 27 June 2009.