Wolfram Function Repository
Instant-use add-on functions for the Wolfram Language
Function Repository Resource:
Generate the power diagram of a set of circles
| ResourceFunction["PowerDiagram"][{c1,c2,…}] gives a MeshRegion representing the power diagram of the circles c1,c2, …. | |
| ResourceFunction["PowerDiagram"][{c1,c2,…},{{xmin,xmax},…}] clips the mesh to the bounds [xmin,xmax]×⋯. | 
Generate the power diagram of a set of circles:
| In[1]:= | ![circles = Table[Circle[RandomVariate[NormalDistribution[], 2], RandomReal[{0, 1/2}]], {10}];
\[ScriptCapitalR] = ResourceFunction["PowerDiagram"][circles]](https://www.wolframcloud.com/obj/resourcesystem/images/a84/a8461ba6-2be8-4c61-afdd-6da8273806c7/3703636874796c0a.png) | 
| Out[1]= |  | 
Show the power diagram with the generating circles:
| In[2]:= | ![Show[\[ScriptCapitalR], Graphics[{Orange, circles}]]](https://www.wolframcloud.com/obj/resourcesystem/images/a84/a8461ba6-2be8-4c61-afdd-6da8273806c7/48f96092042de5bc.png) | 
| Out[2]= |  | 
Create a power diagram from a set of disks:
| In[3]:= | ![cl = Table[Disk[RandomReal[{-2, 2}, {2}], RandomReal[{0, 1/4}]], {20}];
\[ScriptCapitalR] = ResourceFunction["PowerDiagram"][cl]](https://www.wolframcloud.com/obj/resourcesystem/images/a84/a8461ba6-2be8-4c61-afdd-6da8273806c7/5fb7e08539a6f18f.png) | 
| Out[3]= |  | 
Basic properties:
| In[4]:= | ![{RegionQ[\[ScriptCapitalR]], MeshRegionQ[\[ScriptCapitalR]]}](https://www.wolframcloud.com/obj/resourcesystem/images/a84/a8461ba6-2be8-4c61-afdd-6da8273806c7/2ae6158f802e37f2.png) | 
| Out[4]= |  | 
Power diagrams are full dimensional:
| In[5]:= | ![{RegionDimension[\[ScriptCapitalR]], RegionEmbeddingDimension[\[ScriptCapitalR]]}](https://www.wolframcloud.com/obj/resourcesystem/images/a84/a8461ba6-2be8-4c61-afdd-6da8273806c7/1e0de36904562e1e.png) | 
| Out[5]= |  | 
Power diagrams are bounded by their clipping values:
| In[6]:= | ![{BoundedRegionQ[\[ScriptCapitalR]], RegionBounds[\[ScriptCapitalR]]}](https://www.wolframcloud.com/obj/resourcesystem/images/a84/a8461ba6-2be8-4c61-afdd-6da8273806c7/50d2a3fcd725e8ca.png) | 
| Out[6]= |  | 
Generate the power diagram of a mixture of Circle and Disk objects:
| In[7]:= | ![cl = Table[
   RandomChoice[{Circle, Disk}][
    RandomVariate[NormalDistribution[], 2], RandomReal[{0, 1/2}]], {10}];
ResourceFunction["PowerDiagram"][cl]](https://www.wolframcloud.com/obj/resourcesystem/images/a84/a8461ba6-2be8-4c61-afdd-6da8273806c7/25add84108f4849c.png) | 
| Out[7]= |  | 
MeshCellHighlight allows you to specify highlighting for parts of a PowerDiagram:
| In[8]:= | ![ResourceFunction["PowerDiagram"][
 Table[Disk[RandomReal[1, 2], RandomReal[]], {5}], MeshCellHighlight -> {{1, All} -> Red, {0, All} -> Black}]](https://www.wolframcloud.com/obj/resourcesystem/images/a84/a8461ba6-2be8-4c61-afdd-6da8273806c7/74ba62dab2833b70.png) | 
| Out[8]= |  | 
Individual cells can be highlighted using their cell index:
| In[9]:= | ![ResourceFunction["PowerDiagram"][
 Table[Disk[RandomReal[1, 2], RandomReal[]], {5}], MeshCellHighlight -> {{1, 1} -> {Thick, Red}, {1, 2} -> {Dashed, Black}}]](https://www.wolframcloud.com/obj/resourcesystem/images/a84/a8461ba6-2be8-4c61-afdd-6da8273806c7/50baa9efa7aa41f2.png) | 
| Out[9]= |  | 
Or by the cell itself:
| In[10]:= | ![ResourceFunction["PowerDiagram"][
 Table[Disk[RandomReal[1, 2], RandomReal[]], {5}], MeshCellHighlight -> {Line[{1, 2}] -> {Thick, Red}, Line[{2, 3}] -> {Dashed, Black}}]](https://www.wolframcloud.com/obj/resourcesystem/images/a84/a8461ba6-2be8-4c61-afdd-6da8273806c7/0375db803c273a14.png) | 
| Out[10]= |  | 
MeshCellLabel can be used to label parts of a PowerDiagram:
| In[11]:= | ![ResourceFunction["PowerDiagram"][
 Table[Disk[RandomReal[1, 2], RandomReal[]], {5}], MeshCellLabel -> {0 -> "Index"}]](https://www.wolframcloud.com/obj/resourcesystem/images/a84/a8461ba6-2be8-4c61-afdd-6da8273806c7/1c4912c88676432b.png) | 
| Out[11]= |  | 
Individual cells can be labeled using their cell index:
| In[12]:= | ![ResourceFunction["PowerDiagram"][
 Table[Disk[RandomReal[1, 2], RandomReal[]], {5}], MeshCellLabel -> {{1, 1} -> "x", {1, 2} -> "y"}]](https://www.wolframcloud.com/obj/resourcesystem/images/a84/a8461ba6-2be8-4c61-afdd-6da8273806c7/5afe5272ac9d9b3f.png) | 
| Out[12]= |  | 
Or by the cell itself:
| In[13]:= | ![ResourceFunction["PowerDiagram"][
 Table[Disk[RandomReal[1, 2], RandomReal[]], {5}], MeshCellLabel -> {Line[{2, 3}] -> "x", Line[{1, 2}] -> "y"}]](https://www.wolframcloud.com/obj/resourcesystem/images/a84/a8461ba6-2be8-4c61-afdd-6da8273806c7/53cc48e30350ba18.png) | 
| Out[13]= |  | 
MeshCellMarker can be used to assign values to parts of a PowerDiagram:
| In[14]:= | ![ResourceFunction["PowerDiagram"][
 Table[Disk[RandomReal[1, 2], RandomReal[]], {5}], MeshCellMarker -> {{0, 1} -> 1, {0, 2} -> 2, {0, 3} -> 3, {0, 4} -> 4, {0, 5} -> 5}]](https://www.wolframcloud.com/obj/resourcesystem/images/a84/a8461ba6-2be8-4c61-afdd-6da8273806c7/4a3a792941fa5d29.png) | 
| Out[14]= |  | 
Use MeshCellLabel to show the markers:
| In[15]:= | ![ResourceFunction["PowerDiagram"][
 Table[Disk[RandomReal[1, 2], RandomReal[]], {5}], MeshCellMarker -> {{0, 1} -> 1, {0, 2} -> 2, {0, 3} -> 3, {0, 4} -> 4, {0, 5} -> 5}, MeshCellLabel -> {0 -> "Marker"}]](https://www.wolframcloud.com/obj/resourcesystem/images/a84/a8461ba6-2be8-4c61-afdd-6da8273806c7/744d89c23532ef81.png) | 
| Out[15]= |  | 
MeshCellStyle allows you to specify styling for parts of a PowerDiagram:
| In[16]:= | ![ResourceFunction["PowerDiagram"][
 Table[Disk[RandomReal[1, 2], RandomReal[]], {5}], MeshCellStyle -> {{1, All} -> Red, {0, All} -> Black}]](https://www.wolframcloud.com/obj/resourcesystem/images/a84/a8461ba6-2be8-4c61-afdd-6da8273806c7/579a554a425e49bd.png) | 
| Out[16]= |  | 
Individual cells can be highlighted using their cell index:
| In[17]:= | ![ResourceFunction["PowerDiagram"][
 Table[Disk[RandomReal[1, 2], RandomReal[]], {5}], MeshCellStyle -> {{1, 3} -> {Thick, Red}, {1, 2} -> {Dashed, Black}}]](https://www.wolframcloud.com/obj/resourcesystem/images/a84/a8461ba6-2be8-4c61-afdd-6da8273806c7/4d8dc0370aa3865c.png) | 
| Out[17]= |  | 
Or by the cell itself:
| In[18]:= | ![ResourceFunction["PowerDiagram"][
 Table[Disk[RandomReal[1, 2], RandomReal[]], {5}], MeshCellStyle -> {Line[{2, 3}] -> {Thick, Red}, Line[{1, 2}] -> {Dashed, Black}}]](https://www.wolframcloud.com/obj/resourcesystem/images/a84/a8461ba6-2be8-4c61-afdd-6da8273806c7/04639977addd4096.png) | 
| Out[18]= |  | 
Use a theme with grid lines and a legend:
| In[19]:= | ![ResourceFunction["PowerDiagram"][
 Table[Disk[RandomReal[1, 2], RandomReal[]], {10}], PlotTheme -> "Detailed"]](https://www.wolframcloud.com/obj/resourcesystem/images/a84/a8461ba6-2be8-4c61-afdd-6da8273806c7/19e8478440fce36d.png) | 
| Out[19]= |  | 
Use a theme to draw a wireframe:
| In[20]:= | ![ResourceFunction["PowerDiagram"][
 Table[Disk[RandomReal[1, 2], RandomReal[]], {10}], PlotTheme -> "Lines"]](https://www.wolframcloud.com/obj/resourcesystem/images/a84/a8461ba6-2be8-4c61-afdd-6da8273806c7/513ce2a6b08cede9.png) | 
| Out[20]= |  | 
The output of PowerDiagram is always a full-dimensional MeshRegion:
| In[21]:= | ![circles = Table[Circle[RandomVariate[NormalDistribution[], 2], RandomReal[{0, 1/2}]], {10}];
ResourceFunction["PowerDiagram"][circles]](https://www.wolframcloud.com/obj/resourcesystem/images/a84/a8461ba6-2be8-4c61-afdd-6da8273806c7/3d5a9186e88ae3c7.png) | 
| Out[21]= |  | 
| In[22]:= | ![{MeshRegionQ[%], RegionDimension[%]}](https://www.wolframcloud.com/obj/resourcesystem/images/a84/a8461ba6-2be8-4c61-afdd-6da8273806c7/61bc9d9ef68b5f3d.png) | 
| Out[22]= |  | 
The power diagram of two circles is composed of two half-planes divided by the radical line of the two circles:
| In[23]:= | ![radicalLine[Circle[c1_, r1_], Circle[c2_, r2_]] := With[{u = 1/2 (1 + (r1^2 - r2^2)/SquaredEuclideanDistance[c1, c2])}, InfiniteLine[(1 - u) c1 + u c2, Cross[c2 - c1]]]
Show[ResourceFunction[
  "PowerDiagram"][{Circle[{0, 0}, 1], Circle[{2, 2}, 1/3]}], Graphics[{Brown, Circle[{0, 0}, 1], Circle[{2, 2}, 1/3], Directive[Dashed, Orange], radicalLine[Circle[{0, 0}, 1], Circle[{2, 2}, 1/3]]}]]](https://www.wolframcloud.com/obj/resourcesystem/images/a84/a8461ba6-2be8-4c61-afdd-6da8273806c7/635ae2b04353edaa.png) | 
| Out[23]= |  | 
If one circle encloses the other, the cell corresponding to the inner circle is empty:
| In[24]:= | ![Show[ResourceFunction[
  "PowerDiagram"][{Circle[{0, 0}, 1], Circle[{2/5, 1/2}, 1/6]}, {{-3/2, 3/2}, {-3/2, 3/2}}], Graphics[{Brown, Circle[{0, 0}, 1], Circle[{2/5, 1/2}, 1/6], Directive[Dashed, Orange], radicalLine[Circle[{0, 0}, 1], Circle[{2/5, 1/2}, 1/6]]}]]](https://www.wolframcloud.com/obj/resourcesystem/images/a84/a8461ba6-2be8-4c61-afdd-6da8273806c7/365298dbf5d90156.png) | 
| Out[24]= |  | 
The power diagram of a set of circles all having the same radii is equivalent to the VoronoiMesh of the circles' centers:
| In[25]:= | ![circles = Table[Circle[RandomVariate[NormalDistribution[], 2], 0.2], {10}];
GraphicsRow[{ResourceFunction["PowerDiagram"][circles], VoronoiMesh[First /@ circles]}]](https://www.wolframcloud.com/obj/resourcesystem/images/a84/a8461ba6-2be8-4c61-afdd-6da8273806c7/3d34f8ca86fb94f2.png) | 
| Out[25]= |  | 
The resource function PowerTriangulation is the dual of PowerDiagram:
| In[26]:= | ![circles = Table[Circle[RandomReal[{-7/2, 7/2}, 2], RandomReal[1/3]], {30}];
pt = HighlightMesh[
   ResourceFunction["PowerTriangulation"][circles], {Style[0, Black], Style[1, Orange], Style[2, Opacity[0.5]]}];
pd = HighlightMesh[
   ResourceFunction["PowerDiagram"][circles], {Style[1, Green], Style[2, Opacity[0.2]]}];
Show[pt, pd, Graphics[{Brown, circles}]]](https://www.wolframcloud.com/obj/resourcesystem/images/a84/a8461ba6-2be8-4c61-afdd-6da8273806c7/7363100618433599.png) | 
| Out[29]= |  | 
This work is licensed under a Creative Commons Attribution 4.0 International License