# nearestEdge

## Description

## Examples

### Edges of 3-D Geometry Closest to Specified Points

Find edges of a block nearest to the specified points.

Create a block geometry.

gm = multicuboid(3,2,1)

gm = DiscreteGeometry with properties: NumCells: 1 NumFaces: 6 NumEdges: 12 NumVertices: 8 Vertices: [8x3 double]

Plot the geometry with the edge labels. Add the points with the coordinates (0 0 0), (1 0.9 1), and (1.5 -1 0) to the plot.

pdegplot(gm,"EdgeLabels","on","FaceAlpha",0.2) hold on scatter3([0 1 1.5],[0 0.9 -1],[0 1 0],"filled","MarkerFaceColor","g")

Find edges closest to the points with the coordinates (0 0 0), (1 0.9 1), and (1.5 -1 0). If several edges are equally close (within the tolerance) to the point, `nearestEdge`

returns the ID of one of the edges.

edgeIDs = nearestEdge(gm,[0 0 0; 1 0.9 1; 1.5 -1 0])

`edgeIDs = `*1×3*
1 7 1

### Edges of 2-D Geometry Closest to Specified Points

Find edges of the L-shaped membrane nearest to the specified points.

Create a model and include this geometry. The geometry of the L-shaped membrane is described in the file `lshapeg`

.

model = createpde(); gm = geometryFromEdges(model,@lshapeg)

gm = AnalyticGeometry with properties: NumCells: 0 NumFaces: 3 NumEdges: 10 NumVertices: 8 Vertices: [8x2 double]

Plot the geometry with the edge labels. Add the points with the coordinates (0 0), (0.1 0.2), and (-0.5 0.5) to the plot.

pdegplot(gm,"EdgeLabels","on") hold on scatter([0 0.1 -0.5],[0 0.2 0.5],"filled")

Find edges closest to the points with the coordinates (0 0), (0.1 0.2), and (-0.5 0.5). If several edges are equally close (within the tolerance) to the point, `nearestEdge`

returns the ID of one of the edges.

edgeIDs = nearestEdge(gm,[0 0; 0.1 0.2; -0.5 0.5])

`edgeIDs = `*1×3*
7 10 10

## Input Arguments

`g`

— Geometry

`fegeometry`

object | `DiscreteGeometry`

object | `AnalyticGeometry`

object

Geometry, specified as an `fegeometry`

object, a `DiscreteGeometry`

object, or an `AnalyticGeometry`

object.

`Coords`

— Coordinates

`N`

-by-2 numeric matrix | `N`

-by-3 numeric matrix

Coordinates of the points, specified as an `N`

-by-2 or
`N`

-by-3 numeric matrix for a 2-D or 3-D geometry, respectively.
Here, `N`

is the number of points.

**Data Types: **`double`

## Output Arguments

`EdgeID`

— IDs of edges nearest to specified point

positive number | vector of positive numbers

IDs of edges nearest to the specified point, returned as a positive number or a vector of positive numbers.

## Version History

**Introduced in R2021a**

### R2023a: Finite element model

`nearestEdge`

now accepts geometries specified by `fegeometry`

objects.

## See Also

### Functions

### Objects

## Open Example

You have a modified version of this example. Do you want to open this example with your edits?

## MATLAB Command

You clicked a link that corresponds to this MATLAB command:

Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.

Select a Web Site

Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .

You can also select a web site from the following list:

## How to Get Best Site Performance

Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.

### Americas

- América Latina (Español)
- Canada (English)
- United States (English)

### Europe

- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)

- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)