# neighbors

Triangle or tetrahedron neighbors

## Syntax

``N = neighbors(TR)``
``N = neighbors(TR,ID)``

## Description

example

````N = neighbors(TR)` returns the IDs of the neighbors to all triangles or tetrahedra in `TR`. `N` is a 3-column (2-D) or 4-column (3-D) matrix whose rows contain the IDs of the neighboring triangles or tetrahedra to that element in the triangulation.```

example

````N = neighbors(TR,ID)` returns the neighbors of the triangles or tetrahedra specified in `ID`.By convention, the (i,j) element of `N` is the neighbor opposite to the jth vertex of the ith element of `ID`.```

## Examples

collapse all

Find neighboring tetrahedra in a 3-D triangulation.

Create a 3-D triangulation.

```load tetmesh TR = triangulation(tet,X);```

Compute the IDs of the neighboring tetrahedra to each element of the triangulation.

`N = neighbors(TR);`

Display the IDs of the neighbors to the fifth tetrahedron.

`N(5,:)`
```ans = 1×4 2360 1539 2 1851 ```

Examine the vertex IDs of the first neighbor.

`TR.ConnectivityList(N(1),:)`
```ans = 1×4 1093 891 893 858 ```

Find neighboring triangles in a 2-D Delaunay triangulation.

Create a 2-D Delaunay triangulation.

```rng('default') x = rand([10,1]); y = rand([10,1]); TR = delaunayTriangulation(x,y);```

Find the neighbors of the first triangle. `NaN` indicates that the triangle is on the boundary of the triangulation and only has two neighbors.

`N = neighbors(TR,1)`
```N = 1×3 NaN 4 3 ```

Examine the vertex IDs of the third neighbor.

`TR.ConnectivityList(N(3),:)`
```ans = 1×3 5 2 8 ```

## Input Arguments

collapse all

Triangulation representation, specified as a scalar `triangulation` or `delaunayTriangulation` object.

Data Types: `triangulation` | `delaunayTriangulation`

Triangle or tetrahedron IDs, specified as a scalar or a column vector whose elements correspond to a single triangle or tetrahedron in the triangulation object. The ID of each triangle or tetrahedron is the corresponding row number of the `ConnectivityList` property.

If a triangle or tetrahedron has one or more boundary facets, the nonexistent neighbors are represented as `NaN` values in `N`.

Data Types: `double`