# RegionNearest

RegionNearest[reg,p]

gives a point in the region reg that is nearest the point p.

RegionNearest[reg]

gives a that can be repeatedly applied to points.

# Details  • The distance between points q and p is taken to be Norm[p-q].
• RegionNearest is effectively given by ArgMin[{Norm[p-q],qreg},q].
• RegionNearest can be used with symbolic regions and points in GeometricScene.

# Examples

open allclose all

## Basic Examples(2)

Find the nearest point in the unit disk:

Plot it:

Find the nearest point in a MeshRegion:

With one argument you get a RegionNearestFunction:

Apply the function to lists of points to compute many nearest points:

## Scope(16)

### Special Regions(7)

Point sets:

They work in any dimension:

Visualize the nearest points:

Line:

Visualize it:

Rectangle can be used in 2D:

Cuboid generalizes it to any dimension:

Visualize the nearest points on a rectangle:

Visualize the nearest points on a 2D simplex:

Visualize the nearest points in a hexagon:

Disk can be used in 2D:

Ball generalizes a disk in any dimension:

Visualize the nearest points on a 3D ball:

Disk can be an ellipse in 2D:

Ellipsoid generalizes ellipses to any dimension:

Plot the nearest points on an ellipse:

### Formula Regions(2)

The nearest point on a disk represented as an ImplicitRegion:

A cylinder:

The nearest point on a disk represented as a ParametricRegion:

Using a rational parametrization of the disk:

A cylinder:

### Mesh Regions(4)

The nearest point in a 1D BoundaryMeshRegion:

2D:

3D:

The nearest point in a 0D MeshRegion in 1D:

A 1D region:

The nearest point in a 0D MeshRegion in 2D:

A 1D region:

A 2D region:

The nearest point in a 0D MeshRegion in 3D:

A 1D region:

A 2D region:

A 3D region:

### Derived Regions(3)

The distance to a RegionIntersection:

The distance to a TransformedRegion:

The distance to a RegionBoundary:

## Applications(3)

Visualize the nearest points in a region:

The nearest points along two circles:

Visualize a region by mapping uniform points to the region using RegionNearest:

Find the altitude of a triangle:

Visualize altitude in red:

## Properties & Relations(4)

Only one point is returned in case there is a tie:

Visualize the nearest point chosen in red:

A point is a RegionMember if the nearest point to the region is itself:

RegionNearest is closely related to RegionDistance:

The distance to the nearest point is minimal:

Nearest gives nearest points for finite point regions: