PDF version (NAG web site
, 64-bit version, 64-bit version)
NAG Toolbox: nag_pde_2d_triangulate (d03ma)
Purpose
nag_pde_2d_triangulate (d03ma) places a triangular mesh over a given two-dimensional region. The region may have any shape, including one with holes.
Syntax
Description
nag_pde_2d_triangulate (d03ma) begins with a uniform triangular grid as shown in
Figure 1 and assumes that the region to be triangulated lies within the rectangle given by the inequalities
This rectangle is drawn in bold in
Figure 1. The region is specified by the
isin which must determine whether any given point
lies in the region. The uniform grid is processed column-wise, with
preceding
if
or
,
. Points near the boundary are moved onto it and points well outside the boundary are omitted. The direction of movement is chosen to avoid pathologically thin triangles. The points accepted are numbered in exactly the same order as the corresponding points of the uniform grid were scanned. The output consists of the
coordinates of all grid points and integers indicating whether they are internal and to which other points they are joined by triangle sides.
The mesh size must be chosen small enough for the essential features of the region to be apparent from testing all points of the original uniform grid for being inside the region. For instance if any hole is within of another hole or the outer boundary then a triangle may be found with all vertices within of a boundary. Such a triangle is taken to be external to the region so the effect will be to join the hole to another hole or to the external region.
Further details of the algorithm are given in the references.
References
Reid J K (1970) Fortran subroutines for the solutions of Laplace's equation over a general routine in two dimensions Harwell Report TP422
Reid J K (1972) On the construction and convergence of a finite-element solution of Laplace's equation J. Instr. Math. Appl. 9 1–13
Parameters
Compulsory Input Parameters
- 1:
– double scalar
-
, the required length for the sides of the triangles of the uniform mesh.
- 2:
– int64int32nag_int scalar
- 3:
– int64int32nag_int scalar
-
Values
and
such that all points
inside the region satisfy the inequalities
Constraint:
.
- 4:
– int64int32nag_int scalar
-
The number of times a triangle side is bisected to find a point on the boundary. A value of
is adequate for most purposes (see
Accuracy).
Constraint:
.
- 5:
– int64int32nag_int scalar
-
An upper bound on the number of points in the triangulation. The actual value will be returned in
npts.
- 6:
– function handle or string containing name of m-file
-
isin must return the value
if the given point (
x,
y) lies inside the region, and
if it lies outside.
[result] = isin(x, y)
Input Parameters
- 1:
– double scalar
- 2:
– double scalar
-
The coordinates of the given point.
Output Parameters
- 1:
– int64int32nag_int scalar
-
The value
if the given point (
x,
y) lies inside the region, and
if it lies outside.
Optional Input Parameters
None.
Output Parameters
- 1:
– int64int32nag_int scalar
-
The number of points in the triangulation.
- 2:
– double array
-
The and coordinates respectively of the th point of the triangulation.
- 3:
– int64int32nag_int array
-
contains if point is inside the region and if it is on the boundary. For each triangle side between points and with , , , contains or according to whether point is internal or on the boundary. There can never be more than three such points. If there are less, then some values , , are zero.
- 4:
– int64int32nag_int scalar
unless the function detects an error (see
Error Indicators and Warnings).
Error Indicators and Warnings
Errors or warnings detected by the function:
-
-
-
-
A point inside the region violates one of the constraints (see arguments
m and
n).
-
-
sddist is too small.
-
-
.
-
-
.
-
-
.
-
An unexpected error has been triggered by this routine. Please
contact
NAG.
-
Your licence key may have expired or may not have been installed correctly.
-
Dynamic memory allocation failed.
Accuracy
Points are moved onto the boundary by bisecting a triangle side
nb times. The accuracy is therefore
.
Further Comments
The time taken is approximately proportional to .
Example
The following program triangulates the circle with centre and radius using a basic grid size .
Open in the MATLAB editor:
d03ma_example
function d03ma_example
fprintf('d03ma example results\n\n');
h = 4;
m = int64(3);
n = int64(5);
nb = int64(10);
sdindx = int64(100);
[npts, places, index, ifail] = d03ma( ...
h, m, n, nb, sdindx, @isin);
fprintf('Number of points = %4d\n',npts);
fig1 = figure;
k = 0;
hold on
for i = 1:npts
for j=2:4
if(index(j,i)~=0)
k = k + 1;
l = abs(index(j,i));
x(1) = places(1,i);
x(2) = places(1,l);
y(1) = places(2,i);
y(2) = places(2,l);
plot(x,y)
end
end
end
axis square;
title({'Triangulation of a circle','grid-size=4'});
hold off;
fprintf('Number of edges = %4d\n',k);
function result = isin(x,y)
if ((x-7)^2+(y-7)^2 <= 36)
result = int64(1);
else
result = int64(0);
end
d03ma example results
Number of points = 14
Number of edges = 29
PDF version (NAG web site
, 64-bit version, 64-bit version)
© The Numerical Algorithms Group Ltd, Oxford, UK. 2009–2015