# NAG Library Routine Document

## 1Purpose

e01eaf generates a triangulation for a given set of two-dimensional points using the method of Renka and Cline.

## 2Specification

Fortran Interface
 Subroutine e01eaf ( n, x, y,
 Integer, Intent (In) :: n Integer, Intent (Inout) :: ifail Integer, Intent (Out) :: triang(7*n) Real (Kind=nag_wp), Intent (In) :: x(n), y(n)
#include nagmk26.h
 void e01eaf_ (const Integer *n, const double x[], const double y[], Integer triang[], Integer *ifail)

## 3Description

e01eaf creates a Thiessen triangulation with a given set of two-dimensional data points as nodes. This triangulation will be as equiangular as possible (Cline and Renka (1984)). See Renka and Cline (1984) for more detailed information on the algorithm, a development of that by Lawson (1977). The code is derived from Renka (1984).
The computed triangulation is returned in a form suitable for passing to e01ebf which, for a set of nodal function values, computes interpolated values at a set of points.
Cline A K and Renka R L (1984) A storage-efficient method for construction of a Thiessen triangulation Rocky Mountain J. Math. 14 119–139
Lawson C L (1977) Software for ${C}^{1}$ surface interpolation Mathematical Software III (ed J R Rice) 161–194 Academic Press
Renka R L (1984) Algorithm 624: triangulation and interpolation of arbitrarily distributed points in the plane ACM Trans. Math. Software 10 440–442
Renka R L and Cline A K (1984) A triangle-based ${C}^{1}$ interpolation method Rocky Mountain J. Math. 14 223–237

## 5Arguments

1:     $\mathbf{n}$ – IntegerInput
On entry: $n$, the number of data points.
Constraint: ${\mathbf{n}}\ge 3$.
2:     $\mathbf{x}\left({\mathbf{n}}\right)$ – Real (Kind=nag_wp) arrayInput
On entry: the $x$ coordinates of the $n$ data points.
3:     $\mathbf{y}\left({\mathbf{n}}\right)$ – Real (Kind=nag_wp) arrayInput
On entry: the $y$ coordinates of the $n$ data points.
4:     $\mathbf{triang}\left(7×{\mathbf{n}}\right)$ – Integer arrayOutput
On exit: a data structure defining the computed triangulation, in a form suitable for passing to e01ebf. Details of how the triangulation is encoded in triang are given in Section 9. These details are most likely to be of use when plotting the computed triangulation which is demonstrated in Section 10.
5:     $\mathbf{ifail}$ – IntegerInput/Output
On entry: ifail must be set to $0$, $-1\text{​ or ​}1$. If you are unfamiliar with this argument you should refer to Section 3.4 in How to Use the NAG Library and its Documentation for details.
For environments where it might be inappropriate to halt program execution when an error is detected, the value $-1\text{​ or ​}1$ is recommended. If the output of error messages is undesirable, then the value $1$ is recommended. Otherwise, if you are not familiar with this argument, the recommended value is $0$. When the value $-\mathbf{1}\text{​ or ​}\mathbf{1}$ is used it is essential to test the value of ifail on exit.
On exit: ${\mathbf{ifail}}={\mathbf{0}}$ unless the routine detects an error or a warning has been flagged (see Section 6).

## 6Error Indicators and Warnings

If on entry ${\mathbf{ifail}}=0$ or $-1$, explanatory error messages are output on the current error message unit (as defined by x04aaf).
Errors or warnings detected by the routine:
${\mathbf{ifail}}=1$
On entry, ${\mathbf{n}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{n}}\ge 3$.
${\mathbf{ifail}}=2$
On entry, all the $\left(x,y\right)$ pairs are collinear.
${\mathbf{ifail}}=-99$
An unexpected error has been triggered by this routine. Please contact NAG.
See Section 3.9 in How to Use the NAG Library and its Documentation for further information.
${\mathbf{ifail}}=-399$
Your licence key may have expired or may not have been installed correctly.
See Section 3.8 in How to Use the NAG Library and its Documentation for further information.
${\mathbf{ifail}}=-999$
Dynamic memory allocation failed.
See Section 3.7 in How to Use the NAG Library and its Documentation for further information.

Not applicable.

## 8Parallelism and Performance

e01eaf is not threaded in any implementation.

The time taken for a call of e01eaf is approximately proportional to the number of data points, $n$. The routine is more efficient if, before entry, the $\left(x,y\right)$ pairs are arranged in x and y such that the $x$ values are in ascending order.
The triangulation is encoded in triang as follows:
• set ${j}_{0}=0$; for each node, $k=1,2,\dots ,n$, (using the ordering inferred from x and y)
• ${i}_{k}={j}_{k-1}+1$
• ${j}_{k}={\mathbf{triang}}\left(6×{\mathbf{n}}+k\right)$
• ${\mathbf{triang}}\left(\mathit{j}\right)$, for $\mathit{j}={i}_{k},\dots ,{\mathit{j}}_{k}$, contains the list of nodes to which node $k$ is connected. If ${\mathbf{triang}}\left({j}_{k}\right)=0$ then node $k$ is on the boundary of the mesh.

## 10Example

In this example, e01eaf creates a triangulation from a set of data points. e01ebf then evaluates the interpolant at a sample of points using this triangulation. Note that this example is not typical of a realistic problem: the number of data points would normally be larger, so that interpolants can be more accurately evaluated at the fine triangulated grid.

### 10.1Program Text

Program Text (e01eafe.f90)

### 10.2Program Data

Program Data (e01eafe.d)

### 10.3Program Results

Program Results (e01eafe.r)

© The Numerical Algorithms Group Ltd, Oxford, UK. 2017