WOLFRAM

RegionNearest[reg,p]

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

gives a RegionNearestFunction[] that can be repeatedly applied to points.

Details

Examples

open allclose all

Basic Examples  (2)Summary of the most common use cases

Find the nearest point in the unit disk:

Out[3]=3

Plot it:

Out[2]=2

Find the nearest point in a MeshRegion:

Out[1]=1

With one argument you get a RegionNearestFunction:

Out[2]=2

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

Out[3]=3

Scope  (16)Survey of the scope of standard use cases

Special Regions  (7)

Point sets:

Out[1]=1

They work in any dimension:

Out[2]=2

Visualize the nearest points:

Out[6]=6

Line:

Out[1]=1
Out[2]=2

Visualize it:

Out[4]=4

Rectangle can be used in 2D:

Out[1]=1

Cuboid generalizes it to any dimension:

Out[2]=2

Visualize the nearest points on a rectangle:

Out[4]=4

Simplex:

Out[1]=1
Out[2]=2

Visualize the nearest points on a 2D simplex:

Out[4]=4

Polygon:

Out[1]=1

Visualize the nearest points in a hexagon:

Out[3]=3

Disk can be used in 2D:

Out[1]=1

Ball generalizes a disk in any dimension:

Out[2]=2

Visualize the nearest points on a 3D ball:

Out[4]=4

Disk can be an ellipse in 2D:

Out[1]=1

Ellipsoid generalizes ellipses to any dimension:

Out[2]=2

Plot the nearest points on an ellipse:

Out[4]=4

Formula Regions  (2)

The nearest point on a disk represented as an ImplicitRegion:

Out[2]=2
Out[4]=4

A cylinder:

Out[6]=6

The nearest point on a disk represented as a ParametricRegion:

Out[2]=2
Out[3]=3

Using a rational parametrization of the disk:

Out[5]=5

A cylinder:

Out[7]=7
Out[8]=8

Mesh Regions  (4)

The nearest point in a 1D BoundaryMeshRegion:

Out[1]=1
Out[2]=2

2D:

Out[4]=4
Out[5]=5

3D:

Out[7]=7
Out[8]=8

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

Out[1]=1
Out[2]=2

A 1D region:

Out[3]=3
Out[4]=4

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

Out[2]=2
Out[3]=3

A 1D region:

Out[5]=5
Out[6]=6

A 2D region:

Out[8]=8
Out[9]=9

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

Out[2]=2
Out[3]=3

A 1D region:

Out[5]=5
Out[6]=6

A 2D region:

Out[8]=8
Out[9]=9

A 3D region:

Out[11]=11
Out[12]=12

Derived Regions  (3)

The distance to a RegionIntersection:

Out[2]=2
Out[3]=3

The distance to a TransformedRegion:

Out[2]=2
Out[3]=3

The distance to a RegionBoundary:

Out[2]=2
Out[3]=3

Applications  (3)Sample problems that can be solved with this function

Visualize the nearest points in a region:

The nearest points along two circles:

Out[139]=139

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

Out[1]=1

Find the altitude of a triangle:

Visualize altitude in red:

Out[5]=5

Properties & Relations  (4)Properties of the function, and connections to other functions

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

Out[3]=3

Visualize the nearest point chosen in red:

Out[4]=4

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

Out[2]=2
Out[3]=3

RegionNearest is closely related to RegionDistance:

The distance to the nearest point is minimal:

Out[2]=2
Out[3]=3
Out[4]=4

Nearest gives nearest points for finite point regions:

Out[2]=2
Out[3]=3
Wolfram Research (2014), RegionNearest, Wolfram Language function, https://reference.wolfram.com/language/ref/RegionNearest.html.
Wolfram Research (2014), RegionNearest, Wolfram Language function, https://reference.wolfram.com/language/ref/RegionNearest.html.

Text

Wolfram Research (2014), RegionNearest, Wolfram Language function, https://reference.wolfram.com/language/ref/RegionNearest.html.

Wolfram Research (2014), RegionNearest, Wolfram Language function, https://reference.wolfram.com/language/ref/RegionNearest.html.

CMS

Wolfram Language. 2014. "RegionNearest." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/RegionNearest.html.

Wolfram Language. 2014. "RegionNearest." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/RegionNearest.html.

APA

Wolfram Language. (2014). RegionNearest. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/RegionNearest.html

Wolfram Language. (2014). RegionNearest. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/RegionNearest.html

BibTeX

@misc{reference.wolfram_2025_regionnearest, author="Wolfram Research", title="{RegionNearest}", year="2014", howpublished="\url{https://reference.wolfram.com/language/ref/RegionNearest.html}", note=[Accessed: 25-March-2025 ]}

@misc{reference.wolfram_2025_regionnearest, author="Wolfram Research", title="{RegionNearest}", year="2014", howpublished="\url{https://reference.wolfram.com/language/ref/RegionNearest.html}", note=[Accessed: 25-March-2025 ]}

BibLaTeX

@online{reference.wolfram_2025_regionnearest, organization={Wolfram Research}, title={RegionNearest}, year={2014}, url={https://reference.wolfram.com/language/ref/RegionNearest.html}, note=[Accessed: 25-March-2025 ]}

@online{reference.wolfram_2025_regionnearest, organization={Wolfram Research}, title={RegionNearest}, year={2014}, url={https://reference.wolfram.com/language/ref/RegionNearest.html}, note=[Accessed: 25-March-2025 ]}