RegionDistanceFunction[reg,…]
represents a function whose values give the distance from a point to the region reg.
RegionDistanceFunction
RegionDistanceFunction[reg,…]
represents a function whose values give the distance from a point to the region reg.
Details
- RegionDistanceFunction is also known as distance function, distance transform, signed distance function and signed distance transform.
- RegionDistanceFunction works like Function.
- RegionDistanceFunction is generated by RegionDistance[reg] or SignedRegionDistance[reg].
- If generated by RegionDistance, RegionDistanceFunction[reg,…][p] gives RegionDistance[reg,p].
- If generated by SignedRegionDistance, RegionDistanceFunction[reg,…][p] gives SignedRegionDistance[reg,p].
Examples
open all close allBasic Examples (1)
Scope (19)
Special Regions (8)
Point sets:
RegionDistance[Point[{{1, 1}, {1, 2}}]][{3, 4}]RegionDistance[Point[{{0, 0, 0}, {1, 2, 3}}]][{1, 1, 1}]Plot the distance from a three-point set:
ℛ = Point[{{1, 2}, {3, 4}, {5, 6}}];
df = RegionDistance[ℛ];{Plot3D[df[{x, y}], {x, 0, 7}, {y, 0, 7}, MeshFunctions -> {#3&}, Mesh -> 5], ContourPlot[df[{x, y}], {x, -1, 7}, {y, 0, 8}, Contours -> {{0.5, Red}, {1, Green}, {1.5, Blue}}]}Line:
RegionDistance[Line[{{0, 0}, {1, 1}}]][{3, 4}]RegionDistance[Line[{{0, 0, 0}, {1, 1, 1}, {0, 0, 1}}]][{1, 2, 3}]ℛ = Line[{{0, 0}, {1, 1}}];
df = RegionDistance[ℛ];{Plot3D[df[{x, y}], {x, -1, 2}, {y, -1, 2}, MeshFunctions -> {#3&}, Mesh -> 5], ContourPlot[df[{x, y}], {x, -1, 2}, {y, -1, 2}, Contours -> {{0.5, Red}, {1, Green}, {1.5, Blue}}]}Rectangle can be used in 2D:
RegionDistance[Rectangle[{0, 0}, {1, 2}]][{3, 4}]Cuboid generalizes it to any dimension:
RegionDistance[Cuboid[{0, 0, 0}, {1, 2, 3}]][{4, 5, 6}]Equidistance surfaces of a cuboid in 3D:
ℛ = Cuboid[{0, 0, 0}, {1, 1, 1}];
df = RegionDistance[ℛ];ContourPlot3D[Evaluate@df[{x, y, z}], {x, -1.1, 2.1}, {y, -1.1, 2.1}, {z, -1.1, 2.1}, Contours -> {0.25, 0.5, 1.0}, BaseStyle -> Opacity[0.5], Mesh -> None]Simplex can be used in any dimension:
RegionDistance[Simplex[2]][{1, 1}]RegionDistance[Simplex[3]][{1, 1, 1}]Plot the distance to a 2D simplex:
ℛ = Simplex[2];
df = RegionDistance[ℛ];{Plot3D[df[{x, y}], {x, -1, 2}, {y, -1, 2}, MeshFunctions -> {#3&}, Mesh -> 5], ContourPlot[df[{x, y}], {x, -2, 3}, {y, -2, 3}, Contours -> {{0.5, Red}, {1, Green}, {1.5, Blue}}]}Disk can be used in 2D:
RegionDistance[Disk[{0, 0}, 1]][{1, 2}]Ball generalizes a disk to any dimension:
RegionDistance[Ball[{0, 0, 0}, 1]][{1, 2, 3}]ℛ = Disk[];
df = RegionDistance[ℛ];{Plot3D[df[{x, y}], {x, -2, 2}, {y, -2, 2}, MeshFunctions -> {#3&}, Mesh -> 5], ContourPlot[df[{x, y}], {x, -3, 3}, {y, -3, 3}, Contours -> {{0.5, Red}, {1, Green}, {1.5, Blue}}]}Disk can be an ellipse in 2D:
RegionDistance[Disk[{0, 0}, {1, 2}]][{0, 4}]Ellipsoid generalizes this to any dimension:
RegionDistance[Ellipsoid[{0, 0, 0}, {1, 2, 3}]][{0, 3, 4}]Plot the distance to an ellipse:
ℛ = Disk[{0, 0}, {1, 2}];
df = RegionDistance[ℛ];{Plot3D[Evaluate@df[{x, y}], {x, -2, 2}, {y, -3, 3}, MeshFunctions -> {#3&}, Mesh -> 5, Exclusions -> Norm[{x, y / 2}] == 1], ContourPlot[Evaluate@df[{x, y}], {x, -3, 3}, {y, -4, 4}, Contours -> {{0.5, Red}, {1, Green}, {1.5, Blue}}, Exclusions -> None]}Circle can be elliptical:
RegionDistance[Circle[{0, 0}, {2, 1}]][{4, 0}]Plot the distance to a circle:
ℛ = Circle[];
df = RegionDistance[ℛ];{Plot3D[df[{x, y}], {x, -2, 2}, {y, -2, 2}, MeshFunctions -> {#3&}, Mesh -> 5, Exclusions -> Norm[{x, y}] == 1], ContourPlot[df[{x, y}], {x, -3, 3}, {y, -3, 3}, Contours -> {{0.5, Red}, {1, Green}, {1.5, Blue}}]}RegionDistance[Cylinder[{{0, 0, 0}, {0, 0, 2}}, 1]][{1, 1, 1}]//SimplifyRegionDistance[Cone[{{0, 0, 0}, {0, 0, 2}}, 1]][{1, 1, 1}]//SimplifyEquidistance contours for a cylinder:
ℛ = Cylinder[{{0, 0, 0}, {0, 0, 2}}];
df = RegionDistance[ℛ];ContourPlot3D[Evaluate@df[{x, y, z}], {x, -3, 3}, {y, -3, 3}, {z, -2, 4}, Contours -> {0.25, 0.5, 1.0}, BaseStyle -> Opacity[0.5], Mesh -> None]Formula Regions (2)
The distance to a disk represented as an ImplicitRegion:
ℛ = ImplicitRegion[x^2 + y^2 ≤ 1, {x, y}];df = RegionDistance[ℛ];{Plot3D[Evaluate@df[{x, y}], {x, -2, 2}, {y, -2, 2}, MeshFunctions -> {#3&}, Mesh -> 5, Exclusions -> Norm[{x, y}] == 1], ContourPlot[Evaluate@df[{x, y}], {x, -3, 3}, {y, -3, 3}, Contours -> {{0.5, Red}, {1, Green}, {1.5, Blue}}, Exclusions -> None]}df[RandomReal[{-2, 2}, {20, 2}]]ℛ = ImplicitRegion[x^2 + y^2 ≤ 1, {x, y, {z, 0, 2}}];df = RegionDistance[ℛ, WorkingPrecision -> 10];df[RandomReal[{-2, 2}, {20, 3}]]The distance to a disk represented as a ParametricRegion:
ℛ = ParametricRegion[{r Cos[θ], r Sin[θ]}, {{r, 0, 1}, {θ, 0, 2π}}];df = RegionDistance[ℛ];df[RandomReal[{-2, 2}, {20, 2}]]Using a rational parametrization of the disk:
ℛ = ParametricRegion[{r(1 - t^2/1 + t^2), r(2t/1 + t^2)}, {t, {r, 0, 1}}];df = RegionDistance[ℛ];df[RandomReal[{-2, 2}, {20, 2}]]Mesh Regions (4)
The distance to a 1D BoundaryMeshRegion:
ℛ = BoundaryMeshRegion[{{0}, {1}}, Point[{{1}, {2}}]]df = RegionDistance[ℛ];
df[{2}]ℛ = ConvexHullMesh[RandomReal[1, {10, 2}]];df = RegionDistance[ℛ];
{Plot3D[df[{x, y}], {x, -1, 2}, {y, -1, 2}, MeshFunctions -> {#3&}, Mesh -> 5], ContourPlot[df[{x, y}], {x, -2, 3}, {y, -2, 3}, Contours -> {{0.5, Red}, {1, Green}, {1.5, Blue}}]}The distance to a 0D MeshRegion in 1D:
ℛ = MeshRegion[{{0}, {1}}, Point[{{1}, {2}}]]df = RegionDistance[ℛ];
df[{1 / 2}]ℛ = MeshRegion[{{0}, {1}}, Line[{1, 2}]]df = RegionDistance[ℛ];
df[{2}]The distance to a 0D MeshRegion in 2D:
ℛ = MeshRegion[{{0, 0}, {1, 0}, {0, 1}}, Point[{{1}, {2}, {3}}]];Show[ℛ, Graphics[{Red, Point[{1, 1}]}]]df = RegionDistance[ℛ];
df[{1, 1}]ℛ = MeshRegion[{{0, 0}, {1, 0}, {0, 1}}, Line[{1, 2, 3, 1}]];Show[ℛ, Graphics[{Red, Point[{1, 1}]}]]df = RegionDistance[ℛ];
df[{1, 1}]ℛ = MeshRegion[{{0, 0}, {1, 0}, {0, 1}}, Polygon[{1, 2, 3}]];df = RegionDistance[ℛ];
{Plot3D[df[{x, y}], {x, -1, 2}, {y, -1, 2}, MeshFunctions -> {#3&}, Mesh -> 5], ContourPlot[df[{x, y}], {x, -2, 3}, {y, -2, 3}, Contours -> {{0.5, Red}, {1, Green}, {1.5, Blue}}]}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}]}]]df = RegionDistance[ℛ];
df[{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}]}]]df = RegionDistance[ℛ];
df[{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}]}]]df = RegionDistance[ℛ];
df[{1, 1, 1}]ℛ = MeshRegion[{{0, 0, 0}, {0, 0, 1}, {0, 1, 0}, {1, 0, 0}}, Tetrahedron[{{1, 2, 3, 4}}]];df = RegionDistance[ℛ];
ContourPlot3D[df[{x, y, z}], {x, -1, 2}, {y, -1, 2}, {z, -1, 2}, Contours -> {0.25, 0.5, 0.95}, BaseStyle -> Opacity[0.5], Mesh -> None]Derived Regions (3)
The distance to a RegionIntersection:
ℛ = RegionIntersection[Disk[{0, 0}, 1], Disk[{0, 1}, 1]];df = RegionDistance[ℛ];
df[{1, 1}]Show[Graphics[{Red, Point[{1, 1}]}], RegionPlot[ℛ]]The distance to a TransformedRegion:
ℛ = TransformedRegion[Disk[], ScalingTransform[{3, 2}]];df = RegionDistance[ℛ];
df[{4, 3}]Show[DiscretizeRegion[ℛ, {{-3, 3}, {-2, 2}}], Graphics[{Red, Point[{4, 3}]}]]The distance to a RegionBoundary:
ℛ = RegionBoundary[Disk[]];df = RegionDistance[ℛ];
df[{1 / 2, 1 / 2}]Graphics[{ℛ, Red, Point[{1 / 2, 1 / 2}]}]CSG Regions (1)
The distance to a CSGRegion in 2D:
ℛ = CSGRegion["Difference", {Disk[], Disk[{1 / 2, 1 / 2}]}];df = RegionDistance[ℛ];
df[{0, 0}]Show[ℛ, Graphics[{Red, Point[{0, 0}]}]]ℛ = CSGRegion["Difference", {Cube[2], Cylinder[{{1, 1, 1}, {1, -1, 1}}]}];df = RegionDistance[ℛ];
df[{1, 1, 1}]Show[ℛ, Graphics3D[{Red, Point[{1, 1, 1}]}]]Subdivision Regions (1)
The distance to a SubdivisionRegion in 2D:
ℛ = SubdivisionRegion[Rectangle[]];df = RegionDistance[ℛ];
df[{1, 1}]Show[ℛ, Graphics[{Red, Point[{1, 1}]}]]ℛ = SubdivisionRegion[Tetrahedron[]];df = RegionDistance[ℛ];
df[{0.1, 0.1, 0.1}]Show[ℛ, Graphics3D[{Red, Point[{0.1, 0.1, 0.1}]}]]Applications (3)
Create a region that is a distance
from a Triangle:
df = RegionDistance[Triangle[]];ℛ[r_] = ImplicitRegion[df[{x, y}] <= r, {x, y}]Visualize the region and triangle:
Region[ℛ[2 / 3], Epilog -> Triangle[]]Create a region that is a distance
from the given points:
df = RegionDistance[Point[{{0, 0, 0}, {1, 1, 1}}]];ℛ[r_] = ImplicitRegion[df[{x, y, z}] <= r, {x, y, z}]BoundaryDiscretizeRegion[ℛ[1]]Create a region that is a distance
from a Cuboid:
df = RegionDistance[Cuboid[]];ℛ[r_] = ImplicitRegion[df[{x, y, z}] <= r, {x, y, z}]RegionPlot3D[ℛ[2]]Properties & Relations (1)
RegionDistanceFunction gives the same value when applied to a point as RegionDistance:
ℛ = MeshRegion[{{0, 0}, {1, 0}, {0, 1}}, Polygon[{1, 2, 3}]];
df = RegionDistance[ℛ];
pts = RandomReal[1, {10, 2}];df[pts] == (RegionDistance[ℛ, #]& /@ pts)Related Guides
History
Text
Wolfram Research (2014), RegionDistanceFunction, Wolfram Language function, https://reference.wolfram.com/language/ref/RegionDistanceFunction.html.
CMS
Wolfram Language. 2014. "RegionDistanceFunction." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/RegionDistanceFunction.html.
APA
Wolfram Language. (2014). RegionDistanceFunction. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/RegionDistanceFunction.html
BibTeX
@misc{reference.wolfram_2026_regiondistancefunction, author="Wolfram Research", title="{RegionDistanceFunction}", year="2014", howpublished="\url{https://reference.wolfram.com/language/ref/RegionDistanceFunction.html}", note=[Accessed: 12-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_regiondistancefunction, organization={Wolfram Research}, title={RegionDistanceFunction}, year={2014}, url={https://reference.wolfram.com/language/ref/RegionDistanceFunction.html}, note=[Accessed: 12-June-2026]}