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_transform_affine (d06da)

## Purpose

nag_mesh_2d_transform_affine (d06da) is a utility which performs an affine transformation of a given mesh.

## Syntax

[coori, edgei, conni, cooro, edgeo, conno, ifail] = d06da(itype, trans, coori, edgei, conni, itrace, 'nv', nv, 'nedge', nedge, 'nelt', nelt, 'ntrans', ntrans)
[coori, edgei, conni, cooro, edgeo, conno, ifail] = nag_mesh_2d_transform_affine(itype, trans, coori, edgei, conni, itrace, 'nv', nv, 'nedge', nedge, 'nelt', nelt, 'ntrans', ntrans)

## Description

nag_mesh_2d_transform_affine (d06da) 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$Y=A×X+B$, where
• Y$Y$, X$X$ and B$B$ are in 2${ℝ}^{2}$, and
• A$A$ is a real 2$2$ by 2$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.

## Parameters

### Compulsory Input Parameters

1:     itype(ntrans) – int64int32nag_int array
ntrans, the dimension of the array, must satisfy the constraint ntrans1${\mathbf{ntrans}}\ge 1$.
itype(i)${\mathbf{itype}}\left(\mathit{i}\right)$, for i = 1,2,,ntrans$\mathit{i}=1,2,\dots ,{\mathbf{ntrans}}$, indicates the type of each transformation as follows:
itype(i) = 0${\mathbf{itype}}\left(i\right)=0$
Identity transformation.
itype(i) = 1${\mathbf{itype}}\left(i\right)=1$
Translation.
itype(i) = 2${\mathbf{itype}}\left(i\right)=2$
Symmetric transformation with respect to a user-supplied line.
itype(i) = 3${\mathbf{itype}}\left(i\right)=3$
Rotation.
itype(i) = 4${\mathbf{itype}}\left(i\right)=4$
Scaling.
itype(i) = 10${\mathbf{itype}}\left(i\right)=10$
User-supplied analytic transformation.
Note that the transformations are applied in the order described in itype.
Constraint: itype(i) = 0${\mathbf{itype}}\left(\mathit{i}\right)=0$, 1$1$, 2$2$, 3$3$, 4$4$ or 10$10$, for i = 1,2,,ntrans$\mathit{i}=1,2,\dots ,{\mathbf{ntrans}}$.
2:     trans(6$6$,ntrans) – double array
The parameters for each transformation. For i = 1,2,,ntrans$i=1,2,\dots ,{\mathbf{ntrans}}$, trans(1,i)${\mathbf{trans}}\left(1,i\right)$ to trans(6,i)${\mathbf{trans}}\left(6,i\right)$ contain the parameters of the i$i$th transformation.
If itype(i) = 0${\mathbf{itype}}\left(i\right)=0$, elements trans(1,i)${\mathbf{trans}}\left(1,i\right)$ to trans(6,i)${\mathbf{trans}}\left(6,i\right)$ are not referenced.
If itype(i) = 1${\mathbf{itype}}\left(i\right)=1$, the translation vector is u =
 ( a ) b
$\stackrel{\to }{u}=\left(\begin{array}{c}a\\ b\end{array}\right)$, where a = trans(1,i)$a={\mathbf{trans}}\left(1,i\right)$ and b = trans(2,i)$b={\mathbf{trans}}\left(2,i\right)$, while elements trans(3,i)${\mathbf{trans}}\left(3,i\right)$ to trans(6,i)${\mathbf{trans}}\left(6,i\right)$ are not referenced.
If itype(i) = 2${\mathbf{itype}}\left(i\right)=2$, the user-supplied line is the curve {(x,y)2$\left(x,y\right)\in {ℝ}^{2}$; such that ax + by + c = 0$ax+by+c=0$}, where a = trans(1,i)$a={\mathbf{trans}}\left(1,i\right)$, b = trans(2,i)$b={\mathbf{trans}}\left(2,i\right)$ and c = trans(3,i)$c={\mathbf{trans}}\left(3,i\right)$, while elements trans(4,i)${\mathbf{trans}}\left(4,i\right)$ to trans(6,i)${\mathbf{trans}}\left(6,i\right)$ are not referenced.
If itype(i) = 3${\mathbf{itype}}\left(i\right)=3$, the centre of the rotation is (x0,y0)$\left({x}_{0},{y}_{0}\right)$ where x0 = trans(1,i)${x}_{0}={\mathbf{trans}}\left(1,i\right)$ and y0 = trans(2,i)${y}_{0}={\mathbf{trans}}\left(2,i\right)$, θ = trans(3,i)$\theta ={\mathbf{trans}}\left(3,i\right)$ is its angle in degrees, while elements trans(4,i)${\mathbf{trans}}\left(4,i\right)$ to trans(6,i)${\mathbf{trans}}\left(6,i\right)$ are not referenced.
If itype(i) = 4${\mathbf{itype}}\left(i\right)=4$, a = trans(1,i)$a={\mathbf{trans}}\left(1,i\right)$ is the scaling coefficient in the x$x$-direction, b = trans(2,i)$b={\mathbf{trans}}\left(2,i\right)$ is the scaling coefficient in the y$y$-direction, and (x0,y0)$\left({x}_{0},{y}_{0}\right)$ are the scaling centre coordinates, with x0 = trans(3,i)${x}_{0}={\mathbf{trans}}\left(3,i\right)$ and y0 = trans(4,i)${y}_{0}={\mathbf{trans}}\left(4,i\right)$; while elements trans(5,i)${\mathbf{trans}}\left(5,i\right)$ to trans(6,i)${\mathbf{trans}}\left(6,i\right)$ are not referenced.
If itype(i) = 10${\mathbf{itype}}\left(i\right)=10$, the user-supplied analytic affine transformation Y = A × X + B$Y=A×X+B$ is such that A = (akl)1k,l2$A={\left({a}_{kl}\right)}_{1\le k,l\le 2}$ and B = (bk)1k2$B={\left({b}_{k}\right)}_{1\le k\le 2}$ whereakl = trans(2 × (k1) + l,i)${a}_{kl}={\mathbf{trans}}\left(2×\left(k-1\right)+l,i\right)$, and bk = trans(4 + k,i)${b}_{k}={\mathbf{trans}}\left(4+k,i\right)$ with k,l = 1,2$k,l=1,2$.
3:     coori(2$2$,nv) – double array
coori(1,i)${\mathbf{coori}}\left(1,\mathit{i}\right)$ contains the x$x$ coordinate of the i$\mathit{i}$th vertex of the input mesh, for i = 1,2,,nv$\mathit{i}=1,2,\dots ,{\mathbf{nv}}$; while coori(2,i)${\mathbf{coori}}\left(2,i\right)$ contains the corresponding y$y$ coordinate.
4:     edgei(3$3$,nedge) – int64int32nag_int array
The specification of the boundary or interface edges. edgei(1,j)${\mathbf{edgei}}\left(1,j\right)$ and edgei(2,j)${\mathbf{edgei}}\left(2,j\right)$ contain the vertex numbers of the two end points of the j$j$th boundary edge. edgei(3,j)${\mathbf{edgei}}\left(3,j\right)$ is a user-supplied tag for the j$j$th boundary edge.
Constraint: 1edgei(i,j)nv$1\le {\mathbf{edgei}}\left(\mathit{i},\mathit{j}\right)\le {\mathbf{nv}}$ and edgei(1,j)edgei(2,j)${\mathbf{edgei}}\left(1,\mathit{j}\right)\ne {\mathbf{edgei}}\left(2,\mathit{j}\right)$, for i = 1,2$\mathit{i}=1,2$ and j = 1,2,,nedge$\mathit{j}=1,2,\dots ,{\mathbf{nedge}}$.
5:     conni(3$3$,nelt) – int64int32nag_int array
The connectivity of the input mesh between triangles and vertices. For each triangle j$\mathit{j}$, conni(i,j)${\mathbf{conni}}\left(\mathit{i},\mathit{j}\right)$ gives the indices of its three vertices (in anticlockwise order), for i = 1,2,3$\mathit{i}=1,2,3$ and j = 1,2,,nelt$\mathit{j}=1,2,\dots ,{\mathbf{nelt}}$.
Constraints:
• 1conni(i,j)nv$1\le {\mathbf{conni}}\left(i,j\right)\le {\mathbf{nv}}$;
• conni(1,j)conni(2,j)${\mathbf{conni}}\left(1,j\right)\ne {\mathbf{conni}}\left(2,j\right)$;
• conni(1,j)conni(3,j)${\mathbf{conni}}\left(1,\mathit{j}\right)\ne {\mathbf{conni}}\left(3,\mathit{j}\right)$ and conni(2,j)conni(3,j)${\mathbf{conni}}\left(2,\mathit{j}\right)\ne {\mathbf{conni}}\left(3,\mathit{j}\right)$, for i = 1,2,3$\mathit{i}=1,2,3$ and j = 1,2,,nelt$\mathit{j}=1,2,\dots ,{\mathbf{nelt}}$.
6:     itrace – int64int32nag_int scalar
The level of trace information required from nag_mesh_2d_transform_affine (d06da).
itrace0${\mathbf{itrace}}\le 0$
No output is generated.
itrace1${\mathbf{itrace}}\ge 1$
Details of each transformation, the matrix A$A$ and the vector B$B$ of the final transformation, which is the composition of all the ntrans transformations, are printed on the current advisory message unit (see nag_file_set_unit_advisory (x04ab)).

### Optional Input Parameters

1:     nv – int64int32nag_int scalar
Default: The dimension of the array coori.
The total number of vertices in the input mesh.
Constraint: nv3${\mathbf{nv}}\ge 3$.
2:     nedge – int64int32nag_int scalar
Default: The dimension of the array edgei.
The number of the boundary or interface edges in the input mesh.
Constraint: nedge1${\mathbf{nedge}}\ge 1$.
3:     nelt – int64int32nag_int scalar
Default: The dimension of the array conni.
The number of triangles in the input mesh.
Constraint: nelt2 × nv1${\mathbf{nelt}}\le 2×{\mathbf{nv}}-1$.
4:     ntrans – int64int32nag_int scalar
Default: The dimension of the arrays itype, trans. (An error is raised if these dimensions are not equal.)
The number of transformations of the input mesh.
Constraint: ntrans1${\mathbf{ntrans}}\ge 1$.

rwork lrwork

### Output Parameters

1:     coori(2$2$,nv) – double array
2:     edgei(3$3$,nedge) – int64int32nag_int array
3:     conni(3$3$,nelt) – int64int32nag_int array
4:     cooro(2$2$,nv) – double array
cooro(1,i)${\mathbf{cooro}}\left(1,\mathit{i}\right)$ will contain the x$x$ coordinate of the i$\mathit{i}$th vertex of the transformed mesh, for i = 1,2,,nv$\mathit{i}=1,2,\dots ,{\mathbf{nv}}$; while cooro(2,i)${\mathbf{cooro}}\left(2,i\right)$ will contain the corresponding y$y$ coordinate.
5:     edgeo(3$3$,nedge) – int64int32nag_int array
The specification of the boundary or interface edges of the transformed mesh. If the number of symmetric transformations is even or zero thenedgeo(i,j) = edgei(i,j)${\mathbf{edgeo}}\left(\mathit{i},\mathit{j}\right)={\mathbf{edgei}}\left(\mathit{i},\mathit{j}\right)$, for i = 1,2,3$\mathit{i}=1,2,3$ and j = 1,2,,nedge$\mathit{j}=1,2,\dots ,{\mathbf{nedge}}$; otherwise edgeo(1,j) = edgei(2,j)${\mathbf{edgeo}}\left(1,\mathit{j}\right)={\mathbf{edgei}}\left(2,\mathit{j}\right)$,edgeo(2,j) = edgei(1,j)${\mathbf{edgeo}}\left(2,\mathit{j}\right)={\mathbf{edgei}}\left(1,\mathit{j}\right)$ and edgeo(3,j) = edgei(3,j)${\mathbf{edgeo}}\left(3,\mathit{j}\right)={\mathbf{edgei}}\left(3,\mathit{j}\right)$, for j = 1,2,,nedge$\mathit{j}=1,2,\dots ,{\mathbf{nedge}}$.
6:     conno(3$3$,nelt) – int64int32nag_int array
The connectivity of the transformed mesh between triangles and vertices. If the number of symmetric transformations is even or zero thenconno(i,j) = conni(i,j)${\mathbf{conno}}\left(\mathit{i},\mathit{j}\right)={\mathbf{conni}}\left(\mathit{i},\mathit{j}\right)$, for i = 1,2,3$\mathit{i}=1,2,3$ and j = 1,2,,nelt$\mathit{j}=1,2,\dots ,{\mathbf{nelt}}$; otherwise conno(1,j) = conni(1,j)${\mathbf{conno}}\left(1,\mathit{j}\right)={\mathbf{conni}}\left(1,\mathit{j}\right)$, conno(2,j) = conni(3,j)${\mathbf{conno}}\left(2,\mathit{j}\right)={\mathbf{conni}}\left(3,\mathit{j}\right)$ and conno(3,j) = conni(2,j)${\mathbf{conno}}\left(3,\mathit{j}\right)={\mathbf{conni}}\left(2,\mathit{j}\right)$, for j = 1,2,,nelt$\mathit{j}=1,2,\dots ,{\mathbf{nelt}}$.
7:     ifail – int64int32nag_int scalar
${\mathrm{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:
ifail = 1${\mathbf{ifail}}=1$
 On entry, nv < 3${\mathbf{nv}}<3$; or nelt > 2 × nv − 1${\mathbf{nelt}}>2×{\mathbf{nv}}-1$; or nedge < 1${\mathbf{nedge}}<1$; or edgei(i,j) < 1${\mathbf{edgei}}\left(i,j\right)<1$ or edgei(i,j) > nv${\mathbf{edgei}}\left(i,j\right)>{\mathbf{nv}}$ for some i = 1,2$i=1,2$ and j = 1,2, … ,nedge$j=1,2,\dots ,{\mathbf{nedge}}$; or edgei(1,j) = edgei(2,j)${\mathbf{edgei}}\left(1,j\right)={\mathbf{edgei}}\left(2,j\right)$ for some j = 1,2, … ,nedge$j=1,2,\dots ,{\mathbf{nedge}}$; or conni(i,j) < 1${\mathbf{conni}}\left(i,j\right)<1$ or conni(i,j) > nv${\mathbf{conni}}\left(i,j\right)>{\mathbf{nv}}$ for some i = 1,2,3$i=1,2,3$ and j = 1,2, … ,nelt$j=1,2,\dots ,{\mathbf{nelt}}$; or conni(1,j) = conni(2,j)${\mathbf{conni}}\left(1,j\right)={\mathbf{conni}}\left(2,j\right)$ or conni(1,j) = conni(3,j)${\mathbf{conni}}\left(1,j\right)={\mathbf{conni}}\left(3,j\right)$ or conni(2,j) = conni(3,j)${\mathbf{conni}}\left(2,j\right)={\mathbf{conni}}\left(3,j\right)$ for some j = 1,2, … ,nelt$j=1,2,\dots ,{\mathbf{nelt}}$; or ntrans < 1${\mathbf{ntrans}}<1$; or itype(i) ≠ 0${\mathbf{itype}}\left(i\right)\ne 0$, 1$1$, 2$2$, 3$3$, 4$4$ or 10$10$ for some i = 1,2, … ,ntrans$i=1,2,\dots ,{\mathbf{ntrans}}$; or lrwork < 12 × ntrans$\mathit{lrwork}<12×{\mathbf{ntrans}}$.
ifail = 2${\mathbf{ifail}}=2$
A serious error has occurred in an internal call to an auxiliary function. Check the input mesh especially the triangles/vertices and the edges/vertices connectivities as well as the details of each transformations.

## Accuracy

Not applicable.

You may not wish to save the input mesh (coori, edgei and conni) and could call nag_mesh_2d_transform_affine (d06da) using the same parameters for the input and the output (transformed) mesh.

## Example

For an example of the use of this utility function, see Section [Example] in (d06db).
```function nag_mesh_2d_transform_affine_example
coor1 = zeros(2,400);
for j = 1:20
for i = 1:20
coor1(1,(j-1)*20+i) = (i-1)/19;
coor1(2,(j-1)*20+i) = (j-1)/19;
end
end
edge1 = ones(3, 76, 'int64');
edge1(1, 1:76) = [int64(1),2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19, ...
20,40,60,80,100,120,140,160,180,200,220,240,260,280,300,320,340,360,380, ...
400,399,398,397,396,395,394,393,392,391,390,389,388,387,386,385,384,383, ...
382,381,361,341,321,301,281,261,241,221,201,181,161,141,121,101,81,61,41,21];
edge1(2, 1:76) = [ int64(2),3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19, ...
20,40,60,80,100,120,140,160,180,200,220,240,260,280,300,320,340,360,380, ...
400,399,398,397,396,395,394,393,392,391,390,389,388,387,386,385,384,383, ...
382,381,361,341,321,301,281,261,241,221,201,181,161,141,121,101,81,61,41,21,1];
conn1 = zeros(3, 722, 'int64');
ind = -1;
for i=1:379
if (rem(i, 20) ~= 0)
ind = ind+2;
conn1(1, ind)   = int64(i);
conn1(1, ind+1) = int64(i);
conn1(2, ind)   = int64(i+1);
conn1(2, ind+1) = int64(i+21);
conn1(3, ind)   = int64(i+21);
conn1(3, ind+1) = int64(i+20);
end
end
reft1 = ones(722, 1, 'int64');
reft2 = reft1;
reft2(:) = int64(2);
itype = [int64(1)];
itrace = int64(0);

% Transform the first domain to obtain an overlapping second domain
trans = [15/19; 17/19; 0; 0; 0; 0];
[coor1, edge1, conn1, coor2, edge2, conn2, ifail] = ...
nag_mesh_2d_transform_affine(itype, trans, coor1, edge1, conn1, itrace);

% Restitch the meshes
[nv3, nelt3, nedge3, coor3, edge3, conn3, reft3, ifail] = ...
nag_mesh_2d_join(coor1, edge1, conn1, reft1, coor2, edge2, conn2, reft2, itrace);

% Plot the result
fig1 = figure('Number', 'off');
triplot(transpose(conn3(:,1:double(nelt3))), coor3(1,:), coor3(2,:));
title ('Interior mesh of the two overlapping squares geometry', 'FontSize', 14);

% Now consider a partitioned second domain
trans = [1; 0; 0; 0; 0; 0];
[coor1, edge1, conn1, coor2, edge2, conn2, ifail] = ...
nag_mesh_2d_transform_affine(itype, trans, coor1, edge1, conn1, itrace);

% Restitch the meshes
[nv3, nelt3, nedge3, coor3, edge3, conn3, reft3, ifail] = ...
nag_mesh_2d_join(coor1, edge1, conn1, reft1, coor2, edge2, conn2, reft2, itrace);
ifail

% Plot the result
fig2 = figure('Number', 'off');
triplot(transpose(conn3(:,1:double(nelt3))), coor3(1,:), coor3(2,:));
title ('Interior mesh of the two partitioned squares geometry', 'FontSize', 14);
```
```

ifail =

0

```
```function d06da_example
coor1 = zeros(2,400);
for j = 1:20
for i = 1:20
coor1(1,(j-1)*20+i) = (i-1)/19;
coor1(2,(j-1)*20+i) = (j-1)/19;
end
end
edge1 = ones(3, 76, 'int64');
edge1(1, 1:76) = [int64(1),2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19, ...
20,40,60,80,100,120,140,160,180,200,220,240,260,280,300,320,340,360,380, ...
400,399,398,397,396,395,394,393,392,391,390,389,388,387,386,385,384,383, ...
382,381,361,341,321,301,281,261,241,221,201,181,161,141,121,101,81,61,41,21];
edge1(2, 1:76) = [ int64(2),3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19, ...
20,40,60,80,100,120,140,160,180,200,220,240,260,280,300,320,340,360,380, ...
400,399,398,397,396,395,394,393,392,391,390,389,388,387,386,385,384,383, ...
382,381,361,341,321,301,281,261,241,221,201,181,161,141,121,101,81,61,41,21,1];
conn1 = zeros(3, 722, 'int64');
ind = -1;
for i=1:379
if (rem(i, 20) ~= 0)
ind = ind+2;
conn1(1, ind)   = int64(i);
conn1(1, ind+1) = int64(i);
conn1(2, ind)   = int64(i+1);
conn1(2, ind+1) = int64(i+21);
conn1(3, ind)   = int64(i+21);
conn1(3, ind+1) = int64(i+20);
end
end
reft1 = ones(722, 1, 'int64');
reft2 = reft1;
reft2(:) = int64(2);
itype = [int64(1)];
itrace = int64(0);

% Transform the first domain to obtain an overlapping second domain
trans = [15/19; 17/19; 0; 0; 0; 0];
[coor1, edge1, conn1, coor2, edge2, conn2, ifail] = ...
d06da(itype, trans, coor1, edge1, conn1, itrace);

% Restitch the meshes
[nv3, nelt3, nedge3, coor3, edge3, conn3, reft3, ifail] = ...
d06db(coor1, edge1, conn1, reft1, coor2, edge2, conn2, reft2, itrace);

% Plot the result
fig1 = figure('Number', 'off');
triplot(transpose(conn3(:,1:double(nelt3))), coor3(1,:), coor3(2,:));
title ('Interior mesh of the two overlapping squares geometry', 'FontSize', 14);

% Now consider a partitioned second domain
trans = [1; 0; 0; 0; 0; 0];
[coor1, edge1, conn1, coor2, edge2, conn2, ifail] = ...
d06da(itype, trans, coor1, edge1, conn1, itrace);

% Restitch the meshes
[nv3, nelt3, nedge3, coor3, edge3, conn3, reft3, ifail] = ...
d06db(coor1, edge1, conn1, reft1, coor2, edge2, conn2, reft2, itrace);
ifail

% Plot the result
fig2 = figure('Number', 'off');
triplot(transpose(conn3(:,1:double(nelt3))), coor3(1,:), coor3(2,:));
title ('Interior mesh of the two partitioned squares geometry', 'FontSize', 14);
```
```

ifail =

0

```