Integer type:  int32  int64  nag_int  show int32  show int32  show int64  show int64  show nag_int  show nag_int

Chapter Contents
Chapter Introduction
NAG Toolbox

# NAG Toolbox: nag_mesh_2d_gen_boundary (d06ba)

## Purpose

nag_mesh_2d_gen_boundary (d06ba) generates a boundary mesh on a closed connected subdomain $\Omega$ of ${ℝ}^{2}$.

## Syntax

[nvb, coor, nedge, edge, user, ifail] = d06ba(coorch, lined, fbnd, crus, rate, nlcomp, lcomp, nvmax, nedmx, itrace, 'nlines', nlines, 'sdcrus', sdcrus, 'ncomp', ncomp, 'user', user)
[nvb, coor, nedge, edge, user, ifail] = nag_mesh_2d_gen_boundary(coorch, lined, fbnd, crus, rate, nlcomp, lcomp, nvmax, nedmx, itrace, 'nlines', nlines, 'sdcrus', sdcrus, 'ncomp', ncomp, 'user', user)

## Description

Given a closed connected subdomain $\Omega$ of ${ℝ}^{2}$, whose boundary $\partial \Omega$ is divided by characteristic points into $m$ distinct line segments, nag_mesh_2d_gen_boundary (d06ba) generates a boundary mesh on $\partial \Omega$. Each line segment may be a straight line, a curve defined by the equation $f\left(x,y\right)=0$, or a polygonal curve defined by a set of given boundary mesh points.
This function is primarily designed for use with either nag_mesh_2d_gen_inc (d06aa) (a simple incremental method) or nag_mesh_2d_gen_delaunay (d06ab) (Delaunay–Voronoi method) or nag_mesh_2d_gen_front (d06ac) (Advancing Front method) to triangulate the interior of the domain $\Omega$. For more details about the boundary and interior mesh generation, consult the D06 Chapter Introduction as well as George and Borouchaki (1998).
This function is derived from material in the MODULEF package from INRIA (Institut National de Recherche en Informatique et Automatique).

## References

George P L and Borouchaki H (1998) Delaunay Triangulation and Meshing: Application to Finite Elements Editions HERMES, Paris

## Parameters

### Compulsory Input Parameters

1:     $\mathrm{coorch}\left(2,{\mathbf{nlines}}\right)$ – double array
${\mathbf{coorch}}\left(1,\mathit{i}\right)$ contains the $x$ coordinate of the $\mathit{i}$th characteristic point, for $\mathit{i}=1,2,\dots ,{\mathbf{nlines}}$; while ${\mathbf{coorch}}\left(2,i\right)$ contains the corresponding $y$ coordinate.
2:     $\mathrm{lined}\left(4,{\mathbf{nlines}}\right)$int64int32nag_int array
The description of the lines that define the boundary domain. The line $\mathit{i}$, for $\mathit{i}=1,2,\dots ,m$, is defined as follows:
${\mathbf{lined}}\left(1,i\right)$
The number of points on the line, including two end points.
${\mathbf{lined}}\left(2,i\right)$
The first end point of the line. If ${\mathbf{lined}}\left(2,i\right)=j$, then the coordinates of the first end point are those stored in ${\mathbf{coorch}}\left(:,j\right)$.
${\mathbf{lined}}\left(3,i\right)$
The second end point of the line. If ${\mathbf{lined}}\left(3,i\right)=k$, then the coordinates of the second end point are those stored in ${\mathbf{coorch}}\left(:,k\right)$.
${\mathbf{lined}}\left(4,i\right)$
This defines the type of line segment connecting the end points. Additional information is conveyed by the numerical value of ${\mathbf{lined}}\left(4,i\right)$ as follows:
 (i) ${\mathbf{lined}}\left(4,i\right)>0$, the line is described in fbnd with ${\mathbf{lined}}\left(4,i\right)$ as the index. In this case, the line must be described in the trigonometric (anticlockwise) direction; (ii) ${\mathbf{lined}}\left(4,i\right)=0$, the line is a straight line; (iii) if ${\mathbf{lined}}\left(4,i\right)<0$, say ($-p$), then the line is a polygonal arc joining the end points and interior points specified in crus. In this case the line contains the points whose coordinates are stored in ${\mathbf{coorch}}\left(:,j\right),\phantom{\rule{0ex}{0ex}}{\mathbf{crus}}\left(:,p\right),\phantom{\rule{0ex}{0ex}}{\mathbf{crus}}\left(:,p+1\right),\dots ,{\mathbf{crus}}\left(:,p+r-3\right),\phantom{\rule{0ex}{0ex}}{\mathbf{coorch}}\left(:,k\right)$ , where $z\in \left\{1,2\right\}$, $r={\mathbf{lined}}\left(1,i\right)$, $j={\mathbf{lined}}\left(2,i\right)$ and $k={\mathbf{lined}}\left(3,i\right)$.
Constraints:
• $2\le {\mathbf{lined}}\left(1,i\right)$;
• $1\le {\mathbf{lined}}\left(2,i\right)\le {\mathbf{nlines}}$;
• $1\le {\mathbf{lined}}\left(3,i\right)\le {\mathbf{nlines}}$;
• ${\mathbf{lined}}\left(2,\mathit{i}\right)\ne {\mathbf{lined}}\left(3,\mathit{i}\right)$, for $\mathit{i}=1,2,\dots ,{\mathbf{nlines}}$.
For each line described by fbnd (lines with ${\mathbf{lined}}\left(4,\mathit{i}\right)>0$, for $\mathit{i}=1,2,\dots ,{\mathbf{nlines}}$) the two end points (${\mathbf{lined}}\left(2,i\right)$ and ${\mathbf{lined}}\left(3,i\right)$) lie on the curve defined by index ${\mathbf{lined}}\left(4,i\right)$ in fbnd, i.e.,
${\mathbf{fbnd}}\left({\mathbf{lined}}\left(4,i\right),{\mathbf{coorch}}\left(1,{\mathbf{lined}}\left(2,i\right)\right),{\mathbf{coorch}}\left(2,{\mathbf{lined}}\left(2,i\right)\right),{\mathbf{user}},{\mathbf{user}}\right)=0$;
${\mathbf{fbnd}}\left({\mathbf{lined}}\left(4,\mathit{i}\right),{\mathbf{coorch}}\left(1,{\mathbf{lined}}\left(3,\mathit{i}\right)\right),{\mathbf{coorch}}\left(2,{\mathbf{lined}}\left(3,\mathit{i}\right)\right),{\mathbf{user}},{\mathbf{user}}\right)=0$, for $\mathit{i}=1,2,\dots ,{\mathbf{nlines}}$.
For all lines described as polygonal arcs (lines with ${\mathbf{lined}}\left(4,\mathit{i}\right)<0$, for $\mathit{i}=1,2,\dots ,{\mathbf{nlines}}$) the sets of intermediate points (i.e.,$\left[-{\mathbf{lined}}\left(4,i\right):-{\mathbf{lined}}\left(4,i\right)+{\mathbf{lined}}\left(1,i\right)-3\right]$ for all $i$ such that ${\mathbf{lined}}\left(4,i\right)<0$) are not overlapping. This can be expressed as:
 $-lined4i + lined1i - 3 = ∑ i,lined4i<0 lined1i - 2$
or
 $-lined4i + lined1i - 2 = -lined4j ,$
for a $j$ such that $j=1,2,\dots ,{\mathbf{nlines}}$, $j\ne i$ and ${\mathbf{lined}}\left(4,j\right)<0$.
3:     $\mathrm{fbnd}$ – function handle or string containing name of m-file
fbnd must be supplied to calculate the value of the function which describes the curve $\left\{\left(x,y\right)\in {ℝ}^{2}\text{; such that ​}f\left(x,y\right)=0\right\}$ on segments of the boundary for which ${\mathbf{lined}}\left(4,i\right)>0$. If there are no boundaries for which ${\mathbf{lined}}\left(4,i\right)>0$ fbnd will never be referenced by nag_mesh_2d_gen_boundary (d06ba) and fbnd may be the string 'd06bad'. (nag_mesh_2d_gen_boundary_dummy_fbnd (d06bad) is included in the NAG Toolbox.)
[result, user] = fbnd(ii, x, y, user)

Input Parameters

1:     $\mathrm{ii}$int64int32nag_int scalar
${\mathbf{lined}}\left(4,i\right)$, the reference index of the line (portion of the contour) $i$ described.
2:     $\mathrm{x}$ – double scalar
3:     $\mathrm{y}$ – double scalar
The values of $x$ and $y$ at which $f\left(x,y\right)$ is to be evaluated.
4:     $\mathrm{user}$ – Any MATLAB object
fbnd is called from nag_mesh_2d_gen_boundary (d06ba) with the object supplied to nag_mesh_2d_gen_boundary (d06ba).

Output Parameters

1:     $\mathrm{result}$ – double scalar
The value of $f\left(x,y\right)$ at the specified point.
2:     $\mathrm{user}$ – Any MATLAB object
4:     $\mathrm{crus}\left(2,{\mathbf{sdcrus}}\right)$ – double array
The coordinates of the intermediate points for polygonal arc lines. For a line $i$ defined as a polygonal arc (i.e., ${\mathbf{lined}}\left(4,i\right)<0$), if $p=-{\mathbf{lined}}\left(4,i\right)$, then ${\mathbf{crus}}\left(1,\mathit{k}\right)$, for $\mathit{k}=p,\dots ,p+{\mathbf{lined}}\left(1,i\right)-3$, must contain the $x$ coordinate of the consecutive intermediate points for this line. Similarly ${\mathbf{crus}}\left(2,\mathit{k}\right)$, for $\mathit{k}=p,\dots ,p+{\mathbf{lined}}\left(1,i\right)-3$, must contain the corresponding $y$ coordinate.
5:     $\mathrm{rate}\left({\mathbf{nlines}}\right)$ – double array
${\mathbf{rate}}\left(\mathit{i}\right)$ is the geometric progression ratio between the points to be generated on the line $\mathit{i}$, for $\mathit{i}=1,2,\dots ,m$ and ${\mathbf{lined}}\left(4,i\right)\ge 0$.
If ${\mathbf{lined}}\left(4,i\right)<0$, ${\mathbf{rate}}\left(i\right)$ is not referenced.
Constraint: if ${\mathbf{lined}}\left(4,i\right)\ge 0$, ${\mathbf{rate}}\left(\mathit{i}\right)>0.0$, for $\mathit{i}=1,2,\dots ,{\mathbf{nlines}}$.
6:     $\mathrm{nlcomp}\left({\mathbf{ncomp}}\right)$int64int32nag_int array
$\left|{\mathbf{nlcomp}}\left(k\right)\right|$ is the number of line segments in component $k$ of the contour. The line $i$ of component $k$ runs in the direction ${\mathbf{lined}}\left(2,i\right)$ to ${\mathbf{lined}}\left(3,i\right)$ if ${\mathbf{nlcomp}}\left(k\right)>0$, and in the opposite direction otherwise; for $k=1,2,\dots ,n$.
Constraints:
• $1\le \left|{\mathbf{nlcomp}}\left(\mathit{k}\right)\right|\le {\mathbf{nlines}}$, for $\mathit{k}=1,2,\dots ,{\mathbf{ncomp}}$;
• $\sum _{k=1}^{n}\left|{\mathbf{nlcomp}}\left(k\right)\right|={\mathbf{nlines}}$.
7:     $\mathrm{lcomp}\left({\mathbf{nlines}}\right)$int64int32nag_int array
lcomp must contain the list of line numbers for the each component of the boundary. Specifically, the line numbers for the $\mathit{k}$th component of the boundary, for $\mathit{k}=1,2,\dots ,{\mathbf{ncomp}}$, must be in elements $l1-1$ to $l2-1$ of lcomp, where $l2=\sum _{i=1}^{k}\left|{\mathbf{nlcomp}}\left(i\right)\right|$ and $l1=l2+1-\left|{\mathbf{nlcomp}}\left(\mathit{k}\right)\right|$.
Constraint: ${\mathbf{lcomp}}$ must hold a valid permutation of the integers $\left[1,{\mathbf{nlines}}\right]$.
8:     $\mathrm{nvmax}$int64int32nag_int scalar
The maximum number of the boundary mesh vertices to be generated.
Constraint: ${\mathbf{nvmax}}\ge {\mathbf{nlines}}$.
9:     $\mathrm{nedmx}$int64int32nag_int scalar
The maximum number of boundary edges in the boundary mesh to be generated.
Constraint: ${\mathbf{nedmx}}\ge 1$.
10:   $\mathrm{itrace}$int64int32nag_int scalar
The level of trace information required from nag_mesh_2d_gen_boundary (d06ba).
${\mathbf{itrace}}=0$ or ${\mathbf{itrace}}<-1$
No output is generated.
${\mathbf{itrace}}=1$
Output from the boundary mesh generator is printed on the current advisory message unit (see nag_file_set_unit_advisory (x04ab)). This output contains the input information of each line and each connected component of the boundary.
${\mathbf{itrace}}=-1$
An analysis of the output boundary mesh is printed on the current advisory message unit. This analysis includes the orientation (clockwise or anticlockwise) of each connected component of the boundary. This information could be of interest to you, especially if an interior meshing is carried out using the output of this function, calling either nag_mesh_2d_gen_inc (d06aa), nag_mesh_2d_gen_delaunay (d06ab) or nag_mesh_2d_gen_front (d06ac).
${\mathbf{itrace}}>1$
The output is similar to that produced when ${\mathbf{itrace}}=1$, but the coordinates of the generated vertices on the boundary are also output.
You are advised to set ${\mathbf{itrace}}=0$, unless you are experienced with finite element mesh generation.

### Optional Input Parameters

1:     $\mathrm{nlines}$int64int32nag_int scalar
Default: the dimension of the arrays coorch, lined, rate, lcomp. (An error is raised if these dimensions are not equal.)
$m$, the number of lines that define the boundary of the closed connected subdomain (this equals the number of characteristic points which separate the entire boundary $\partial \Omega$ into lines).
Constraint: ${\mathbf{nlines}}\ge 1$.
2:     $\mathrm{sdcrus}$int64int32nag_int scalar
Default: the second dimension of the array crus.
The second dimension of the array crus.
Constraint: ${\mathbf{sdcrus}}\ge \sum _{\left\{i,{\mathbf{lined}}\left(4,i\right)<0\right\}}\phantom{\rule{0.25em}{0ex}}\left\{{\mathbf{lined}}\left(1,i\right)-2\right\}$.
3:     $\mathrm{ncomp}$int64int32nag_int scalar
Default: the dimension of the array nlcomp.
$n$, the number of separately connected components of the boundary.
Constraint: ${\mathbf{ncomp}}\ge 1$.
4:     $\mathrm{user}$ – Any MATLAB object
user is not used by nag_mesh_2d_gen_boundary (d06ba), but is passed to fbnd. Note that for large objects it may be more efficient to use a global variable which is accessible from the m-files than to use user.

### Output Parameters

1:     $\mathrm{nvb}$int64int32nag_int scalar
The total number of boundary mesh vertices generated.
2:     $\mathrm{coor}\left(2,{\mathbf{nvmax}}\right)$ – double array
${\mathbf{coor}}\left(1,\mathit{i}\right)$ will contain the $x$ coordinate of the $\mathit{i}$th boundary mesh vertex generated, for $\mathit{i}=1,2,\dots ,{\mathbf{nvb}}$; while ${\mathbf{coor}}\left(2,i\right)$ will contain the corresponding $y$ coordinate.
3:     $\mathrm{nedge}$int64int32nag_int scalar
The total number of boundary edges in the boundary mesh.
4:     $\mathrm{edge}\left(3,{\mathbf{nedmx}}\right)$int64int32nag_int array
The specification of the boundary edges. ${\mathbf{edge}}\left(1,j\right)$ and ${\mathbf{edge}}\left(2,j\right)$ will contain the vertex numbers of the two end points of the $j$th boundary edge. ${\mathbf{edge}}\left(3,j\right)$ is a reference number for the $j$th boundary edge and
• ${\mathbf{edge}}\left(3,j\right)={\mathbf{lined}}\left(4,i\right)$, where $i$ and $j$ are such that the $j$th edges is part of the $i$th line of the boundary and ${\mathbf{lined}}\left(4,i\right)\ge 0$;
• ${\mathbf{edge}}\left(3,j\right)=100+\left|{\mathbf{lined}}\left(4,i\right)\right|$, where $i$ and $j$ are such that the $j$th edges is part of the $i$th line of the boundary and ${\mathbf{lined}}\left(4,i\right)<0$.
5:     $\mathrm{user}$ – Any MATLAB object
6:     $\mathrm{ifail}$int64int32nag_int scalar
${\mathbf{ifail}}={\mathbf{0}}$ unless the function detects an error (see Error Indicators and Warnings).

## Error Indicators and Warnings

Errors or warnings detected by the function:
${\mathbf{ifail}}=1$
 On entry, ${\mathbf{nlines}}<1$; or ${\mathbf{nvmax}}<{\mathbf{nlines}}$; or ${\mathbf{nedmx}}<1$; or ${\mathbf{ncomp}}<1$; or $\mathit{lrwork}<2×\left({\mathbf{nlines}}+{\mathbf{sdcrus}}\right)+2×{\mathrm{max}}_{i=1,2,\dots ,m}\left\{{\mathbf{lined}}\left(1,i\right)\right\}×{\mathbf{nlines}}$; or $\mathit{liwork}<\sum _{\left\{i,{\mathbf{lined}}\left(4,i\right)<0\right\}}\phantom{\rule{0.25em}{0ex}}\left\{{\mathbf{lined}}\left(1,i\right)-2\right\}+8×{\mathbf{nlines}}+{\mathbf{nvmax}}+3×\phantom{\rule{0ex}{0ex}}{\mathbf{nedmx}}+2×{\mathbf{sdcrus}}$; or ${\mathbf{sdcrus}}<\sum _{\left\{i,{\mathbf{lined}}\left(4,i\right)<0\right\}}\phantom{\rule{0.25em}{0ex}}\left\{{\mathbf{lined}}\left(1,i\right)-2\right\}$; or ${\mathbf{rate}}\left(i\right)<0.0$ for some $i=1,2,\dots ,{\mathbf{nlines}}$ with ${\mathbf{lined}}\left(4,i\right)\ge 0$; or ${\mathbf{lined}}\left(1,i\right)<2$ for some $i=1,2,\dots ,{\mathbf{nlines}}$; or ${\mathbf{lined}}\left(2,i\right)<1$ or ${\mathbf{lined}}\left(2,i\right)>{\mathbf{nlines}}$ for some $i=1,2,\dots ,{\mathbf{nlines}}$; or ${\mathbf{lined}}\left(3,i\right)<1$ or ${\mathbf{lined}}\left(3,i\right)>{\mathbf{nlines}}$ for some $i=1,2,\dots ,{\mathbf{nlines}}$; or ${\mathbf{lined}}\left(2,i\right)={\mathbf{lined}}\left(3,i\right)$ for some $i=1,2,\dots ,{\mathbf{nlines}}$; or ${\mathbf{nlcomp}}\left(k\right)=0$, or $\left|{\mathbf{nlcomp}}\left(k\right)\right|>{\mathbf{nlines}}$ for a $k=1,2,\dots ,{\mathbf{ncomp}}$; or $\sum _{k=1}^{n}\left|{\mathbf{nlcomp}}\left(k\right)\right|\ne {\mathbf{nlines}}$; or lcomp does not represent a valid permutation of the integers in $\left[1,{\mathbf{nlines}}\right]$; or one of the end points for a line $\mathit{i}$ described by the user-supplied function (lines with ${\mathbf{lined}}\left(4,\mathit{i}\right)>0$, for $\mathit{i}=1,2,\dots ,{\mathbf{nlines}}$) does not belong to the corresponding curve in fbnd; or the intermediate points for the lines described as polygonal arcs (lines with ${\mathbf{lined}}\left(4,\mathit{i}\right)<0$, for $\mathit{i}=1,2,\dots ,{\mathbf{nlines}}$) are overlapping.
${\mathbf{ifail}}=2$
An error has occurred during the generation of the boundary mesh. It appears that nedmx is not large enough, so you are advised to increase the value of nedmx.
${\mathbf{ifail}}=3$
An error has occurred during the generation of the boundary mesh. It appears that nvmax is not large enough, so you are advised to increase the value of nvmax.
${\mathbf{ifail}}=4$
An error has occurred during the generation of the boundary mesh. Check the definition of each line (the argument lined) and each connected component of the boundary (the arguments nlcomp, and lcomp, as well as the coordinates of the characteristic points. Setting ${\mathbf{itrace}}>0$ may provide more details.
${\mathbf{ifail}}=-99$
${\mathbf{ifail}}=-399$
Your licence key may have expired or may not have been installed correctly.
${\mathbf{ifail}}=-999$
Dynamic memory allocation failed.

## Accuracy

Not applicable.

The boundary mesh generation technique in this function has a ‘tree’ structure. The boundary should be partitioned into geometrically simple segments (straight lines or curves) delimited by characteristic points. Then, the lines should be assembled into connected components of the boundary domain.
Using this strategy, the inputs to that function can be built up, following the requirements stated in Arguments:
The example below details the use of this strategy.

## Example

The NAG logo is taken as an example of a geometry with holes. The boundary has been partitioned in $40$ lines characteristic points; including $4$ for the exterior boundary and $36$ for the logo itself. All line geometry specifications have been considered, see the description of lined, including $4$ lines defined as polygonal arc, $4$ defined by fbnd and all the others are straight lines.
```function d06ba_example

fprintf('d06ba example results\n\n');

% Desciption of Nag Logo boundary in terms of arguments to d06ba
nlines = 45;
line = zeros(4,nlines,'int64');
line(1:4,1:nlines) = [ 15  1  2  1;    15  2  3  1;    15  3  4  1;
15  4  1  1;     4  6  5 -1;    10 10  6  0;
10 14 10  2;    10  7 14  0;     4  8  7  0;
10 13  8  0;    10 13  9  3;    10 12  9  0;
4 11 12  0;    15  5 11  0;    15 26 15  4;
10 26 25  0;     4 25 24  0;     4 24 23  0;
4 23 22  0;    10 21 22  6;    10 20 21  6;
10 19 20  6;     4 19 18  0;     5 18 17  0;
15 17 16  5;     4 16 15  0;     4 27 28  0;
7 28 30  8;     7 30 32  8;     7 32 34  8;
6 36 34 10;     6 38 36 12;    10 40 38 13;
10 42 40 13;     8 44 42 13;     4 44 45  0;
4 45 43  0;     4 43 41  0;     6 39 41 13;
10 37 39 13;     6 37 35 11;     6 35 33  9;
10 31 33  7;    10 29 31  7;    10 27 29  7]';
coorch = zeros(2,nlines);
coorch(1,:) = ...
[ 9.5 33.0  9.5 -14.0                                                 ...
-4.0 -2.0  2.0   4.0 -2.0    -2.0  -4.0 -2.0     4.0   2.0           ...
5.0  6.0 11.0  11.0  8.5     5.0   8.5  11.5    13.0 14.0 13.0 13.0 ...
14.0 15.5 17.5  17.5 21.0    19.5  17.5  17.5    16.0 14.5           ...
17.0 16.0    20.0  14.0  19.3142 17.0 20.5 18.7249 19.5];
coorch(2,:) = ...
[-3.0  6.5 16.0   6.5                                                  ...
3.0  3.0  3.0   3.0 11.0    10.0  11.5  12.0    11.0 10.5            ...
11.0 10.0 10.0   8.5  8.5     5.75  3.0   4.3335  3.0  3.75 4.75 10.5 ...
2.5  2.5  0.0   1.0  2.5     2.5   5.0   4.0     5.5  5.5            ...
6.5  6.6573  9.25  9.25 11.0    12.0 11.5  11.5 12.0];

crus = zeros(2, 2);
crus(1,1:2)=[-8,-10]/3;
crus(2,1:2) = [3,3];
rate = ones(nlines,1);
rate(1:4,1) = [0.95;1.05;0.95;1.05];
nlcomp = int64([4 10 12 19]);
lcomp = zeros(nlines,1,'int64');
lcomp(1:nlines,1) = [  1  2  3  4                         ...
14 13 12 11 10  9  8  7  6  5       ...
18 19 20 21 22 23 24 25 26 15 16 17 ...
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45];
nvmax = int64(5000);
nedmx = int64(1000);
itrace = int64(-1);
user = [23.5; 9.5; 9.5; 6.5];

% Generate boundary mesh
[nvb, coor, nedge, edge, user, ifail] = ...
d06ba( ...
coorch, line, @fbnd, crus, rate, nlcomp, lcomp, nvmax, ...
nedmx, itrace, 'user', user);

i = int64(0);
k = int64(0);
fig1 = figure;
hold on;
title('Boundary Mesh');

for seg = 1:4
i0 = i;
for j = k+1:k+nlcomp(seg)
i = i + line(1,lcomp(j,1));
end
k = k + nlcomp(seg);
i = i - nlcomp(seg);
segl = i - i0;
for j = 1:segl
segx(j) = coor(1,i0+j);
segy(j) = coor(2,i0+j);
end
segx(segl+1) = segx(1);
segy(segl+1) = segy(1);
plot(segx(1:segl+1),segy(1:segl+1));
end
axis equal tight;

% generate Delauney-Voronoi mesh using logo boundary
npropa = int64(1);
itrace = int64(0);
weight = [];
[nv, nelt, coor, conn, ifail] = ...
d06ab( ...
nvb, edge, coor, weight, npropa, itrace,'nedge',nedge);

% Plot mesh
fig2 = figure;
triplot(transpose(double(conn(:,1:nelt))), coor(1,:), coor(2,:));
title('Delauney-Voronoi Mesh');
axis equal tight;

fprintf('\nComplete mesh characteristics for Delauney-Voronoi mesh:\n');
fprintf('Number of vertices    = %4d\n',nv);
fprintf('Number of elements    = %4d\n',nelt);

% generate 2D advancing front mesh on logo
[nv, nelt, coor, conn, ifail] = ...
d06ac( ...
nvb, edge(:,1:nedge), coor, weight, itrace);

% Plot mesh
fig3 = figure;
triplot(transpose(double(conn(:,1:nelt))), coor(1,:), coor(2,:));
axis equal tight;

fprintf('\nComplete mesh characteristics for advancing front mesh:\n');
fprintf('Number of vertices    = %4d\n',nv);
fprintf('Number of elements    = %4d\n',nelt);

function [result, user] = fbnd(i, x, y, user)
xa = user(1);
xb = user(2);
x0 = user(3);
y0 = user(4);

result = 0;
if (i == 1)
% line 1,2,3, and 4: ellipse centred in (x0,y0) with
% xa and xb as coefficients
result = ((x-x0)/xa)^2 + ((y-y0)/xb)^2 - 1;
elseif (i == 2)
% line 24, 27, 33 and 38 are a circle centred in (x0,y0)
x0 = 0.5;
y0 = 6.25;
result = (x-x0)^2 + (y-y0)^2 - radius2;
elseif (i == 3)
x0 = 1;
y0 = 4;
result = (x-x0)^2 + (y-y0)^2 - radius2;
elseif (i == 4)
x0 = 8.5;
y0 = 2.75;
result = (x-x0)^2 + (y-y0)^2 - radius2;
elseif (i == 5)
x0 = 8.5;
y0 = 4;
result = (x-x0)^2 + (y-y0)^2 - radius2;
elseif (i == 6)
x0 = 8.5;
y0 = 5.75;
result = ((x-x0)/3.5)^2 + ((y-y0)/2.75)^2 - 1;
elseif (i == 7)
x0 = 17.5;
y0 = 2.5;
result = ((x-x0)/3.5)^2 + ((y-y0)/2.5)^2 - 1;
elseif (i == 8)
x0 = 17.5;
y0 = 2.5;
result = ((x-x0)/2)^2 + ((y-y0)/1.5)^2 - 1;
elseif (i == 9)
x0 = 17.5;
y0 = 5.5;
result = ((x-x0)/1.5)^2 + ((y-y0)/0.5)^2 - 1;
elseif (i == 10)
x0 = 17.5;
y0 = 5.5;
result = ((x-x0)/3)^2 + ((y-y0)/1.5)^2 - 1;
elseif (i == 11)
x0 = 17.0;
y0 = 5.5;
result = ((x-x0))^2 + ((y-y0))^2 - 1;
elseif (i == 12)
x0 = 16;
y0 = 5.5;
result = ((x-x0)/1.5)^2 + ((y-y0)/1.1573)^2 - 1;
elseif (i == 13)
x0 = 17;
y0 = 9.25;
result = ((x-x0)/3)^2 + ((y-y0)/2.75)^2 - 1;
end
```
```d06ba example results

Analysis of the boundary created:
The boundary mesh contains    332 vertices and    332 edges
There are      4 components comprising the boundary:
The  1-st component contains      4 lines in anticlockwise orientation
The  2-nd component contains     10 lines in     clockwise orientation
The  3-rd component contains     12 lines in anticlockwise orientation
The  4-th component contains     19 lines in     clockwise orientation

Complete mesh characteristics for Delauney-Voronoi mesh:
Number of vertices    =  904
Number of elements    = 1480

Complete mesh characteristics for advancing front mesh:
Number of vertices    =  924
Number of elements    = 1520
```