RegionNearest[reg,p]
gives a point in the region reg that is nearest the point p.
RegionNearest[reg]
gives a RegionNearestFunction[…] that can be repeatedly applied to points.
RegionNearest
RegionNearest[reg,p]
gives a point in the region reg that is nearest the point p.
RegionNearest[reg]
gives a RegionNearestFunction[…] 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],q∈reg},q].
- RegionNearest can be used with symbolic regions and points in GeometricScene.
Examples
open all close allBasic Examples (2)
Find the nearest point in the unit disk:
RegionNearest[Disk[], {2, 2}]Graphics[{{LightBlue, Disk[]}, {{Red, Point[{2, 2}]}, {Blue, Point[%]}, Line[{{2, 2}, %}]}}]Find the nearest point in a MeshRegion:
DelaunayMesh[RandomReal[1, {25, 2}]]With one argument you get a RegionNearestFunction:
nf = RegionNearest[%]Apply the function to lists of points to compute many nearest points:
nf[RandomReal[2, {5, 2}]]Scope (16)
Special Regions (7)
Point sets:
RegionNearest[Point[{{1, 1}, {1, 2}}], {3, 4}]RegionNearest[Point[{{0, 0, 0, 0}, {1, 2, 3, 4}}], {2, 2, 2, 2}]ℛ = Point[{{1, 2}, {3, 4}, {5, 6}}];
pts = Table[{3, 4} + 4{Cos[k 2π / 16], Sin[k 2π / 16]}, {k, 0, 15}];
nst = RegionNearest[ℛ, #]& /@ pts;Legended[Graphics[{ℛ, {Thin, Gray, Line[Transpose[{pts, nst}]]}, {Red, Point[pts]}, {Blue, Point[nst]}}], PointLegend[{Red, Blue}, {"start", "nearest"}]]Line:
RegionNearest[Line[{{0, 0}, {1, 1}}], {3, 4}]RegionNearest[Line[{{0, 0, 0}, {1, 1, 1}, {0, 0, 1}}], {1, 0, 3}]ℛ = Line[{{0, 0}, {1, 2}, {1, 0}, {2, 2}}];
pts = Table[{1, 1} + 2{Cos[k 2π / 16], Sin[k 2π / 16]}, {k, 0, 15}];
nst = RegionNearest[ℛ, #]& /@ pts;Legended[Graphics[{ℛ, {Thin, Gray, Line[Transpose[{pts, nst}]]}, {Red, Point[pts]}, {Blue, Point[nst]}}], PointLegend[{Red, Blue}, {"start", "nearest"}]]Rectangle can be used in 2D:
RegionNearest[Rectangle[{0, 0}, {1, 2}], {3, 4}]Cuboid generalizes it to any dimension:
RegionNearest[Cuboid[{0, 0, 0, 0}, {1, 2, 3, 4}], {1, 1, 1, 5}]Visualize the nearest points on a rectangle:
ℛ = Rectangle[{0, 0}, {2, 1}];
pts = Table[{1, 1 / 2} + 2{Cos[k 2π / 16], Sin[k 2π / 16]}, {k, 0, 15}];
nst = RegionNearest[ℛ, #]& /@ pts;Legended[Graphics[{{LightBlue, EdgeForm[Gray], ℛ}, {Thin, Gray, Line[Transpose[{pts, nst}]]}, {Red, Point[pts]}, {Blue, Point[nst]}}], PointLegend[{Red, Blue}, {"start", "nearest"}]]RegionNearest[Simplex[1], {2}]RegionNearest[Simplex[3], {1, 1, 1}]Visualize the nearest points on a 2D simplex:
ℛ = Simplex[2];
pts = Table[{1 / 3, 1 / 3} + {Cos[k 2π / 16], Sin[k 2π / 16]}, {k, 0, 15}];
nst = RegionNearest[ℛ, #]& /@ pts;Legended[Graphics[{{LightBlue, EdgeForm[Gray], ℛ}, {Thin, Gray, Line[Transpose[{pts, nst}]]}, {Red, Point[pts]}, {Blue, Point[nst]}}], PointLegend[{Red, Blue}, {"start", "nearest"}]]RegionNearest[Polygon[{{0, 0}, {1, 0}, {0, 1}}], {1, 1}]Visualize the nearest points in a hexagon:
ℛ = Polygon[{{-2, 0}, {-1, 3 / 2}, {1, 3 / 2}, {2, 0}, {1, -3 / 2}, {-1, -3 / 2}}];
pts = Table[4{Cos[k 2 π / 25], Sin[k 2π / 25]}, {k, 0., 24}];
nst = RegionNearest[ℛ, #]& /@ pts;Legended[Graphics[{{LightBlue, EdgeForm[Gray], ℛ}, {Thin, Gray, Line[Transpose[{pts, nst}]]}, {Red, Point[pts]}, {Blue, Point[nst]}}], PointLegend[{Red, Blue}, {"start", "nearest"}]]Disk can be used in 2D:
RegionNearest[Disk[{0, 0}, 1], {3, 4}]Ball generalizes a disk in any dimension:
RegionNearest[Ball[{0, 0, 0}, 1], {3, 4, 5}]Visualize the nearest points on a 3D ball:
ℛ = Ball[{0, 0, 0}, 1];
pts = Flatten[Table[2{Cos[k 2π / 8]Cos[l π / 8], Sin[k 2π / 8]Cos[l π / 8], Sin[l π / 8]}, {k, 0, 7}, {l, -3, 3}], 1];
nst = RegionNearest[ℛ, #]& /@ pts;Legended[Graphics3D[{ℛ, {Thin, Gray, Line[Transpose[{pts, nst}]]}, {Red, Point[pts]}, {Blue, Point[nst]}}, Boxed -> False], PointLegend[{Red, Blue}, {"start", "nearest"}]]Disk can be an ellipse in 2D:
RegionNearest[Disk[{0, 0}, {1, 2}], {0, 4}]Ellipsoid generalizes ellipses to any dimension:
RegionNearest[Ellipsoid[{0, 0, 0}, {1, 2, 3}], {0, 3, 4}]Plot the nearest points on an ellipse:
ℛ = Disk[{0, 0}, {2, 1}];
pts = Table[3{Cos[k 2π / 16], Sin[k 2π / 16]}, {k, 0., 15}];
nst = RegionNearest[ℛ, #]& /@ pts;Legended[Graphics[{{LightBlue, EdgeForm[Gray], ℛ}, {Thin, Gray, Line[Transpose[{pts, nst}]]}, {Red, Point[pts]}, {Blue, Point[nst]}}], PointLegend[{Red, Blue}, {"start", "nearest"}]]Formula Regions (2)
The nearest point on a disk represented as an ImplicitRegion:
ℛ = ImplicitRegion[x^2 + y^2 ≤ 1, {x, y}];Region[ℛ]RegionNearest[ℛ, {3, 4}]ℛ = ImplicitRegion[x^2 + y^2 ≤ 1, {x, y, {z, 0, 2}}];RegionNearest[ℛ, {3, 4, 5}]The nearest point on a disk represented as a ParametricRegion:
ℛ = ParametricRegion[{r Cos[θ], r Sin[θ]}, {{r, 0, 1}, {θ, 0, 2π}}];RegionNearest[ℛ, {3, 4}]FullSimplify[%]Using a rational parametrization of the disk:
ℛ = ParametricRegion[{r(1 - t^2/1 + t^2), r(2t/1 + t^2)}, {t, {r, 0, 1}}];RegionNearest[ℛ, {3, 4}]ℛ = ParametricRegion[{r Cos[θ], r Sin[θ], z}, {{r, 0, 1}, {θ, 0, 2π}, {z, 0, 2}}];RegionNearest[ℛ, {3, 4, 5}]FullSimplify[%]Mesh Regions (4)
The nearest point in a 1D BoundaryMeshRegion:
ℛ = BoundaryMeshRegion[{{0}, {1}}, Point[{{1}, {2}}]]RegionNearest[ℛ, {2}]ℛ = ConvexHullMesh[RandomReal[1, {10, 2}]];Show[ℛ, Graphics[{Red, Point[{1, 1}]}]]RegionNearest[ℛ, {1, 1}]ℛ = ConvexHullMesh[RandomReal[1, {20, 3}]];Show[ℛ, Graphics3D[{Red, Point[{1, 1, 1}]}]]RegionNearest[ℛ, {1, 1, 1}]The nearest point in a 0D MeshRegion in 1D:
ℛ = MeshRegion[{{0}, {1}}, Point[{{1}, {2}}]]RegionNearest[ℛ, {1 / 2}]ℛ = MeshRegion[{{0}, {1}}, Line[{1, 2}]]RegionNearest[ℛ, {2}]The nearest point in a 0D MeshRegion in 2D:
ℛ = MeshRegion[{{0, 0}, {1, 0}, {0, 1}}, Point[{{1}, {2}, {3}}]];Show[ℛ, Graphics[{Red, Point[{1, 1}]}]]RegionNearest[ℛ, {1, 1}]ℛ = MeshRegion[{{0, 0}, {1, 0}, {0, 1}}, Line[{1, 2, 3, 1}]];Show[ℛ, Graphics[{Red, Point[{1, 1}]}]]RegionNearest[ℛ, {1, 1}]ℛ = MeshRegion[{{0, 0}, {1, 0}, {0, 1}}, Polygon[{1, 2, 3}]];Show[ℛ, Graphics[{Red, Point[{1, 1}]}]]RegionNearest[ℛ, {1, 1}]The nearest point in a 0D MeshRegion in 3D:
ℛ = MeshRegion[{{0, 0, 0}, {0, 0, 1}, {0, 1, 0}, {1, 0, 0}}, Point[{{1}, {2}, {3}, {4}}]];Show[ℛ, Graphics3D[{Red, Point[{1, 1, 1}]}]]RegionNearest[ℛ, {1, 1, 1}]ℛ = MeshRegion[{{0, 0, 0}, {0, 0, 1}, {0, 1, 0}, {1, 0, 0}}, Line[{{1, 2, 3, 4, 1}}]];Show[ℛ, Graphics3D[{Red, Point[{1, 1, 1}]}]]RegionNearest[ℛ, {1, 1, 1}]ℛ = MeshRegion[{{0, 0, 0}, {0, 0, 1}, {0, 1, 0}, {1, 0, 0}}, Polygon[{{1, 2, 3}, {2, 3, 4}}]];Show[ℛ, Graphics3D[{Red, Point[{1, 1, 1}]}]]RegionNearest[ℛ, {1, 1, 1}]ℛ = MeshRegion[{{0, 0, 0}, {0, 0, 1}, {0, 1, 0}, {1, 0, 0}}, Tetrahedron[{{1, 2, 3, 4}}]];Show[ℛ, Graphics3D[{Red, Point[{1, 1, 1}]}]]RegionNearest[ℛ, {1, 1, 1}]Derived Regions (3)
The distance to a RegionIntersection:
ℛ = RegionIntersection[Disk[{0, 0}, 1], Disk[{0, 1}, 1]];RegionNearest[ℛ, {1, 1}]Show[Graphics[{Red, Point[{1, 1}]}], RegionPlot[ℛ]]The distance to a TransformedRegion:
ℛ = TransformedRegion[Disk[], ScalingTransform[{3, 2}]];RegionNearest[ℛ, {4, 3}]Show[DiscretizeRegion[ℛ, {{-3, 3}, {-2, 2}}], Graphics[{Red, Point[{4, 3}]}]]The distance to a RegionBoundary:
ℛ = RegionBoundary[Disk[]];RegionNearest[ℛ, {1 / 2, 1 / 2}]Graphics[{ℛ, Red, Point[{1 / 2, 1 / 2}]}]Applications (3)
Visualize the nearest points in a region:
ℛ = BoundaryDiscretizeRegion[ImplicitRegion[Abs[x]^1 / 2 + Abs[y]^1 / 2 ≤ 1, {x, y}], {{-1, 1}, {-1, 1}}];
nf = RegionNearest[ℛ];
pts = Flatten[Table[r{Cos[k 2π / 128], Sin[k 2π / 128]}, {k, 0, 127}, {r, 1, 2}], 1];
nst = nf[pts];The nearest points along two circles:
Show[ℛ, Graphics[{Thin, Gray, Line[Transpose[{pts, nst}]]}]]Visualize a region by mapping uniform points to the region using RegionNearest:
ℛ = BoundaryDiscretizeRegion[ImplicitRegion[Abs[x]^1 / 2 + Abs[y]^1 / 2 ≤ 1, {x, y}], {{-1, 1}, {-1, 1}}];
nf = RegionNearest[ℛ];
pts = RandomReal[{-1, 1}, {10000, 2}];
Graphics[{PointSize[Tiny], Point[nf[pts]]}]Find the altitude of a triangle:
{a, b, c} = {{0, 0}, {3, 0}, {1, 2}};base = InfiniteLine[{a, b}];foot = RegionNearest[base, c];altitude = Line[{c, foot}];Graphics[{{LightBlue, Triangle[{a, b, c}]}, {Thick, Darker@LightBlue, base}, {PointSize@Medium, Red, Point[{c, foot}]}, {Dashed, Red, altitude}}]Properties & Relations (4)
Only one point is returned in case there is a tie:
pt = {0, 0};
ℛ = Circle[pt, 1];n = RegionNearest[ℛ, pt]Visualize the nearest point chosen in red:
Graphics[{Point[pt], {Gray, ℛ}, {Red, Point[n]}}]A point is a RegionMember if the nearest point to the region is itself:
pt = {0, 0};
ℛ = Disk[pt, 1];RegionMember[ℛ, pt]pt === RegionNearest[ℛ, pt]RegionNearest is closely related to RegionDistance:
ℛ = Disk[];The distance to the nearest point is minimal:
EuclideanDistance[RegionNearest[ℛ, {5, 5}], {5, 5}]RegionDistance[ℛ, {5, 5}]FullSimplify[%% - %]Nearest gives nearest points for finite point regions:
pts = {{0, 1}, {2, 1}, {3, 3}};Nearest[pts, {0.5, 0.5}]RegionNearest[Point[pts], {0.5, 0.5}]Related Guides
History
Text
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.
APA
Wolfram Language. (2014). RegionNearest. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/RegionNearest.html
BibTeX
@misc{reference.wolfram_2026_regionnearest, author="Wolfram Research", title="{RegionNearest}", year="2014", howpublished="\url{https://reference.wolfram.com/language/ref/RegionNearest.html}", note=[Accessed: 12-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_regionnearest, organization={Wolfram Research}, title={RegionNearest}, year={2014}, url={https://reference.wolfram.com/language/ref/RegionNearest.html}, note=[Accessed: 12-June-2026]}