RegionDistance[reg,p]
给出从点 p 到区域 reg 的最小距离.
RegionDistance[reg1,reg2]
给出区域 reg1 和 reg2 中的点之间最小的距离.
RegionDistance[reg]
给出一个可以重复应用于不同点的 RegionDistanceFunction[…].
RegionDistance
RegionDistance[reg,p]
给出从点 p 到区域 reg 的最小距离.
RegionDistance[reg1,reg2]
给出区域 reg1 和 reg2 中的点之间最小的距离.
RegionDistance[reg]
给出一个可以重复应用于不同点的 RegionDistanceFunction[…].
更多信息和选项
- RegionDistance 也称为点到区域的距离,距离变换,距离场和最小区域距离.
- RegionDistance 测量两个区域之间的距离有多近.
- 点 q 与 p 之间的距离被视为 Norm[p-q].
- 实际上,RegionDistance[reg,p] 由 MinValue[{Norm[p-q],q∈reg},q] 给出.
- 实际上,RegionDistance[reg1,reg2] 由 MinValue[Norm[p-q],{p∈reg1,q∈reg2}] 给出.
- 除非区域是闭合的,否则最近距离可能不是通过区域中的点而是通过区域的闭包获得的.
范例
打开所有单元 关闭所有单元基本范例 (2)
RegionDistance[Disk[], {3, 3}]Plot3D[RegionDistance[Disk[], {x, y}], {x, -2, 2}, {y, -2, 2}]找到从一个点到一个 MeshRegion 的距离:
DelaunayMesh[RandomReal[1, {25, 2}]]用一个参数,得到一个 RegionDistanceFunction:
df = RegionDistance[%]df[RandomReal[2, {5, 2}]]范围 (17)
特殊区域 (9)
RegionDistance[Point[{{1, 1}, {1, 2}}], {3, 4}]RegionDistance[Point[{{0, 0, 0}, {1, 2, 3}}], {1, 1, 1}]ℛ = Point[{{1, 2}, {3, 4}, {5, 6}}];{Plot3D[RegionDistance[ℛ, {x, y}], {x, 0, 7}, {y, 0, 7}, MeshFunctions -> {#3&}, Mesh -> 5], ContourPlot[RegionDistance[ℛ, {x, y}], {x, -1, 7}, {y, 0, 8}, Contours -> {{0.5, Red}, {1, Green}, {1.5, Blue}}]}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}}];{Plot3D[RegionDistance[ℛ, {x, y}], {x, -1, 2}, {y, -1, 2}, MeshFunctions -> {#3&}, Mesh -> 5], ContourPlot[RegionDistance[ℛ, {x, y}], {x, -1, 2}, {y, -1, 2}, Contours -> {{0.5, Red}, {1, Green}, {1.5, Blue}}]}RegionDistance[Rectangle[{0, 0}, {1, 2}], {3, 4}]RegionDistance[Cuboid[{0, 0, 0}, {1, 2, 3}], {4, 5, 6}]ℛ = Rectangle[{0, 0}, {1, 2}];{Plot3D[RegionDistance[ℛ, {x, y}], {x, -1, 2}, {y, -1, 3}, MeshFunctions -> {#3&}, Mesh -> 5], ContourPlot[RegionDistance[ℛ, {x, y}], {x, -2, 3}, {y, -2, 4}, Contours -> {{0.5, Red}, {1, Green}, {1.5, Blue}}]}RegionDistance[Simplex[1], {2}]RegionDistance[Simplex[2], {1, 1}]RegionDistance[Simplex[3], {1, 1, 1}]ℛ = Simplex[2];{Plot3D[RegionDistance[ℛ, {x, y}], {x, -1, 2}, {y, -1, 2}, MeshFunctions -> {#3&}, Mesh -> 5], ContourPlot[RegionDistance[ℛ, {x, y}], {x, -2, 3}, {y, -2, 3}, Contours -> {{0.5, Red}, {1, Green}, {1.5, Blue}}]}RegionDistance[Disk[{0, 0}, 1], {1, 2}]RegionDistance[Ball[{0, 0, 0}, 1], {1, 2, 3}]ℛ = Disk[];{Plot3D[RegionDistance[ℛ, {x, y}], {x, -2, 2}, {y, -2, 2}, MeshFunctions -> {#3&}, Mesh -> 5], ContourPlot[RegionDistance[ℛ, {x, y}], {x, -3, 3}, {y, -3, 3}, Contours -> {{0.5, Red}, {1, Green}, {1.5, Blue}}]}RegionDistance[Disk[{0, 0}, {1, 2}], {0, 4}]RegionDistance[Ellipsoid[{0, 0, 0}, {1, 2, 3}], {0, 3, 4}]ℛ = Disk[{0, 0}, {1, 2}];{Plot3D[RegionDistance[ℛ, {x, y}], {x, -2, 2}, {y, -3, 3}, MeshFunctions -> {#3&}, Mesh -> 5, Exclusions -> Norm[{x, y / 2}] == 1], ContourPlot[RegionDistance[ℛ, {x, y}], {x, -3, 3}, {y, -4, 4}, Contours -> {{0.5, Red}, {1, Green}, {1.5, Blue}}]}RegionDistance[Circle[{0, 0}, 1], {1, 2}]RegionDistance[Circle[{0, 0}, {1, 2}], {0, 4}]ℛ = Circle[];{Plot3D[RegionDistance[ℛ, {x, y}], {x, -2, 2}, {y, -2, 2}, MeshFunctions -> {#3&}, Mesh -> 5, Exclusions -> Norm[{x, y}] == 1], ContourPlot[RegionDistance[ℛ, {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}]//Simplifyℛ = Cylinder[{{0, 0, 0}, {0, 0, 2}}];ContourPlot3D[Evaluate@RegionDistance[ℛ, {x, y, z}], {x, -3, 3}, {y, -3, 3}, {z, -2, 4}, Contours -> {0.5, 1.0, 1.5}, PlotTheme -> "Minimal", BaseStyle -> Opacity[0.5]]RegionDistance[Simplex[{{1, 0, 0, 0}, {0, 1, 0, 0}, {0, 0, 1, 0}, {0, 0, 0, 1}}], {1, 2, 3, 4}]RegionDistance[Cuboid[{1, 2, 3, 4, 5}, {6, 7, 8, 9, 10}], {11, 12, 13, 14, 15}]RegionDistance[Ball[{1, 2, 3, 4, 5, 6, 7}, 8], {9, 10, 11, 12, 13, 14, 15}]公式区域 (2)
表示为 ImplicitRegion 的到圆盘的距离:
ℛ = ImplicitRegion[x^2 + y^2 ≤ 1, {x, y}];RegionPlot[ℛ]RegionDistance[ℛ, {3, 4}]ℛ = ImplicitRegion[x^2 + y^2 ≤ 1.5, {x, y, {z, 0, 2}}];RegionDistance[ℛ, {3, 4, 5}]表示为 ParametricRegion 的到圆盘的距离:
ℛ = ParametricRegion[{r Cos[θ], r Sin[θ]}, {{r, 0, 1}, {θ, 0, 2π}}];RegionDistance[ℛ, {3, 4}]ℛ = ParametricRegion[{r(1 - t^2/1 + t^2), r(2t/1 + t^2)}, {t, {r, 0, 1}}];RegionDistance[ℛ, {3, 4}]ℛ = ParametricRegion[{r Cos[θ], r Sin[θ], z}, {{r, 0, 1}, {θ, 0, 2π}, {z, 0, 2}}];RegionDistance[ℛ, {3, 4, 5}]网格区域 (1)
到一维 BoundaryMeshRegion 的距离:
ℛ = BoundaryMeshRegion[{{0}, {1}}, Point[{{1}, {2}}]]RegionDistance[ℛ, {2}]ℛ = ConvexHullMesh[RandomReal[1, {10, 2}]];Show[ℛ, Graphics[{Red, Point[{1, 1}]}]]RegionDistance[ℛ, {1, 1}]ℛ = ConvexHullMesh[RandomReal[1, {20, 3}]];Show[ℛ, Graphics3D[{Red, Point[{1, 1, 1}]}]]RegionDistance[ℛ, {1, 1, 1}]导出区域 (3)
到 RegionIntersection 的距离:
ℛ = RegionIntersection[Disk[{0, 0}, 1], Disk[{0, 1}, 1]];RegionDistance[ℛ, {1, 1}]Show[Graphics[{Red, Point[{1, 1}]}], RegionPlot[ℛ]]到 TransformedRegion 的距离:
ℛ = TransformedRegion[Disk[], ScalingTransform[{3, 2}]];RegionDistance[ℛ, {4, 3}]Show[DiscretizeRegion[ℛ, {{-3, 3}, {-2, 2}}], Graphics[{Red, Point[{4, 3}]}]]到 RegionBoundary 的距离:
ℛ = RegionBoundary[Disk[]];RegionDistance[ℛ, {1 / 2, 1 / 2}]Graphics[{ℛ, Red, Point[{1 / 2, 1 / 2}]}]CSG 区域 (1)
到二维 CSGRegion 的距离:
ℛ = CSGRegion["Difference", {Disk[], Disk[{1 / 2, 1 / 2}]}];RegionDistance[ℛ, {1 / 2, 1 / 2}]Show[ℛ, Graphics[{Red, Point[{1 / 2, 1 / 2}]}]]ℛ = CSGRegion["Difference", {Cube[2], Cylinder[{{1, 1, 1}, {1, -1, 1}}]}];RegionDistance[ℛ, {1 / 2, 1, 1 / 2}]Show[ℛ, Graphics3D[{Red, Point[{1 / 2, 1, 1 / 2}]}]]细分区域 (1)
到 SubdivisionRegion 的距离:
ℛ = SubdivisionRegion[Rectangle[]];RegionDistance[ℛ, {1, 1}]Show[ℛ, Graphics[{Red, Point[{1, 1}]}]]ℛ = SubdivisionRegion[Cuboid[]];RegionDistance[ℛ, {1, 1, 1}]Show[ℛ, Graphics3D[{Red, Point[{1, 1, 1}]}]]应用 (5)
{a, b, c} = {{1, 0}, {4, 0}, {0, 2}};base = InfiniteLine[{a, b}];RegionDistance[base, c]Graphics[Triangle[{a, b, c}], Axes -> {False, True}, Epilog -> {Red, base}]circle = Circle[{0, 0}, 5];d = RegionDistance[circle, {x, y}];ℛ[r_] = ImplicitRegion[d ≤ r, {x, y}]RegionPlot[ℛ[2], Epilog -> {Red, circle}, PlotRange -> {{-8, 8}, {-8, 8}}]Subscript[ℛ, 1] = BoundaryDiscretizeGraphics@CountryData["France", "Shape"];Subscript[ℛ, 2] = Quiet@DiscretizeRegion[ImplicitRegion[Evaluate[RegionDistance[Subscript[ℛ, 1], {x, y}] ≤ 0.005], {x, y}]];{Subscript[ℛ, 1], Subscript[ℛ, 2]}从区域
到
的豪斯多夫有向距离被定义为
. 用 RegionDistance 计算从 =Triangle[{{0,0},{2,0},{0,1}}] 到 ℬ=Triangle[{{0,0},{1,0},{0,3/2}}] 的豪斯多夫有向距离:
𝒜 = Triangle[{{0, 0}, {2, 0}, {0, 1}}];
ℬ = Triangle[{{0, 0}, {1, 0}, {0, 3 / 2}}];Legended[Graphics[{Opacity[0.5], {Red, 𝒜}, {Blue, ℬ}}], SwatchLegend[{Red, Blue}, {"𝒜", "ℬ"}]]d1 = RegionDistance[𝒜, {x, y}]Plot3D[d1, {x, y}∈ℬ, PlotRange -> All]MaxValue[d1, {x, y}∈ℬ]如果
,可以得出结论
,其中
是
的闭包和
. 证明对于这个例子中的区域,
:
Show[RegionPlot[d1 ≤ 1 / 2, {x, -1, 3}, {y, -1, 5 / 2}], Graphics[{Opacity[0.5], {Red, 𝒜}, {Blue, ℬ}}]]区域
和
之间的豪斯多夫距离被定义为
,其中
是前一个例子中的豪斯多夫有向距离. 用 RegionDistance 计算 =Triangle[{{0,0},{2,0},{0,1}}] 和 ℬ=Triangle[{{0,0},{1,0},{0,3/2}}] 之间的豪斯多夫距离:
𝒜 = Triangle[{{0, 0}, {2, 0}, {0, 1}}];
ℬ = Triangle[{{0, 0}, {1, 0}, {0, 3 / 2}}];Legended[Graphics[{Opacity[0.5], {Red, 𝒜}, {Blue, ℬ}}], SwatchLegend[{Red, Blue}, {"𝒜", "ℬ"}]]hAB = MaxValue[RegionDistance[𝒜, {x, y}], {x, y}∈ℬ]hBA = MaxValue[RegionDistance[ℬ, {x, y}], {x, y}∈𝒜]dH = Max[hAB, hBA]如果
,可以得出结论
和
,就如在前一个例子中一样. 证明对于这个例子中的区域,
且
:
d1 = RegionDistance[𝒜, {x, y}];
d2 = RegionDistance[ℬ, {x, y}];Show[RegionPlot[{d1 ≤ 1, d2 ≤ 1}, {x, -1, 3}, {y, -1, 5 / 2}], Graphics[{Opacity[0.5], {Red, 𝒜}, {Blue, ℬ}}]]属性和关系 (4)
一个点是 RegionMember 如果它到区域的距离为0:
ℛ = Disk[{0, 0}, {3, 2}];Reduce[RegionMember[ℛ, {x, y}]⧦RegionDistance[ℛ, {x, y}] == 0, {x, y}, Reals]RegionDistance 是到区域任意一点的距离的 MinValue:
ℛ = Disk[{0, 0}, {3, 2}];d1 = RegionDistance[ℛ, {5, 5}];
d2 = MinValue[Norm[{5 - x, 5 - y}], {x, y}∈ℛ];FullSimplify[d1 == d2]RegionNearest 给出一个离输入距离最近的点:
ℛ = Disk[];Norm[{5, 5} - RegionNearest[ℛ, {5, 5}]] == RegionDistance[ℛ, {5, 5}]//FullSimplify对一个在区域外的点,RegionDistance 与 SignedRegionDistance 相同:
ℛ = Disk[];RegionDistance[ℛ, {2, 2}] == SignedRegionDistance[ℛ, {2, 2}]文本
Wolfram Research (2014),RegionDistance,Wolfram 语言函数,https://reference.wolfram.com/language/ref/RegionDistance.html (更新于 2023 年).
CMS
Wolfram 语言. 2014. "RegionDistance." Wolfram 语言与系统参考资料中心. Wolfram Research. 最新版本 2023. https://reference.wolfram.com/language/ref/RegionDistance.html.
APA
Wolfram 语言. (2014). RegionDistance. Wolfram 语言与系统参考资料中心. 追溯自 https://reference.wolfram.com/language/ref/RegionDistance.html 年
BibTeX
@misc{reference.wolfram_2026_regiondistance, author="Wolfram Research", title="{RegionDistance}", year="2023", howpublished="\url{https://reference.wolfram.com/language/ref/RegionDistance.html}", note=[Accessed: 03-November-2026]}
BibLaTeX
@online{reference.wolfram_2026_regiondistance, organization={Wolfram Research}, title={RegionDistance}, year={2023}, url={https://reference.wolfram.com/language/ref/RegionDistance.html}, note=[Accessed: 03-November-2026]}