---
title: "MeshConnectivityGraph"
language: "en"
type: "Symbol"
summary: "MeshConnectivityGraph[mr, 0] gives a graph of points connected by lines. MeshConnectivityGraph[mr, d] gives a graph between cells of dimension d that share a cell of dimension d - 1. MeshConnectivityGraph[mr, {d, e}, r] gives a graph from cells of dimension d to cells of dimension e that share a cell of dimension r."
keywords: 
- mesh connectivity
- mesh connectivity graph
- mesh connectivity matrix
- mesh adjacency graph
- mesh adjacency matrix
- mesh incidence graph
- mesh incidence matrix
- face face connectivity graph
- face face connectivity matrix
- face edge connectivity graph
- face edge connectivity matrix
- face point connectivity graph
- face point connectivity matrix
- edge edge connectivity graph
- edge edge connectivity matrix
- edge point connectivity graph
- edge point connectivity matrix
- point point connectivity graph
- point point connectivity matrix
canonical_url: "https://reference.wolfram.com/language/ref/MeshConnectivityGraph.html"
source: "Wolfram Language Documentation"
related_guides: 
  - 
    title: "Mesh-Based Geometric Regions"
    link: "https://reference.wolfram.com/language/guide/MeshRegions.en.md"
  - 
    title: "Graph Construction & Representation"
    link: "https://reference.wolfram.com/language/guide/GraphConstructionAndRepresentation.en.md"
related_functions: 
  - 
    title: "MeshRegion"
    link: "https://reference.wolfram.com/language/ref/MeshRegion.en.md"
  - 
    title: "BoundaryMeshRegion"
    link: "https://reference.wolfram.com/language/ref/BoundaryMeshRegion.en.md"
  - 
    title: "Graph"
    link: "https://reference.wolfram.com/language/ref/Graph.en.md"
  - 
    title: "AdjacencyMatrix"
    link: "https://reference.wolfram.com/language/ref/AdjacencyMatrix.en.md"
---
# MeshConnectivityGraph

MeshConnectivityGraph[mr, 0] gives a graph of points connected by lines.

MeshConnectivityGraph[mr, d] gives a graph between cells of dimension d that share a cell of dimension d - 1.

MeshConnectivityGraph[mr, {d, e}, r] gives a graph from cells of dimension d to cells of dimension e that share a cell of dimension r.

## Details and Options

* ``MeshConnectivityGraph`` is also known as mesh adjacency graph and mesh incidence graph.

* Typical uses include getting cell adjacencies and topological information in a mesh.

[image]

* A vertex ``{d, i}`` in the connectivity graph corresponds to the cell ``cd, i`` with dimension ``d`` and index ``i`` in the mesh ``mr``.

* An undirected edge in ``MeshConnectivityGraph[mr, d]``connects two vertices ``{d, i}`` and ``{d, j}`` whenever the cells ``cd, i`` and ``cd, j`` both have a common subcell of dimension ``d - 1``. For ``d = 0``, the common subcell has dimension 1.

* Common cases for ``d`` are:

|         |   |                                |
| ------- | - | ------------------------------ |
| [image] | 0 | points that share a line       |
| [image] | 1 | lines that share a point       |
| [image] | 2 | polygons that share an edge    |
| [image] | 3 | polyhedra that share a polygon |

* In ``MeshConnectivityGraph[mr, {d, e}, r]``, a directed edge connects the vertex ``{d, i}`` to the vertex ``{e, j}`` whenever the cells ``cd, i`` and ``ce, j`` have a common cell of dimension ``r`` that is either a subset or a superset of ``cd, i`` and ``ce, j``.

* ``MeshConnectivityGraph[mr]`` is effectively equivalent to ``MeshConnectivityGraph[mr, 0]``.

* ``MeshConnectivityGraph[mr, d, r]`` is equivalent to the undirected graph of the graph ``MeshConnectivityGraph[mr, {d, d}, r]``.

* ``MeshConnectivityGraph`` takes the same options as ``Graph`` with the following changes:

[`AnnotationRules`](https://reference.wolfram.com/language/ref/AnnotationRules.en.md) 	``Inherited``

### List of all options

|                        |                 |                                                                                    |
| ---------------------- | --------------- | ---------------------------------------------------------------------------------- |
| AlignmentPoint         | Center          | the default point in the graphic to align with                                     |
| AnnotationRules        | {}              | annotations for graph, edges and vertices                                          |
| AspectRatio            | Automatic       | ratio of height to width                                                           |
| Axes                   | False           | whether to draw axes                                                               |
| AxesLabel              | None            | axes labels                                                                        |
| AxesOrigin             | Automatic       | where axes should cross                                                            |
| AxesStyle              | {}              | style specifications for the axes                                                  |
| Background             | None            | background color for the plot                                                      |
| BaselinePosition       | Automatic       | how to align with a surrounding text baseline                                      |
| BaseStyle              | {}              | base style specifications for the graphic                                          |
| ContentSelectable      | Automatic       | whether to allow contents to be selected                                           |
| CoordinatesToolOptions | Automatic       | detailed behavior of the coordinates tool                                          |
| DirectedEdges          | Automatic       | whether to interpret Rule as DirectedEdge                                          |
| EdgeLabels             | None            | labels and label placements for edges                                              |
| EdgeLabelStyle         | Automatic       | style to use for edge labels                                                       |
| EdgeShapeFunction      | Automatic       | generate graphic shapes for edges                                                  |
| EdgeStyle              | Automatic       | style used for edges                                                               |
| EdgeWeight             | Automatic       | weights for edges                                                                  |
| Epilog                 | {}              | primitives rendered after the main plot                                            |
| FormatType             | TraditionalForm | the default format type for text                                                   |
| Frame                  | False           | whether to put a frame around the plot                                             |
| FrameLabel             | None            | frame labels                                                                       |
| FrameStyle             | {}              | style specifications for the frame                                                 |
| FrameTicks             | Automatic       | frame ticks                                                                        |
| FrameTicksStyle        | {}              | style specifications for frame ticks                                               |
| GraphHighlight         | {}              | graph elements to highlight                                                        |
| GraphHighlightStyle    | Automatic       | style for highlight                                                                |
| GraphLayout            | Automatic       | how to lay out vertices and edges                                                  |
| GridLines              | None            | grid lines to draw                                                                 |
| GridLinesStyle         | {}              | style specifications for grid lines                                                |
| ImageMargins           | 0.              | the margins to leave around the graphic                                            |
| ImagePadding           | All             | what extra padding to allow for labels etc.                                        |
| ImageSize              | Automatic       | the absolute size at which to render the graphic                                   |
| LabelStyle             | {}              | style specifications for labels                                                    |
| Method                 | Automatic       | details of graphics methods to use                                                 |
| PerformanceGoal        | Automatic       | aspects of performance to try to optimize                                          |
| PlotLabel              | None            | an overall label for the plot                                                      |
| PlotRange              | All             | range of values to include                                                         |
| PlotRangeClipping      | False           | whether to clip at the plot range                                                  |
| PlotRangePadding       | Automatic       | how much to pad the range of values                                                |
| PlotRegion             | Automatic       | the final display region to be filled                                              |
| PlotTheme              | \$PlotTheme     | overall theme for the graph                                                        |
| PreserveImageOptions   | Automatic       | whether to preserve image options when displaying new versions of the same graphic |
| Prolog                 | {}              | primitives rendered before the main plot                                           |
| RotateLabel            | True            | whether to rotate y labels on the frame                                            |
| Ticks                  | Automatic       | axes ticks                                                                         |
| TicksStyle             | {}              | style specifications for axes ticks                                                |
| VertexCoordinates      | Automatic       | coordinates for vertices                                                           |
| VertexLabels           | None            | labels and placements for vertices                                                 |
| VertexLabelStyle       | Automatic       | style to use for vertex labels                                                     |
| VertexShape            | Automatic       | graphic shape for vertices                                                         |
| VertexShapeFunction    | Automatic       | generate graphic shapes for vertices                                               |
| VertexSize             | Medium          | size of vertices                                                                   |
| VertexStyle            | Automatic       | styles for vertices                                                                |
| VertexWeight           | Automatic       | weights for vertices                                                               |

---

## Examples (101)

### Basic Examples (2)

Construct a connectivity graph between cells of dimension 0 in a mesh:

```wl
In[1]:= mesh = MengerMesh[2]

Out[1]= [image]
```

Points are connected if they shared the same edges:

```wl
In[2]:= g = MeshConnectivityGraph[mesh, 0]

Out[2]= [image]
```

Find a shortest path between two vertices of cell indices ``{0, 1}`` and ``{0, 96}`` :

```wl
In[3]:= FindShortestPath[g, {0, 1}, {0, 96}]

Out[3]= {{0, 1}, {0, 2}, {0, 4}, {0, 6}, {0, 8}, {0, 10}, {0, 12}, {0, 14}, {0, 16}, {0, 18}, {0, 20}, {0, 30}, {0, 40}, {0, 48}, {0, 56}, {0, 64}, {0, 76}, {0, 86}, {0, 96}}
```

Highlight the path:

```wl
In[4]:= HighlightGraph[g, PathGraph[%]]

Out[4]= [image]
```

---

Get the connectivity matrix between faces of an icosahedron:

```wl
In[1]:= MeshConnectivityGraph[Icosahedron[], {2, 2}]

Out[1]= [image]
```

The adjacency matrix:

```wl
In[2]:= AdjacencyMatrix[%]

Out[2]=
SparseArray[Automatic, {20, 20}, 0, 
 {1, {{0, 3, 6, 9, 12, 15, 18, 21, 24, 27, 30, 33, 36, 39, 42, 45, 48, 51, 54, 57, 60}, 
   {{2}, {5}, {11}, {1}, {3}, {12}, {2}, {4}, {13}, {3}, {5}, {14}, {1}, {4}, {15}, {7}, {10}, 
    {16}, {6}, {8}, {17},  ... 5}, {8}, {11}, {15}, {9}, {11}, {12}, {10}, {12}, {13}}}, 
  {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 
   1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}}]
```

### Scope (4)

``MeshConnectivityGraph`` works on ``MeshRegion`` :

```wl
In[1]:= MeshConnectivityGraph[[image], 0]

Out[1]= [image]
```

``BoundaryMeshRegion`` :

```wl
In[2]:= MeshConnectivityGraph[[image], 0]

Out[2]= [image]
```

Linear regions:

```wl
In[3]:= MeshConnectivityGraph[Rectangle[], 0]

Out[3]= [image]
```

---

``MeshConnectivityGraph`` works on all dimensions:

```wl
In[1]:= Table[MeshConnectivityGraph[[image], d], {d, {0, 1, 2, 3}}]

Out[1]= {[image], [image], [image], [image]}
```

---

Construct a connectivity graph between cells of dimension 0 in a mesh:

```wl
In[1]:= MeshConnectivityGraph[[image], 0]

Out[1]= [image]
```

Between cells of dimension 0 and 1:

```wl
In[2]:= MeshConnectivityGraph[[image], {0, 1}]

Out[2]= [image]
```

Between cells of dimension 0 and 0 sharing the same face:

```wl
In[3]:= MeshConnectivityGraph[[image], {0, 0}, 2]

Out[3]= [image]
```

---

By default, ``AnnotationRules -> Inherited`` annotations are preserved:

```wl
In[1]:= MeshConnectivityGraph[Triangle[], {0, 1}]

Out[1]= [image]

In[2]:= VertexList[%]

Out[2]= {{0, 1}, {0, 2}, {0, 3}, {1, 1}, {1, 2}, {1, 3}}
```

With the setting ``AnnotationRules -> None``, annotations are not preserved and the graph is indexed:

```wl
In[3]:= MeshConnectivityGraph[Triangle[], 0, AnnotationRules -> None]

Out[3]= [image]

In[4]:= VertexList[%]

Out[4]= {1, 2, 3}
```

### Options (81)

#### AnnotationRules (4)

Specify an annotation for vertices:

```wl
In[1]:= MeshConnectivityGraph[Triangle[], 0, AnnotationRules -> {1 -> {VertexLabels -> "hello"}}]

Out[1]= [image]
```

---

Edges:

```wl
In[1]:= MeshConnectivityGraph[Triangle[], 0, AnnotationRules -> {1\[UndirectedEdge]2 -> {EdgeLabels -> "hello"}}]

Out[1]= [image]
```

---

Graph itself:

```wl
In[1]:= MeshConnectivityGraph[Triangle[], 0, AnnotationRules -> {"GraphProperties" -> {"Message" -> "hello"}}]

Out[1]= [image]

In[2]:= AnnotationValue[%, "Message"]

Out[2]= "hello"
```

---

With the setting ``AnnotationRules -> None``, annotations are not preserved and the graph is indexed:

```wl
In[1]:= MeshConnectivityGraph[Triangle[], 0, AnnotationRules -> None]

Out[1]= [image]

In[2]:= VertexList[%]

Out[2]= {1, 2, 3}
```

#### DirectedEdges (1)

By default, a directed path is generated when computing connectivity between cells of different dimensions:

```wl
In[1]:= MeshConnectivityGraph[Triangle[], {0, 1}]

Out[1]= [image]
```

Use ``DirectedEdges -> False`` to interpret rules as undirected edges:

```wl
In[2]:= MeshConnectivityGraph[Triangle[], {0, 1}, DirectedEdges -> False]

Out[2]= [image]
```

#### EdgeLabels (7)

Label the edge ``{0, 1}\[UndirectedEdge]{0, 2}``:

```wl
In[1]:= MeshConnectivityGraph[Triangle[], 0, EdgeLabels -> {{0, 1}\[UndirectedEdge]{0, 2} -> "Hello"}]

Out[1]= [image]
```

---

Label all edges individually:

```wl
In[1]:= el = EdgeList[MeshConnectivityGraph[Triangle[], 0]];

In[2]:= MeshConnectivityGraph[Triangle[], 0, EdgeLabels -> Table[el[[i]] -> Subscript["e", i], {i, Length[el]}]]

Out[2]= [image]
```

---

Use any expression as a label:

```wl
In[1]:= MeshConnectivityGraph[Triangle[], 0, EdgeLabels -> {{0, 1}\[UndirectedEdge]{0, 2} -> [image], {0, 2}\[UndirectedEdge]{0, 3} -> [image], {0, 3}\[UndirectedEdge]{0, 1} -> [image]}]

Out[1]= [image]
```

---

Use ``Placed`` with symbolic locations to control label placement along an edge:

```wl
In[1]:= Table[MeshConnectivityGraph[Triangle[], 0, EdgeLabels -> {{0, 1}\[UndirectedEdge]{0, 2} -> Placed["■■■", p]}, PlotLabel -> p], {p, {"Start", "Middle", "End"}}]

Out[1]= {[image], [image], [image]}
```

---

Use explicit coordinates to place labels:

```wl
In[1]:= Table[MeshConnectivityGraph[Triangle[], 0, EdgeLabels -> {{0, 2}\[UndirectedEdge]{0, 3} -> Placed["■■■", p]}, PlotLabel -> p, BaselinePosition -> Bottom], {p, {0, 1 / 4, 1 / 3}}]

Out[1]= {[image], [image], [image]}
```

Vary positions within the label:

```wl
In[2]:= Table[MeshConnectivityGraph[Triangle[], 0, EdgeLabels -> {{0, 1}\[UndirectedEdge]{0, 2} -> Placed["■■■", {1 / 2, p}]}, PlotLabel -> p, BaselinePosition -> Bottom], {p, {{0, 0}, {1 / 2, 1 / 2}, {1, 1}}}]

Out[2]= {[image], [image], [image]}
```

---

Place multiple labels:

```wl
In[1]:= MeshConnectivityGraph[Triangle[], 0, EdgeLabels -> {{0, 3}\[UndirectedEdge]{0, 1} -> Placed[{"lbl1", "lbl2"}, {"Start", "End"}]}]

Out[1]= [image]

In[2]:= MeshConnectivityGraph[Triangle[], 0, EdgeLabels -> {{0, 3}\[UndirectedEdge]{0, 1} -> Placed[{"lbl1", "lbl2", "lbl3"}, {"Start", "Middle", "End"}]}]

Out[2]= [image]
```

---

Use automatic labeling by values through ``Tooltip`` and ``StatusArea``:

```wl
In[1]:= MeshConnectivityGraph[Triangle[], 0, EdgeLabels -> Placed["Name", Tooltip]]

Out[1]= [image]

In[2]:= MeshConnectivityGraph[Triangle[], 0, EdgeLabels -> Placed["Name", StatusArea]]

Out[2]= [image]
```

#### EdgeShapeFunction (6)

Get a list of built-in settings for ``EdgeShapeFunction``:

```wl
In[1]:= ResourceData["EdgeShapeFunction"]

Out[1]= {"Arrow", "BoxLine", "CarvedArcArrow", "CarvedArrow", "DashedLine", "DiamondLine", "DotLine", "DottedLine", "FilledArcArrow", "FilledArrow", "HalfFilledArrow", "HalfFilledDoubleArrow", "HalfUnfilledArrow", "HalfUnfilledDoubleArrow", "Line", "ShortCarvedArcArrow", "ShortCarvedArrow", "ShortFilledArcArrow", "ShortFilledArrow", "ShortUnfilledArcArrow", "ShortUnfilledArrow", "UnfilledArcArrow", "UnfilledArrow"}
```

---

Undirected edges including the basic line:

```wl
In[1]:= MeshConnectivityGraph[Triangle[], 0, EdgeShapeFunction -> "Line"]

Out[1]= [image]
```

Lines with different glyphs on the edges:

```wl
In[2]:= Table[MeshConnectivityGraph[Triangle[], 0, EdgeShapeFunction -> {{ef, "ArrowSize" -> 0.1}}, PlotLabel -> ef], {ef, {"BoxLine", "DiamondLine", "DotLine"}}]

Out[2]= {[image], [image], [image]}
```

---

Directed edges including solid arrows:

```wl
In[1]:= Table[MeshConnectivityGraph[Triangle[], 0, EdgeShapeFunction -> {{ef, "ArrowSize" -> 0.1}}, PlotLabel -> ef], {ef, ResourceData["EdgeShapeFunction", "FilledArrow"]}]

Out[1]= {[image], [image], [image], [image], [image], [image]}
```

Line arrows:

```wl
In[2]:= Table[MeshConnectivityGraph[Triangle[], 0, EdgeShapeFunction -> {{ef, "ArrowSize" -> 0.1}}, PlotLabel -> ef], {ef, ResourceData["EdgeShapeFunction", "UnfilledArrow"]}]

Out[2]= {[image], [image], [image], [image], [image], [image]}
```

Open arrows:

```wl
In[3]:= Table[MeshConnectivityGraph[Triangle[], 0, EdgeShapeFunction -> {{ef, "ArrowSize" -> 0.1}}, PlotLabel -> ef], {ef, ResourceData["EdgeShapeFunction", "CarvedArrow"]}]

Out[3]= {[image], [image], [image], [image]}
```

---

Specify an edge function for an individual edge:

```wl
In[1]:= MeshConnectivityGraph[Triangle[], 0, EdgeShapeFunction -> {{0, 1}\[UndirectedEdge]{0, 2} -> "DotLine"}]

Out[1]= [image]
```

Combine with a different default edge function:

```wl
In[2]:= MeshConnectivityGraph[Triangle[], 0, EdgeShapeFunction -> {{0, 1}\[UndirectedEdge]{0, 2} -> "BoxLine", "DotLine"}]

Out[2]= [image]
```

---

Draw edges by running a program:

```wl
In[1]:=
ef[pts_List, e_] := 
	Block[{s = 0.015, g = [image]}, {Arrowheads[{{s, 0.33, g}, {s, 0.67, g}}], Arrow[pts]}]

In[2]:= MeshConnectivityGraph[Triangle[], 0, EdgeShapeFunction -> ef]

Out[2]= [image]
```

---

``EdgeShapeFunction`` can be combined with ``EdgeStyle``:

```wl
In[1]:= MeshConnectivityGraph[Triangle[], 0, EdgeStyle -> Blue, EdgeShapeFunction -> (Line[#1]&)]

Out[1]= [image]
```

``EdgeShapeFunction`` has higher priority than ``EdgeStyle``:

```wl
In[2]:= MeshConnectivityGraph[Triangle[], 0, EdgeStyle -> Blue, EdgeShapeFunction -> ({Red, Line[#1]}&)]

Out[2]= [image]
```

#### EdgeStyle (2)

Style all edges:

```wl
In[1]:= Table[MeshConnectivityGraph[Triangle[], 0, EdgeStyle -> style], {style, {Gray, Dashed, Thick}}]

Out[1]= {[image], [image], [image]}
```

---

Style individual edges:

```wl
In[1]:= MeshConnectivityGraph[Triangle[], 0, EdgeStyle -> {{0, 1}\[UndirectedEdge]{0, 2} -> Blue, {0, 1}\[UndirectedEdge]{0, 3} -> Dashed}]

Out[1]= [image]
```

#### EdgeWeight (2)

Specify a weight for all edges:

```wl
In[1]:= MeshConnectivityGraph[Triangle[], 0, EdgeWeight -> RandomInteger[5, 3]]

Out[1]= [image]

In[2]:= WeightedAdjacencyMatrix[%]//MatrixForm

Out[2]//MatrixForm=
(⁠|   |   |   |
| - | - | - |
| 0 | 0 | 0 |
| 0 | 0 | 1 |
| 0 | 1 | 0 |⁠)
```

---

Use any numeric expression as a weight:

```wl
In[1]:= MeshConnectivityGraph[Triangle[], 0, EdgeWeight -> {a, b, c}]

Out[1]= [image]

In[2]:= WeightedAdjacencyMatrix[%]//MatrixForm

Out[2]//MatrixForm=
(⁠|   |   |   |
| - | - | - |
| 0 | a | b |
| a | 0 | c |
| b | c | 0 |⁠)
```

#### GraphHighlight (3)

Highlight the vertex ``1`` :

```wl
In[1]:= MeshConnectivityGraph[Triangle[], 0, VertexSize -> Tiny, GraphHighlight -> {{0, 1}}]

Out[1]= [image]
```

---

Highlight the edge ``{0, 2}\[UndirectedEdge]{0, 3}`` :

```wl
In[1]:= MeshConnectivityGraph[Triangle[], 0, VertexSize -> Tiny, GraphHighlight -> {{0, 2}\[UndirectedEdge]{0, 3}}]

Out[1]= [image]
```

---

Highlight vertices and edges:

```wl
In[1]:= MeshConnectivityGraph[Triangle[], 0, VertexSize -> Tiny, GraphHighlight -> {{0, 1}, {0, 2}, {0, 1}\[UndirectedEdge]{0, 2}}]

Out[1]= [image]
```

#### GraphHighlightStyle (2)

Get a list of built-in settings for ``GraphHighlightStyle``:

```wl
In[1]:= ResourceData["GraphHighlightStyle"]

Out[1]= {Automatic, "Dashed", "Dotted", "Thick", "VertexConcaveDiamond", "VertexDiamond", "VertexTriangle", "DehighlightFade", "DehighlightGray", "DehighlightHide"}
```

---

Use built-in settings for ``GraphHighlightStyle`` :

```wl
In[1]:= MeshConnectivityGraph[Triangle[], 0, GraphHighlight -> {{0, 1}, {0, 2}\[UndirectedEdge]{0, 3}}, VertexSize -> Small, GraphHighlightStyle -> #, PlotLabel -> #]& /@ Select[ResourceData["GraphHighlightStyle"], # =!= Automatic&]

Out[1]= {[image], [image], [image], [image], [image], [image], [image], [image], [image]}
```

#### GraphLayout (5)

By default, the layout is chosen automatically:

```wl
In[1]:= MeshConnectivityGraph[MengerMesh[2], 0, GraphLayout -> Automatic]

Out[1]= [image]
```

---

Specify layouts on special curves:

```wl
In[1]:= Table[MeshConnectivityGraph[MengerMesh[1], 0, GraphLayout -> l, PlotLabel -> l], {l, {"CircularEmbedding", "SpiralEmbedding"}}]

Out[1]= {[image], [image]}
```

---

Specify layouts that satisfy optimality criteria:

```wl
In[1]:= Table[MeshConnectivityGraph[MengerMesh[2], 0, GraphLayout -> l, PlotLabel -> l], {l, {"SpringEmbedding", "SpringElectricalEmbedding", "HighDimensionalEmbedding"}}]

Out[1]= {[image], [image], [image]}
```

---

``VertexCoordinates`` overrides ``GraphLayout`` coordinates:

```wl
In[1]:=
{MeshConnectivityGraph[Triangle[], 0, GraphLayout -> "SpringElectricalEmbedding"], 
	MeshConnectivityGraph[Triangle[], 0, GraphLayout -> "SpringElectricalEmbedding", VertexCoordinates -> Table[{i, i}, {i, 0, 2}]]}

Out[1]= {[image], [image]}
```

---

Use ``AbsoluteOptions`` to extract ``VertexCoordinates`` computed using a layout algorithm:

```wl
In[1]:= MeshConnectivityGraph[Triangle[], 0]

Out[1]= [image]

In[2]:= AbsoluteOptions[%, VertexCoordinates]

Out[2]= {VertexCoordinates -> {{0., 0.}, {1., 0.}, {0., 1.}}}
```

#### PlotTheme (4)

##### Base Themes (2)

---

Use a common base theme:

```wl
In[1]:= MeshConnectivityGraph[Triangle[], 0, PlotTheme -> "Business"]

Out[1]= [image]
```

---

Use a monochrome theme:

```wl
In[1]:= MeshConnectivityGraph[Triangle[], 0, PlotTheme -> "Monochrome"]

Out[1]= [image]
```

##### Feature Themes (2)

---

Use a large graph theme:

```wl
In[1]:= MeshConnectivityGraph[Triangle[], 0, PlotTheme -> "LargeGraph"]

Out[1]= [image]
```

---

Use a classic diagram theme:

```wl
In[1]:= MeshConnectivityGraph[Triangle[], 0, PlotTheme -> "ClassicDiagram"]

Out[1]= [image]
```

#### VertexCoordinates (2)

By default, any vertex coordinates are computed automatically:

```wl
In[1]:= MeshConnectivityGraph[Triangle[], 0]

Out[1]= [image]
```

Extract the resulting vertex coordinates using ``AbsoluteOptions``:

```wl
In[2]:= AbsoluteOptions[%, VertexCoordinates]

Out[2]= {VertexCoordinates -> {{0., 0.}, {1., 0.}, {0., 1.}}}
```

---

Specify a layout function along an ellipse:

```wl
In[1]:= ellipseLayout[n_, {a_, b_}] := Table[{a Cos[2Pi / n u], b Sin[2Pi / n u]}, {u, 1, n}]

In[2]:= Graphics[Point[ellipseLayout[16, {2, 1}]]]

Out[2]= [image]
```

Use it to generate vertex coordinates for a graph:

```wl
In[3]:= MeshConnectivityGraph[MengerMesh[1], 0, VertexCoordinates -> ellipseLayout[16, {2, 1}]]

Out[3]= [image]
```

#### VertexLabels (13)

Use vertex names as labels:

```wl
In[1]:= MeshConnectivityGraph[Triangle[], 0, VertexLabels -> "Name"]

Out[1]= [image]
```

---

Label individual vertices:

```wl
In[1]:= MeshConnectivityGraph[Triangle[], 0, VertexLabels -> {{0, 1} -> "one"}]

Out[1]= [image]
```

---

Label all vertices:

```wl
In[1]:= MeshConnectivityGraph[Triangle[], 0, VertexLabels -> Table[{0, i} -> Subscript[v, i], {i, 3}]]

Out[1]= [image]
```

---

Use any expression as a label:

```wl
In[1]:= MeshConnectivityGraph[Triangle[], 0, VertexLabels -> {{0, 1} -> **[image]**, {0, 2} -> [image], {0, 3} -> [image]}]

Out[1]= [image]
```

---

Use ``Placed`` with symbolic locations to control label placement, including outside positions:

```wl
In[1]:= Table[MeshConnectivityGraph[Triangle[], 0, VertexSize -> 0.1, VertexShapeFunction -> "Square", VertexLabels -> Table[{0, i} -> Placed["■■■", p], {i, 3}], PlotLabel -> p, ImagePadding -> 20], {p, {Before, After, Below, Above}}]

Out[1]= {[image], [image], [image], [image]}
```

---

Symbolic outside corner positions:

```wl
In[1]:= pl = {{Before, Below}, {After, Below}, {Before, Above}, {After, Above}};

In[2]:= Table[MeshConnectivityGraph[Triangle[], 0, VertexSize -> 0.1, VertexShapeFunction -> "Square", ImagePadding -> 20, VertexLabels -> Table[{0, i} -> Placed["■■■", p], {i, 3}], PlotLabel -> p], {p, pl}]

Out[2]= {[image], [image], [image], [image]}
```

---

Symbolic inside positions:

```wl
In[1]:= Table[MeshConnectivityGraph[Triangle[], 03, VertexSize -> 0.25, VertexLabels -> Table[{0, i} -> Placed["■■■", p], {i, 3}], VertexShapeFunction -> "Square", PlotLabel -> p], {p, {Left, Top, Right, Bottom}}]

Out[1]= {[image], [image], [image], [image]}
```

---

Symbolic inside corner positions:

```wl
In[1]:= pl = {{Left, Bottom}, {Right, Bottom}, {Left, Top}, {Right, Top}};

In[2]:= Table[MeshConnectivityGraph[Triangle[], 0, VertexSize -> 0.25, VertexShapeFunction -> "Square", VertexLabels -> Table[{0, i} -> Placed["■■■", p], {i, 3}], PlotLabel -> p], {p, pl}]

Out[2]= {[image], [image], [image], [image]}
```

---

Use explicit coordinates to place the center of labels:

```wl
In[1]:= Table[MeshConnectivityGraph[Triangle[], 0, VertexSize -> 0.25, VertexShapeFunction -> "Square", VertexLabels -> Table[{0, i} -> Placed[[image], p], {i, 3}], PlotLabel -> p, BaselinePosition -> Bottom], {p, {{0, 0}, {1 / 2, 1 / 2}, {1, 1}}}]

Out[1]= {[image], [image], [image]}
```

---

Place all labels at the upper-right corner of the vertex and vary the coordinates within the label:

```wl
In[1]:= Table[MeshConnectivityGraph[Triangle[], 0, VertexSize -> 0.35, VertexShapeFunction -> "Square", VertexLabels -> Table[{0, i} -> Placed[[image], {{1, 1}, p}], {i, 3}], PlotLabel -> p, BaselinePosition -> Bottom], {p, {{0, 0}, {1 / 2, 1 / 2}, {1, 1}}}]

Out[1]= {[image], [image], [image]}
```

---

Place multiple labels:

```wl
In[1]:= MeshConnectivityGraph[Triangle[], 0, VertexLabels -> {{0, 1} -> Placed[{"lbl1", "lbl2"}, {Above, Below}]}]

Out[1]= [image]
```

Any number of labels can be used:

```wl
In[2]:= MeshConnectivityGraph[Triangle[], 0, VertexLabels -> {{0, 1} -> Placed[{"lbl1", "lbl2", "lbl3", "lbl4"}, {Above, After, Below, Before}]}]

Out[2]= [image]
```

---

Use the argument to ``Placed`` to control formatting including ``Tooltip``:

```wl
In[1]:= MeshConnectivityGraph[Triangle[], 0, VertexLabels -> Placed["Name", Tooltip]]

Out[1]= [image]
```

Or ``StatusArea``:

```wl
In[2]:= MeshConnectivityGraph[Triangle[], 0, VertexLabels -> Placed["Name", StatusArea]]

Out[2]= [image]
```

---

Use more elaborate formatting functions:

```wl
In[1]:= rotateLabel[lab_] := Rotate[lab, 45Degree]

In[2]:= MeshConnectivityGraph[Triangle[], 0, VertexLabels -> Table[{0, i} -> Placed["xxx", Below, rotateLabel], {i, 3}]]

Out[2]= [image]

In[3]:= panelLabel[lab_] := Panel[lab, FrameMargins -> 0, Background -> Lighter[Yellow, 0.7]]

In[4]:= MeshConnectivityGraph[Triangle[], 0, VertexLabels -> Table[{0, i} -> Placed["xxx", Center, panelLabel], {i, 3}]]

Out[4]= [image]

In[5]:= hyperlinkLabel[lab_] := Hyperlink[lab, "http://www.wolfram.com"]

In[6]:= MeshConnectivityGraph[Triangle[], 0, VertexLabels -> Table[{0, i} -> Placed["xxx", Center, hyperlinkLabel], {i, 3}]]

Out[6]= [image]
```

#### VertexShape (5)

Use any ``Graphics``, ``Image`` or ``Graphics3D`` as a vertex shape:

```wl
In[1]:= Table[MeshConnectivityGraph[Triangle[], 0, VertexShape -> s, VertexSize -> Medium], {s, {[image], [image], [image]}}]

Out[1]= {[image], [image], [image]}
```

---

Specify vertex shapes for individual vertices:

```wl
In[1]:= MeshConnectivityGraph[Triangle[], 0, VertexShape -> {{0, 2} -> [image]}, VertexSize -> Small]

Out[1]= [image]
```

---

``VertexShape`` can be combined with ``VertexSize``:

```wl
In[1]:= Table[MeshConnectivityGraph[Triangle[], 0, VertexSize -> s, VertexShape -> [image], PlotLabel -> s], {s, {Small, Large}}]

Out[1]= {[image], [image]}
```

---

``VertexShape`` is not affected by ``VertexStyle``:

```wl
In[1]:= MeshConnectivityGraph[Triangle[], 0, VertexSize -> 0.2, VertexShape -> [image], VertexStyle -> Blue]

Out[1]= [image]
```

---

``VertexShapeFunction`` has higher priority than ``VertexShape`` :

```wl
In[1]:= MeshConnectivityGraph[Triangle[], 0, VertexSize -> 0.1, VertexShapeFunction -> "Square", VertexShape -> [image]]

Out[1]= [image]
```

#### VertexShapeFunction (10)

Get a list of built-in collections for ``VertexShapeFunction``:

```wl
In[1]:= ResourceData["VertexShapeFunction"]

Out[1]= {"Capsule", "Circle", "ConcaveDiamond", "ConcaveHexagon", "ConcavePentagon", "ConcaveSquare", "ConcaveTriangle", "Diamond", "DownTrapezoid", "FiveDown", "Hexagon", "Octagon", "Parallelogram", "Pentagon", "Point", "Rectangle", "RoundedDiamond", "RoundedDownTrapezoid", "RoundedFiveDown", "RoundedHexagon", "RoundedParallelogram", "RoundedPentagon", "RoundedRectangle", "RoundedSquare", "RoundedTriangle", "RoundedUpTrapezoid", "Square", "Star", "Triangle", "UpTrapezoid"}
```

---

Use built-in settings for ``VertexShapeFunction`` in the ``"Basic"`` collection:

```wl
In[1]:= ResourceData["VertexShapeFunction", "Basic"]

Out[1]= {"Capsule", "Circle", "Diamond", "DownTrapezoid", "FiveDown", "Hexagon", "Octagon", "Parallelogram", "Pentagon", "Point", "Rectangle", "Square", "Star", "Triangle", "UpTrapezoid"}
```

Simple basic shapes:

```wl
In[2]:= Table[MeshConnectivityGraph[Triangle[], 0, VertexShapeFunction -> vf, VertexSize -> 0.2, PlotLabel -> vf], {vf, {"Triangle", "Square", "Rectangle", "Pentagon", "Hexagon", "Octagon"}}]

Out[2]= {[image], [image], [image], [image], [image], [image]}
```

Common basic shapes:

```wl
In[3]:= Table[MeshConnectivityGraph[Triangle[], 0, VertexShapeFunction -> vf, VertexSize -> 0.2, PlotLabel -> vf], {vf, {"DownTrapezoid", "UpTrapezoid", "Parallelogram", "FiveDown", "Circle", "Diamond", "Star", "Capsule"}}]

Out[3]= {[image], [image], [image], [image], [image], [image], [image], [image]}
```

---

Use built-in settings for ``VertexShapeFunction`` in the ``"Rounded"`` collection:

```wl
In[1]:= ResourceData["VertexShapeFunction", "Rounded"]

Out[1]= {"RoundedDiamond", "RoundedDownTrapezoid", "RoundedFiveDown", "RoundedHexagon", "RoundedParallelogram", "RoundedPentagon", "RoundedRectangle", "RoundedSquare", "RoundedTriangle", "RoundedUpTrapezoid"}

In[2]:= Table[MeshConnectivityGraph[Triangle[], 0, VertexShapeFunction -> vf, VertexSize -> 0.2, PlotLabel -> vf], {vf, ResourceData["VertexShapeFunction", "Rounded"]}]

Out[2]= {[image], [image], [image], [image], [image], [image], [image], [image], [image], [image]}
```

---

Use built-in settings for ``VertexShapeFunction`` in the ``"Concave"`` collection:

```wl
In[1]:= ResourceData["VertexShapeFunction", "Concave"]

Out[1]= {"ConcaveDiamond", "ConcaveHexagon", "ConcavePentagon", "ConcaveSquare", "ConcaveTriangle"}

In[2]:= Table[MeshConnectivityGraph[Triangle[], 0, VertexShapeFunction -> vf, VertexSize -> 0.2, PlotLabel -> vf], {vf, ResourceData["VertexShapeFunction", "Concave"]}]

Out[2]= {[image], [image], [image], [image], [image]}
```

---

Draw individual vertices:

```wl
In[1]:= MeshConnectivityGraph[Triangle[], 0, VertexShapeFunction -> { {0, 1} -> "Square"}, VertexSize -> 0.2]

Out[1]= [image]
```

Combine with a default vertex function:

```wl
In[2]:= MeshConnectivityGraph[Triangle[], 0, VertexShapeFunction -> { {0, 1} -> "Square", "Triangle"}, VertexSize -> 0.2]

Out[2]= [image]
```

---

Draw vertices using a predefined graphic:

```wl
In[1]:= MeshConnectivityGraph[Triangle[], 0, VertexShapeFunction -> (Inset[[image], #]&)]

Out[1]= [image]
```

---

Draw vertices by running a program:

```wl
In[1]:=
vf[{xc_, yc_}, name_, {w_, h_}] := 
	Block[{xmin = xc - w, xmax = xc + w, ymin = yc - h, ymax = yc + h}, 
	Polygon[{{xmin, ymin}, {xmax, ymax}, {xmin, ymax}, {xmax, ymin}}]
	];

In[2]:= MeshConnectivityGraph[Triangle[], 0, VertexShapeFunction -> vf, VertexSize -> 0.2]

Out[2]= [image]
```

---

``VertexShapeFunction`` can be combined with ``VertexStyle``:

```wl
In[1]:= vf1[{xc_, yc_}, name_, {w_, h_}] := Rectangle[{xc - w, yc - h}, {xc + w, yc + h}]

In[2]:= MeshConnectivityGraph[Triangle[], 0, VertexSize -> 0.2, VertexStyle -> Blue, VertexShapeFunction -> vf1]

Out[2]= [image]
```

``VertexShapeFunction`` has higher priority than ``VertexStyle``:

```wl
In[3]:= vf2[{xc_, yc_}, name_, {w_, h_}] := {Red, Rectangle[{xc - w, yc - h}, {xc + w, yc + h}]}

In[4]:= MeshConnectivityGraph[Triangle[], 0, VertexSize -> 0.2, VertexStyle -> Blue, VertexShapeFunction -> vf2]

Out[4]= [image]
```

---

``VertexShapeFunction`` can be combined with ``VertexSize``:

```wl
In[1]:= MeshConnectivityGraph[Triangle[], 0, VertexShapeFunction -> "Star", VertexSize -> {{0, 1} -> Small, Medium}]

Out[1]= [image]
```

---

``VertexShapeFunction`` has higher priority than ``VertexShape``:

```wl
In[1]:= MeshConnectivityGraph[Triangle[], 0, VertexSize -> 0.3, VertexShapeFunction -> "Star", VertexShape -> [image]]

Out[1]= [image]
```

#### VertexSize (8)

By default, the size of vertices is computed automatically:

```wl
In[1]:= MeshConnectivityGraph[Triangle[], 0, VertexSize -> Automatic]

Out[1]= [image]
```

---

Specify the size of all vertices using symbolic vertex size:

```wl
In[1]:= Table[MeshConnectivityGraph[Triangle[], 0, VertexSize -> s, PlotLabel -> s], {s, {Tiny, Small, Medium, Large}}]

Out[1]= {[image], [image], [image], [image]}
```

---

Use a fraction of the minimum distance between vertex coordinates:

```wl
In[1]:= Table[MeshConnectivityGraph[Triangle[], 0, VertexSize -> s, PlotLabel -> s], {s, 0.1, 1, 0.3}]

Out[1]= {[image], [image], [image], [image]}
```

---

Use a fraction of the overall diagonal for all vertex coordinates:

```wl
In[1]:= Table[MeshConnectivityGraph[Triangle[], 0, VertexSize -> {"Scaled", s}, PlotLabel -> {"Scaled", s}], {s, 0.1, 1, 0.3}]

Out[1]= {[image], [image], [image], [image]}
```

---

Specify size in both the $x$ and $y$ directions:

```wl
In[1]:= Table[MeshConnectivityGraph[Triangle[], 0, VertexSize -> s, PlotLabel -> s], {s, {{0.1, 0.2}, {0.2, 0.1}}}]

Out[1]= {[image], [image]}
```

---

Specify the size for individual vertices:

```wl
In[1]:= MeshConnectivityGraph[Triangle[], 0, VertexSize -> {{0, 1} -> 0.2, {0, 2} -> 0.3}]

Out[1]= [image]
```

---

``VertexSize`` can be combined with ``VertexShapeFunction`` :

```wl
In[1]:= Table[MeshConnectivityGraph[Triangle[], 0, VertexSize -> s, VertexShapeFunction -> "Square", PlotLabel -> s], {s, {0.05, 0.1, 0.2}}]

Out[1]= {[image], [image], [image]}
```

---

``VertexSize`` can be combined with ``VertexShape`` :

```wl
In[1]:= Table[MeshConnectivityGraph[Triangle[], 0, VertexSize -> s, VertexShape -> [image], PlotLabel -> s], {s, {0.1, 0.2, 0.4}}]

Out[1]= {[image], [image], [image]}
```

#### VertexStyle (5)

Style all vertices:

```wl
In[1]:= Table[MeshConnectivityGraph[Triangle[], 0, VertexStyle -> style, VertexSize -> 0.3], {style, {Yellow, EdgeForm@Dashed}}]

Out[1]= {[image], [image]}
```

---

Style individual vertices:

```wl
In[1]:= MeshConnectivityGraph[Triangle[], 0, VertexStyle -> {{0, 1} -> Blue, {0, 2} -> Red}, VertexSize -> 0.2]

Out[1]= [image]
```

---

``VertexShapeFunction`` can be combined with ``VertexStyle``:

```wl
In[1]:= vf1[{xc_, yc_}, name_, {w_, h_}] := Rectangle[{xc - w, yc - h}, {xc + w, yc + h}]

In[2]:= MeshConnectivityGraph[Triangle[], 0, VertexSize -> 0.2, VertexStyle -> Blue, VertexShapeFunction -> vf1]

Out[2]= [image]
```

``VertexShapeFunction`` has higher priority than ``VertexStyle``:

```wl
In[3]:= vf2[{xc_, yc_}, name_, {w_, h_}] := {Red, Rectangle[{xc - w, yc - h}, {xc + w, yc + h}]}

In[4]:= MeshConnectivityGraph[Triangle[], 0, VertexSize -> 0.2, VertexStyle -> Blue, VertexShapeFunction -> vf2]

Out[4]= [image]
```

---

``VertexStyle`` can be combined with ``BaseStyle``:

```wl
In[1]:= MeshConnectivityGraph[Triangle[], 0, VertexStyle -> LightBlue, BaseStyle -> EdgeForm[Dotted], VertexSize -> 0.2]

Out[1]= [image]
```

``VertexStyle`` has higher priority than ``BaseStyle``:

```wl
In[2]:= MeshConnectivityGraph[Triangle[], 0, VertexStyle -> LightBlue, BaseStyle -> Gray, VertexSize -> 0.2]

Out[2]= [image]
```

---

``VertexShape`` is not affected by ``VertexStyle``:

```wl
In[1]:= MeshConnectivityGraph[Triangle[], 0, VertexSize -> 0.2, VertexShape -> [image], VertexStyle -> Blue]

Out[1]= [image]
```

#### VertexWeight (2)

Set the weight for all vertices:

```wl
In[1]:= MeshConnectivityGraph[Triangle[], 0, VertexWeight -> {2, 3, 4}]

Out[1]= [image]

In[2]:= AnnotationValue[{%, {0, 1}}, VertexWeight]

Out[2]= 2
```

---

Use any numeric expression as a weight:

```wl
In[1]:= MeshConnectivityGraph[Triangle[], 0, VertexWeight -> {a, b, c}]

Out[1]= [image]

In[2]:= AnnotationValue[{%, {0, 1}}, VertexWeight]

Out[2]= a
```

### Applications (10)

#### Basic Applications (5)

Triangle connectivity graph:

```wl
In[1]:= mesh = [image];
```

Point to point:

```wl
In[2]:= MeshConnectivityGraph[mesh, {0, 0}, #]& /@ {0, 1, 2}

Out[2]= {[image], [image], [image]}
```

Point to edge sharing the same face:

```wl
In[3]:= MeshConnectivityGraph[mesh, {0, 1}, 2, VertexLabels -> Automatic]

Out[3]= [image]
```

---

Cube connectivity graph:

```wl
In[1]:= mesh = [image];
```

Point to point:

```wl
In[2]:= MeshConnectivityGraph[mesh, {0, 0}, #]& /@ {0, 1, 2}

Out[2]= {[image], [image], [image]}
```

Point to edge sharing the same face:

```wl
In[3]:= MeshConnectivityGraph[mesh, {0, 1}, 2]

Out[3]= [image]
```

---

Menger mesh connectivity graph:

```wl
In[1]:= mesh = MengerMesh[2]

Out[1]= [image]
```

Point to point:

```wl
In[2]:= MeshConnectivityGraph[mesh, {0, 0}, #]& /@ {0, 1, 2}

Out[2]= {[image], [image], [image]}
```

Point to edge sharing the same face:

```wl
In[3]:= MeshConnectivityGraph[mesh, {0, 1}, 2]

Out[3]= [image]
```

---

3D boundary mesh connectivity graph:

```wl
In[1]:= mesh = [image];
```

Point to point:

```wl
In[2]:= MeshConnectivityGraph[mesh, {0, 0}, #]& /@ {0, 1, 2}

Out[2]= {[image], [image], [image]}
```

Point to edge sharing the same face:

```wl
In[3]:= MeshConnectivityGraph[mesh, {0, 1}, 2]

Out[3]= [image]
```

---

Get the face adjacency of a Voronoi mesh:

```wl
In[1]:= pts = RandomReal[1, {10, 2}];

In[2]:= mesh = VoronoiMesh[pts]

Out[2]= [image]

In[3]:= centroids  = RegionCentroid /@ MeshPrimitives[mesh, 2];

In[4]:= Show[{mesh, MeshConnectivityGraph[mesh, 2, VertexCoordinates -> centroids ]}]

Out[4]= [image]
```

#### Adjacency Queries (1)

Use the mesh connectivity graph to find point-point adjacency in a mesh:

```wl
In[1]:= MeshConnectivityGraph[[image], 0]

Out[1]= [image]
```

Find all the points that are connected to the point with cell index ``{0, 1}`` :

```wl
In[2]:= AdjacencyList[%, {0, 1}]

Out[2]= {{0, 2}, {0, 4}, {0, 5}}
```

#### Polyhedra Operations (1)

Use ``MeshConnectivityGraph`` to compute the ``DualPolyhedron`` of a cuboid:

```wl
In[1]:= cube = [image];
```

Compute the connectivity graph between points and faces:

```wl
In[2]:= g = MeshConnectivityGraph[cube, {0, 2}]

Out[2]= [image]
```

Get the adjacent faces for each point:

```wl
In[3]:=
mat = AdjacencyMatrix[g];
faces  = Cases[mat["AdjacencyLists"] - MeshCellCount[cube, 0], Except[{}]]

Out[3]= {{1, 2, 5}, {1, 2, 3}, {1, 3, 4}, {1, 4, 5}, {2, 5, 6}, {2, 3, 6}, {3, 4, 6}, {4, 5, 6}}
```

Compute the coordinates of the dual:

```wl
In[4]:=
pts = MeshCoordinates[cube];
fs  = And@@@ MeshCells[cube, 2];
coords = Table[Mean[pts[[i]]], {i, fs}]

Out[4]= {{0.5, 0.5, 0.}, {0.5, 0., 0.5}, {1., 0.5, 0.5}, {0.5, 1., 0.5}, {0., 0.5, 0.5}, {0.5, 0.5, 1.}}
```

Construct the dual of the cube:

```wl
In[5]:= dual = Polyhedron[coords, faces]

Out[5]=
Polyhedron[{{0.5, 0.5, 0.}, {0.5, 0., 0.5}, {1., 0.5, 0.5}, {0.5, 1., 0.5}, {0., 0.5, 0.5}, 
  {0.5, 0.5, 1.}}, {{1, 2, 5}, {1, 2, 3}, {1, 3, 4}, {1, 4, 5}, {2, 5, 6}, {2, 3, 6}, {3, 4, 6}, 
  {4, 5, 6}}]

In[6]:= Graphics3D[{Opacity[0.2], cube, dual}]

Out[6]= [image]
```

#### Topological Operations (3)

Use ``MeshConnectivityGraph`` to test whether a mesh is connected:

```wl
In[1]:= ConnectedMeshQ[mesh_] := ConnectedGraphQ[ MeshConnectivityGraph[mesh, 0, RegionDimension[mesh]]]

In[2]:= Table[ConnectedMeshQ[i], {i, {[image], [image], [image], [image]}}]

Out[2]= {False, True, True, True}
```

---

Use ``MeshConnectivityGraph`` to compute ``ConnectedMeshComponents`` :

```wl
In[1]:= mesh = [image];
```

Connected components of a mesh connectivity graph:

```wl
In[2]:= com = ConnectedComponents[MeshConnectivityGraph[mesh, 0, 2, AnnotationRules -> None]]

Out[2]= {{1, 2, 3, 4, 5}, {6, 7, 8}}
```

Group the mesh cells to different mesh connected components:

```wl
In[3]:= belong[a_, b_] := Length[Intersection[a, b]] == Length[a]

In[4]:=
cells  = MeshCells[mesh, 2];
res  = Flatten@Table[Position[belong[i, #]& /@ com, True], {i, cells[[All, 1]]}];

In[5]:= groups  = Gather[Thread[List[cells, res]], Last[#1] == Last[#2]&]

Out[5]= {{{Polygon[{1, 3, 2}], 1}, {Polygon[{3, 4, 5}], 1}}, {{Polygon[{8, 7, 6}], 2}}}
```

Get mesh connected components:

```wl
In[6]:= Table[MeshRegion[MeshCoordinates[mesh], groups[[i]][[All, 1]]], {i, Length[com]}]

Out[6]= {[image], [image]}
```

---

$k$-skeleton graph of Platonic solids:

```wl
In[1]:= Table[MeshConnectivityGraph[reg, 0], {reg, {[image], [image], [image], [image], [image]}}]

Out[1]= {[image], [image], [image], [image], [image]}
```

### Properties & Relations (3)

The cell of index ``{d, k}`` corresponds to the vertex $k$ :

```wl
In[1]:= mesh = MeshRegion[{{0, 0}, {1, 0}, {2, 1 / 2}, {2, -1 / 2}}, {Line[{1, 2}], Line[{2, 3}], Line[{3, 4}], Line[{4, 2}]}]

Out[1]= [image]

In[2]:= MeshConnectivityGraph[mesh, 1, VertexLabels -> "Name"]

Out[2]= [image]
```

---

``MeshConnectivityGraph`` between cells of different dimensions is a directed bipartite graph:

```wl
In[1]:= mesh = MeshRegion[{{0, 0, 0}, {2, 0, 0}, {2, 2, 0}, {0, 2, 0}, {1, 1, 2}}, {Tetrahedron[{1, 2, 3, 5}], Tetrahedron[{1, 3, 4, 5}]}]

Out[1]= [image]

In[2]:= MeshConnectivityGraph[mesh, {1, 2}]

Out[2]= [image]

In[3]:= BipartiteGraphQ[%]

Out[3]= True
```

---

The ``AdjacencyMatrix`` of a mesh connectivity graph between cells of the same dimension is symmetric:

```wl
In[1]:= mesh = MeshRegion[{{0, 0, 0}, {2, 0, 0}, {2, 2, 0}, {0, 2, 0}, {1, 1, 2}}, {Tetrahedron[{1, 2, 3, 5}], Tetrahedron[{1, 3, 4, 5}]}]

Out[1]= [image]

In[2]:= AdjacencyMatrix[MeshConnectivityGraph[mesh, {1, 1}]]

Out[2]=
SparseArray[Automatic, {9, 9}, 0, {1, {{0, 5, 10, 16, 22, 27, 33, 38, 43, 48}, 
   {{2}, {3}, {4}, {5}, {7}, {1}, {3}, {5}, {6}, {8}, {1}, {2}, {4}, {6}, {7}, {8}, {1}, {3}, {5}, 
    {6}, {7}, {9}, {1}, {2}, {4}, {6}, {9}, {2}, {3}, {4}, {5}, {8}, {9}, {1}, {3}, {4}, {8}, {9}, 
    {2}, {3}, {6}, {7}, {9}, {4}, {5}, {6}, {7}, {8}}}, {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 
   1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 
   1, 1}}]

In[3]:= SymmetricMatrixQ[%]

Out[3]= True
```

### Neat Examples (1)

Different dimensional connectivity graphs of a Menger mesh:

```wl
In[1]:= Table[MeshConnectivityGraph[MengerMesh[3], i], {i, 0, 2}]

Out[1]= {[image], [image], [image]}
```

## See Also

* [`MeshRegion`](https://reference.wolfram.com/language/ref/MeshRegion.en.md)
* [`BoundaryMeshRegion`](https://reference.wolfram.com/language/ref/BoundaryMeshRegion.en.md)
* [`Graph`](https://reference.wolfram.com/language/ref/Graph.en.md)
* [`AdjacencyMatrix`](https://reference.wolfram.com/language/ref/AdjacencyMatrix.en.md)

## Related Guides

* [Mesh-Based Geometric Regions](https://reference.wolfram.com/language/guide/MeshRegions.en.md)
* [Graph Construction & Representation](https://reference.wolfram.com/language/guide/GraphConstructionAndRepresentation.en.md)

## History

* [Introduced in 2020 (12.1)](https://reference.wolfram.com/language/guide/SummaryOfNewFeaturesIn121.en.md)