# NAG Library Function Document

## 1Purpose

nag_mesh2d_trans (d06dac) is a utility which performs an affine transformation of a given mesh.

## 2Specification

 #include #include
 void nag_mesh2d_trans (Integer mode, Integer nv, Integer nedge, Integer nelt, Integer ntrans, const Integer itype[], const double trans[], double coori[], Integer edgei[], Integer conni[], double cooro[], Integer edgeo[], Integer conno[], Integer itrace, const char *outfile, NagError *fail)

## 3Description

nag_mesh2d_trans (d06dac) generates a mesh (coordinates, triangle/vertex connectivities and edge/vertex connectivities) resulting from an affine transformation of a given mesh. This transformation is of the form $Y=A×X+B$, where
• $Y$, $X$ and $B$ are in ${ℝ}^{2}$, and
• $A$ is a real $2$ by $2$ matrix.
Such a transformation includes a translation, a rotation, a scale reduction or increase, a symmetric transformation with respect to a user-supplied line, a user-supplied analytic transformation, or a composition of several transformations.
This function is partly derived from material in the MODULEF package from INRIA (Institut National de Recherche en Informatique et Automatique).

None.

## 5Arguments

1:    $\mathbf{mode}$IntegerInput
On entry: if ${\mathbf{mode}}=1$, the arguments coori, edgei and conni are overwritten on exit by the output values described in cooro, edgeo and conno respectively. In this case cooro, edgeo and conno are not referenced, and you can save storage space.
If ${\mathbf{mode}}\ne 1$, no such aliasing is assumed.
2:    $\mathbf{nv}$IntegerInput
On entry: the total number of vertices in the input mesh.
Constraint: ${\mathbf{nv}}\ge 3$.
3:    $\mathbf{nedge}$IntegerInput
On entry: the number of the boundary or interface edges in the input mesh.
Constraint: ${\mathbf{nedge}}\ge 1$.
4:    $\mathbf{nelt}$IntegerInput
On entry: the number of triangles in the input mesh.
Constraint: ${\mathbf{nelt}}\le 2×{\mathbf{nv}}-1$.
5:    $\mathbf{ntrans}$IntegerInput
On entry: the number of transformations of the input mesh.
Constraint: ${\mathbf{ntrans}}\ge 1$.
6:    $\mathbf{itype}\left[{\mathbf{ntrans}}\right]$const IntegerInput
On entry: ${\mathbf{itype}}\left[\mathit{i}-1\right]$, for $\mathit{i}=1,2,\dots ,{\mathbf{ntrans}}$, indicates the type of each transformation as follows:
${\mathbf{itype}}\left[i-1\right]=0$
Identity transformation.
${\mathbf{itype}}\left[i-1\right]=1$
Translation.
${\mathbf{itype}}\left[i-1\right]=2$
Symmetric transformation with respect to a user-supplied line.
${\mathbf{itype}}\left[i-1\right]=3$
Rotation.
${\mathbf{itype}}\left[i-1\right]=4$
Scaling.
${\mathbf{itype}}\left[i-1\right]=10$
User-supplied analytic transformation.
Note that the transformations are applied in the order described in itype.
Constraint: ${\mathbf{itype}}\left[\mathit{i}-1\right]=0$, $1$, $2$, $3$, $4$ or $10$, for $\mathit{i}=1,2,\dots ,{\mathbf{ntrans}}$.
7:    $\mathbf{trans}\left[6×{\mathbf{ntrans}}\right]$const doubleInput
On entry: the arguments for each transformation. For $i=1,2,\dots ,{\mathbf{ntrans}}$, ${\mathbf{trans}}\left[\left(i-1\right)×6\right]$ to ${\mathbf{trans}}\left[\left(i-1\right)×6+5\right]$ contain the arguments of the $i$th transformation.
If ${\mathbf{itype}}\left[i-1\right]=0$, elements ${\mathbf{trans}}\left[\left(i-1\right)×6\right]$ to ${\mathbf{trans}}\left[\left(i-1\right)×6+5\right]$ are not referenced.
If ${\mathbf{itype}}\left[i-1\right]=1$, the translation vector is $\stackrel{\to }{u}=\left(\begin{array}{c}a\\ b\end{array}\right)$, where $a={\mathbf{trans}}\left[\left(i-1\right)×6\right]$ and $b={\mathbf{trans}}\left[\left(i-1\right)×6+1\right]$, while elements ${\mathbf{trans}}\left[\left(i-1\right)×6+2\right]$ to ${\mathbf{trans}}\left[\left(i-1\right)×6+5\right]$ are not referenced.
If ${\mathbf{itype}}\left[i-1\right]=2$, the user-supplied line is the curve {$\left(x,y\right)\in {ℝ}^{2}$; such that $ax+by+c=0$}, where $a={\mathbf{trans}}\left[\left(i-1\right)×6\right]$, $b={\mathbf{trans}}\left[\left(i-1\right)×6+1\right]$ and $c={\mathbf{trans}}\left[\left(i-1\right)×6+2\right]$, while elements ${\mathbf{trans}}\left[\left(i-1\right)×6+3\right]$ to ${\mathbf{trans}}\left[\left(i-1\right)×6+5\right]$ are not referenced.
If ${\mathbf{itype}}\left[i-1\right]=3$, the centre of the rotation is $\left({x}_{0},{y}_{0}\right)$ where ${x}_{0}={\mathbf{trans}}\left[\left(i-1\right)×6\right]$ and ${y}_{0}={\mathbf{trans}}\left[\left(i-1\right)×6+1\right]$, $\theta ={\mathbf{trans}}\left[\left(i-1\right)×6+2\right]$ is its angle in degrees, while elements ${\mathbf{trans}}\left[\left(i-1\right)×6+3\right]$ to ${\mathbf{trans}}\left[\left(i-1\right)×6+5\right]$ are not referenced.
If ${\mathbf{itype}}\left[i-1\right]=4$, $a={\mathbf{trans}}\left[\left(i-1\right)×6\right]$ is the scaling coefficient in the $x$-direction, $b={\mathbf{trans}}\left[\left(i-1\right)×6+1\right]$ is the scaling coefficient in the $y$-direction, and $\left({x}_{0},{y}_{0}\right)$ are the scaling centre coordinates, with ${x}_{0}={\mathbf{trans}}\left[\left(i-1\right)×6+2\right]$ and ${y}_{0}={\mathbf{trans}}\left[\left(i-1\right)×6+3\right]$; while elements ${\mathbf{trans}}\left[\left(i-1\right)×6+4\right]$ to ${\mathbf{trans}}\left[\left(i-1\right)×6+5\right]$ are not referenced.
If ${\mathbf{itype}}\left[i-1\right]=10$, the user-supplied analytic affine transformation $Y=A×X+B$ is such that $A={\left({a}_{kl}\right)}_{1\le k,l\le 2}$ and $B={\left({b}_{k}\right)}_{1\le k\le 2}$ where${a}_{kl}={\mathbf{trans}}\left[\left(i-1\right)×6+2×\left(k-1\right)+l-1\right]$, and ${b}_{k}={\mathbf{trans}}\left[\left(i-1\right)×6+4+k-1\right]$ with $k,l=1,2$.
8:    $\mathbf{coori}\left[2×{\mathbf{nv}}\right]$doubleInput/Output
Note: the $\left(i,j\right)$th element of the matrix is stored in ${\mathbf{coori}}\left[\left(j-1\right)×2+i-1\right]$.
On entry: ${\mathbf{coori}}\left[\left(\mathit{i}-1\right)×2\right]$ contains the $x$ coordinate of the $\mathit{i}$th vertex of the input mesh, for $\mathit{i}=1,2,\dots ,{\mathbf{nv}}$; while ${\mathbf{coori}}\left[\left(i-1\right)×2+1\right]$ contains the corresponding $y$ coordinate.
On exit: if ${\mathbf{mode}}=1$, coori is assumed to hold the values of cooro.
9:    $\mathbf{edgei}\left[3×{\mathbf{nedge}}\right]$IntegerInput/Output
Note: the $\left(i,j\right)$th element of the matrix is stored in ${\mathbf{edgei}}\left[\left(j-1\right)×3+i-1\right]$.
On entry: the specification of the boundary or interface edges. ${\mathbf{edgei}}\left[\left(j-1\right)×3\right]$ and ${\mathbf{edgei}}\left[\left(j-1\right)×3+1\right]$ contain the vertex numbers of the two end points of the $j$th boundary edge. ${\mathbf{edgei}}\left[\left(j-1\right)×3+2\right]$ is a user-supplied tag for the $j$th boundary edge. Note that the edge vertices are numbered from $1$ to nv.
Constraint: $1\le {\mathbf{edgei}}\left[\left(\mathit{j}-1\right)×3+\mathit{i}-1\right]\le {\mathbf{nv}}$ and ${\mathbf{edgei}}\left[\left(\mathit{j}-1\right)×3\right]\ne {\mathbf{edgei}}\left[\left(\mathit{j}-1\right)×3+1\right]$, for $\mathit{i}=1,2$ and $\mathit{j}=1,2,\dots ,{\mathbf{nedge}}$.
On exit: if ${\mathbf{mode}}=1$, edgei holds the output values described in edgeo.
10:  $\mathbf{conni}\left[3×{\mathbf{nelt}}\right]$IntegerInput/Output
Note: the $\left(i,j\right)$th element of the matrix is stored in ${\mathbf{conni}}\left[\left(j-1\right)×3+i-1\right]$.
On entry: the connectivity of the input mesh between triangles and vertices. For each triangle $\mathit{j}$, ${\mathbf{conni}}\left[\left(\mathit{j}-1\right)×3+\mathit{i}-1\right]$ gives the indices of its three vertices (in anticlockwise order), for $\mathit{i}=1,2,3$ and $\mathit{j}=1,2,\dots ,{\mathbf{nelt}}$. Note that the mesh vertices are numbered from $1$ to nv.
Constraints:
• $1\le {\mathbf{conni}}\left[\left(j-1\right)×3+i-1\right]\le {\mathbf{nv}}$;
• ${\mathbf{conni}}\left[\left(j-1\right)×3\right]\ne {\mathbf{conni}}\left[\left(j-1\right)×3+1\right]$;
• ${\mathbf{conni}}\left[\left(\mathit{j}-1\right)×3\right]\ne {\mathbf{conni}}\left[\left(\mathit{j}-1\right)×3+2\right]$ and ${\mathbf{conni}}\left[\left(\mathit{j}-1\right)×3+1\right]\ne {\mathbf{conni}}\left[\left(\mathit{j}-1\right)×3+2\right]$, for $\mathit{i}=1,2,3$ and $\mathit{j}=1,2,\dots ,{\mathbf{nelt}}$.
On exit: if ${\mathbf{mode}}=1$, conni holds the output values described in conno.
11:  $\mathbf{cooro}\left[\mathit{dim}\right]$doubleOutput
Note: the dimension, dim, of the array cooro must be at least
• if ${\mathbf{mode}}\ne 1$$2×{\mathbf{nv}}$;
• otherwise cooro is not referenced.
The $\left(i,j\right)$th element of the matrix is stored in ${\mathbf{cooro}}\left[\left(j-1\right)×2+i-1\right]$.
On exit: ${\mathbf{cooro}}\left[\left(\mathit{i}-1\right)×2\right]$ will contain the $x$ coordinate of the $\mathit{i}$th vertex of the transformed mesh, for $\mathit{i}=1,2,\dots ,{\mathbf{nv}}$; while ${\mathbf{cooro}}\left[\left(i-1\right)×2+1\right]$ will contain the corresponding $y$ coordinate. If ${\mathbf{mode}}=1$ the results are instead overwritten in coori.
12:  $\mathbf{edgeo}\left[\mathit{dim}\right]$IntegerOutput
Note: the dimension, dim, of the array edgeo must be at least
• if ${\mathbf{mode}}\ne 1$$3×{\mathbf{nedge}}$;
• otherwise edgeo is not referenced.
The $\left(i,j\right)$th element of the matrix is stored in ${\mathbf{edgeo}}\left[\left(j-1\right)×3+i-1\right]$.
On exit: the specification of the boundary or interface edges of the transformed mesh. If the number of symmetric transformations is even or zero then${\mathbf{edgeo}}\left[\left(\mathit{j}-1\right)×3+\mathit{i}-1\right]={\mathbf{edgei}}\left[\left(\mathit{j}-1\right)×3+\mathit{i}-1\right]$, for $\mathit{i}=1,2,3$ and $\mathit{j}=1,2,\dots ,{\mathbf{nedge}}$; otherwise ${\mathbf{edgeo}}\left[\left(\mathit{j}-1\right)×3\right]={\mathbf{edgei}}\left[\left(\mathit{j}-1\right)×3+1\right]$,${\mathbf{edgeo}}\left[\left(\mathit{j}-1\right)×3+1\right]={\mathbf{edgei}}\left[\left(\mathit{j}-1\right)×3\right]$ and ${\mathbf{edgeo}}\left[\left(\mathit{j}-1\right)×3+2\right]={\mathbf{edgei}}\left[\left(\mathit{j}-1\right)×3+2\right]$, for $\mathit{j}=1,2,\dots ,{\mathbf{nedge}}$. If ${\mathbf{mode}}=1$ the results are overwritten in edgei.
13:  $\mathbf{conno}\left[\mathit{dim}\right]$IntegerOutput
Note: the dimension, dim, of the array conno must be at least
• if ${\mathbf{mode}}\ne 1$$3×{\mathbf{nelt}}$;
• $\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,3\right)$ otherwise.
The $\left(i,j\right)$th element of the matrix is stored in ${\mathbf{conno}}\left[\left(j-1\right)×3+i-1\right]$.
On exit: the connectivity of the transformed mesh between triangles and vertices. If the number of symmetric transformations is even or zero then${\mathbf{conno}}\left[\left(\mathit{j}-1\right)×3+\mathit{i}-1\right]={\mathbf{conni}}\left[\left(\mathit{j}-1\right)×3+\mathit{i}-1\right]$, for $\mathit{i}=1,2,3$ and $\mathit{j}=1,2,\dots ,{\mathbf{nelt}}$; otherwise ${\mathbf{conno}}\left[\left(\mathit{j}-1\right)×3\right]={\mathbf{conni}}\left[\left(\mathit{j}-1\right)×3\right]$, ${\mathbf{conno}}\left[\left(\mathit{j}-1\right)×3+1\right]={\mathbf{conni}}\left[\left(\mathit{j}-1\right)×3+2\right]$ and ${\mathbf{conno}}\left[\left(\mathit{j}-1\right)×3+2\right]={\mathbf{conni}}\left[\left(\mathit{j}-1\right)×3+1\right]$, for $\mathit{j}=1,2,\dots ,{\mathbf{nelt}}$. Note that the mesh vertices are numbered from $1$ to nv. If ${\mathbf{mode}}=1$ the results are instead overwritten in conni.
14:  $\mathbf{itrace}$IntegerInput
On entry: the level of trace information required from nag_mesh2d_trans (d06dac).
${\mathbf{itrace}}\le 0$
No output is generated.
${\mathbf{itrace}}\ge 1$
Details of each transformation, the matrix $A$ and the vector $B$ of the final transformation, which is the composition of all the ntrans transformations, are printed.
15:  $\mathbf{outfile}$const char *Input
On entry: the name of a file to which diagnostic output will be directed. If outfile is NULL the diagnostic output will be directed to standard output.
16:  $\mathbf{fail}$NagError *Input/Output
The NAG error argument (see Section 3.7 in How to Use the NAG Library and its Documentation).

## 6Error Indicators and Warnings

NE_ALLOC_FAIL
Dynamic memory allocation failed.
See Section 2.3.1.2 in How to Use the NAG Library and its Documentation for further information.
On entry, argument $〈\mathit{\text{value}}〉$ had an illegal value.
NE_INT
On entry, ${\mathbf{nedge}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{nedge}}\ge 1$.
On entry, ${\mathbf{ntrans}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{ntrans}}>0$.
On entry, ${\mathbf{ntrans}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{ntrans}}\ge 1$.
On entry, ${\mathbf{nv}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{nv}}\ge 3$.
NE_INT_2
On entry, ${\mathbf{itype}}\left[\mathit{I}-1\right]=〈\mathit{\text{value}}〉$ and $\mathit{I}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{itype}}\left[\mathit{I}-1\right]=0$, $1$, $2$, $3$, $4$ or $10$.
On entry, ${\mathbf{nelt}}=〈\mathit{\text{value}}〉$ and ${\mathbf{nv}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{nelt}}\le 2×{\mathbf{nv}}-1$.
On entry, the end points of the edge $\mathit{J}$ have the same index $\mathit{I}$: $\mathit{J}=〈\mathit{\text{value}}〉$ and $\mathit{I}=〈\mathit{\text{value}}〉$.
On entry, vertices $1$ and $2$ of the triangle $\mathit{K}$ have the same index $\mathit{I}$: $\mathit{K}=〈\mathit{\text{value}}〉$ and $\mathit{I}=〈\mathit{\text{value}}〉$.
On entry, vertices $1$ and $3$ of the triangle $\mathit{K}$ have the same index $\mathit{I}$: $\mathit{K}=〈\mathit{\text{value}}〉$ and $\mathit{I}=〈\mathit{\text{value}}〉$.
On entry, vertices $2$ and $3$ of the triangle $\mathit{K}$ have the same index $\mathit{I}$: $\mathit{K}=〈\mathit{\text{value}}〉$ and $\mathit{I}=〈\mathit{\text{value}}〉$.
NE_INT_4
On entry, ${\mathbf{conni}}\left(\mathit{I},\mathit{J}\right)=〈\mathit{\text{value}}〉$, $\mathit{I}=〈\mathit{\text{value}}〉$, $\mathit{J}=〈\mathit{\text{value}}〉$ and ${\mathbf{nv}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{conni}}\left(\mathit{I},\mathit{J}\right)\ge 1$ and ${\mathbf{conni}}\left(\mathit{I},\mathit{J}\right)\le {\mathbf{nv}}$, where ${\mathbf{conni}}\left(\mathit{I},\mathit{J}\right)$ denotes ${\mathbf{conni}}\left[\left(\mathit{J}-1\right)×3+\mathit{I}-1\right]$.
On entry, ${\mathbf{edgei}}\left(\mathit{I},\mathit{J}\right)=〈\mathit{\text{value}}〉$, $\mathit{I}=〈\mathit{\text{value}}〉$, $\mathit{J}=〈\mathit{\text{value}}〉$ and ${\mathbf{nv}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{edgei}}\left(\mathit{I},\mathit{J}\right)\ge 1$ and ${\mathbf{edgei}}\left(\mathit{I},\mathit{J}\right)\le {\mathbf{nv}}$, where ${\mathbf{edgei}}\left(\mathit{I},\mathit{J}\right)$ denotes ${\mathbf{edgei}}\left[\left(\mathit{J}-1\right)×3+\mathit{I}-1\right]$.
NE_INTERNAL_ERROR
An internal error has occurred in this function. Check the function call and any array sizes. If the call is correct then please contact NAG for assistance.
See Section 2.7.6 in How to Use the NAG Library and its Documentation for further information.
A serious error has occurred in an internal call to an auxiliary function. Check the input mesh especially the connectivities and the details of each transformations.
NE_NO_LICENCE
Your licence key may have expired or may not have been installed correctly.
See Section 2.7.5 in How to Use the NAG Library and its Documentation for further information.
NE_NOT_CLOSE_FILE
Cannot close file $〈\mathit{\text{value}}〉$.
NE_NOT_WRITE_FILE
Cannot open file $〈\mathit{\text{value}}〉$ for writing.

Not applicable.

## 8Parallelism and Performance

nag_mesh2d_trans (d06dac) makes calls to BLAS and/or LAPACK routines, which may be threaded within the vendor library used by this implementation. Consult the documentation for the vendor library for further information.
Please consult the x06 Chapter Introduction for information on how to control and interrogate the OpenMP environment used within this function. Please also consult the Users' Note for your implementation for any additional implementation-specific information.

None.

## 10Example

For an example of the use of this utility function, see Section 10 in nag_mesh2d_join (d06dbc).
© The Numerical Algorithms Group Ltd, Oxford, UK. 2017