---
title: "MeshRegion"
language: "en"
type: "Symbol"
summary: "MeshRegion[{p1, p2, ...}, {mcell1[{i1, ...}], mcell2[{j1, ...}], ...}] yields a mesh with cells mcellj, where coordinates given as integer i are taken to be pi. MeshRegion[..., {..., wi[mcelli[...]], ...}] yields a mesh with cell properties defined by the symbolic wrapper wi. MeshRegion[mreg, opts] yields a mesh from a mesh region mreg with options opts."
keywords: 
- unstructured mesh
- irregular mesh
- unstructured grid
- irregular grid
- mesh
- grid
- complex
- geometric grid
- geometric mesh
- geometric complex
- simplicial complex
- computational mesh
- topological mesh
- element mesh
- element grid
canonical_url: "https://reference.wolfram.com/language/ref/MeshRegion.html"
source: "Wolfram Language Documentation"
related_guides: 
  - 
    title: "Mesh-Based Geometric Regions"
    link: "https://reference.wolfram.com/language/guide/MeshRegions.en.md"
  - 
    title: "Geometric Computation"
    link: "https://reference.wolfram.com/language/guide/GeometricComputation.en.md"
  - 
    title: "Plane Geometry"
    link: "https://reference.wolfram.com/language/guide/PlaneGeometry.en.md"
  - 
    title: "Solid Geometry"
    link: "https://reference.wolfram.com/language/guide/SolidGeometry.en.md"
  - 
    title: "WDF (Wolfram Data Framework)"
    link: "https://reference.wolfram.com/language/guide/WDFWolframDataFramework.en.md"
  - 
    title: "Partial Differential Equations"
    link: "https://reference.wolfram.com/language/guide/PDEModelingAndAnalysis.en.md"
  - 
    title: "Systems Modeling"
    link: "https://reference.wolfram.com/language/guide/SystemsModeling.en.md"
---
# MeshRegion

MeshRegion[{p1, p2, …}, {mcell1[{i1, …}], mcell2[{j1, …}], …}] yields a mesh with cells mcellj, where coordinates given as integer i are taken to be pi.

MeshRegion[…, {…, wi[mcelli[…]], …}] yields a mesh with cell properties defined by the symbolic wrapper wi. 

MeshRegion[mreg, opts] yields a mesh from a mesh region mreg with options opts.

## Details and Options

* ``MeshRegion`` is also known as a simplicial complex or cell complex.

* ``MeshRegion`` can represent a piecewise linear region of any geometric dimension embedded in dimension 1, 2, or 3.

[image]

* ``MeshRegion[…]`` displays in a notebook as a plot of a mesh region.

* ``MeshRegion`` is typically created using functions such as ``DelaunayMesh``, ``DiscretizeGraphics``, and ``DiscretizeRegion``.

* The region represented by ``MeshRegion`` consists of the disjoint union of mesh cells.

* ``MeshRegion`` has an embedding dimension that is equal to the length of each point ``pi`` and can be found using ``RegionEmbeddingDimension``.

* Each cell has a geometric dimension and can be found using ``RegionDimension``.

* Possible mesh cells ``mcelli`` and their geometric dimensions:

|                              |            |                                     |
| ---------------------------- | ---------- | ----------------------------------- |
| Point[i]                     | 0          | point                               |
| Line[{i1, i2, …}]            | 1          | line segments {i1, i2}, {i2, i3}, … |
| Triangle[{i1, i2, i3}]       | 2          | filled triangle                     |
| Polygon[{i1, i2, …}]         | 2          | filled polygon                      |
| Polyhedron[{{ii, i2, …}, …}] | 3          | filled polyhedron                   |
| Tetrahedron[{i1, …, i4}]     | 3          | filled tetrahedron                  |
| Hexahedron[{i1, …, i8}]      | 3          | filled hexahedron                   |
| Pyramid[{i1, …, i5}]         | 3          | filled pyramid                      |
| Prism[{i1, …, i6}]           | 3          | filled prism                        |
| Simplex[{i1, …, ik}]         | 0, 1, 2, 3 | filled simplex                      |

* ``Tetrahedron``, ``Hexahedron``, ``Pyramid``, and ``Prism`` can only be used with 3D coordinates.

* ``Point``, ``Line``, ``Triangle``, ``Polygon``, ``Polyhedron``, ``Tetrahedron``, ``Hexahedron``, ``Pyramid``, ``Prism``, and ``Simplex`` all have multi-cell specifications as well.

* The following special wrappers ``wi`` can be used for cells:

|                                |                                                  |
| ------------------------------ | ------------------------------------------------ |
| Labeled[cell, …]               | display the cell with labeling                   |
| Style[cell, …]                 | show the cell with the specified style           |
| Annotation[cell, name -> value] | associate the annotation name -> value with cell |

* Each cell in a ``MeshRegion`` is given a unique ``MeshCellIndex`` of the form ``{d, i}``, where ``d`` is the geometric dimension and ``i`` is the index.

* For purposes of selecting cells of a ``MeshRegion``, the following cell specifications may be used:

|             |                                                     |
| ----------- | --------------------------------------------------- |
| {d, i}      | cell with index i of dimension d                    |
| {d, ispec}  | cells with index specification ispec of dimension d |
| {dspec, …}  | cells of dimensions given by dspec                  |
| h[{i1, …}]  | explicit cell with head h and vertex indices i1, …  |
| {c1, c2, …} | list of explicit cells ci                           |

* The index specification ``ispec`` can have the following form:

|             |                                              |
| ----------- | -------------------------------------------- |
| i           | cell index i                                 |
| {i1, i2, …} | cells with indices ik                        |
| All         | all cells                                    |
| patt        | cells with indices matching the pattern patt |

* The dimension specification ``dspec`` can have the following form:

|      |                                                        |
| ---- | ------------------------------------------------------ |
| d    | explicit dimension d                                   |
| All  | all dimensions from 0 to geometric dimension of region |
| patt | dimensions matching the pattern patt                   |

* ``MeshRegion`` is always converted to an optimized representation and treated as raw by functions like ``AtomQ`` and for purposes of pattern matching.

* ``MeshRegion`` has the same options as ``Graphics`` for embedding dimension 2 and the same options as ``Graphics3D`` for embedding dimension 3 with the following additions and changes:

|                        |             |                                |
| ---------------------- | ----------- | ------------------------------ |
| MeshCellLabel          | Automatic   | labels and placement for cells |
| MeshCellShapeFunction  | Automatic   | shape functions for cells      |
| MeshCellStyle          | Automatic   | styles for cells               |
| MeshCellHighlight      | {}          | list of highlighted cells      |
| MeshCellMarker         | 0           | integer markers for cells      |
| PlotTheme              | \$PlotTheme | overall theme for the mesh     |

* Possible settings for ``PlotTheme`` include common base themes, font features themes, and size features themes.

* Mesh feature themes affect the plots of mesh cells. Themes include:

|         |            |                     |
| ------- | ---------- | ------------------- |
| [image] | "Points"   | 0D cells            |
| [image] | "Lines"    | 1D cells, wireframe |
| [image] | "Polygons" | 2D cells            |

* Rendering feature themes affect the rendering of meshes. Themes include:

|         |                 |                                      |
| ------- | --------------- | ------------------------------------ |
| [image] | "SampledPoints" | sampled points from mesh cells       |
| [image] | "SphereAndTube" | points as spheres and lines as tubes |
| [image] | "SmoothShading" | smooth shading                       |
| [image] | "FaceNormals"   | normal for each 2D cell              |
| [image] | "LargeMesh"     | optimized for large number of cells  |

* Style and other specifications for cells are effectively applied in the order ``MeshCellStyle``, ``Style``, and other wrappers, with later specifications overriding earlier ones.

* Label style and other specifications for cell labels are effectively applied in the order ``MeshCellLabel`` and ``Labeled``, with later specifications overriding earlier ones.

* ``MeshRegion`` can be used with functions such as ``RegionMember``, ``RegionDistance``, ``RegionMeasure``, and ``NIntegrate``.

## Examples (179)

### Basic Examples (6)

A 1D (curve) mesh region in 1D:

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

Out[1]= [image]
```

Label each point with its index:

```wl
In[2]:= HighlightMesh[%, Labeled[0, "Index"]]

Out[2]= [image]
```

---

A 1D (curve) mesh region in 2D:

```wl
In[1]:= 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]
```

Label each point with its index:

```wl
In[2]:= HighlightMesh[%, Labeled[0, "Index"]]

Out[2]= [image]
```

---

A 2D (surface) mesh region in 3D with each point labeled by its index:

```wl
In[1]:= ℛ = MeshRegion[{{0, 0, 0}, {0, 0, 1}, {0, -1, 0}, {1, 0, 0}, {0, 1, 0}}, {Triangle[{1, 2, 3}], Triangle[{1, 2, 4}], Triangle[{1, 2, 5}]}];

In[2]:= HighlightMesh[ℛ, Labeled[0, "Index"]]

Out[2]= [image]
```

---

A 3D (volume) mesh region in 3D with points labeled by its index:

```wl
In[1]:= ℛ = 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}]}];

In[2]:= HighlightMesh[ℛ, Labeled[0, "Index"]]

Out[2]= [image]
```

---

A mesh region containing cells of mixed dimensions:

```wl
In[1]:= ℛ = MeshRegion[{{0, 0, 0}, {1, 0, 0}, {2, 0, 0}, {3, 0, -1 / 2}, {3, 0, 1 / 2}, {4, -1 / 2, 0}, {4, 1 / 2, 0}}, {Point[1], Line[{2, 3}], Triangle[{3, 4, 5}], Tetrahedron[{4, 6, 5, 7}]}];

In[2]:= HighlightMesh[ℛ, Labeled[0, "Index"]]

Out[2]= [image]
```

---

A volume mesh region in 3D from ``DelaunayMesh``:

```wl
In[1]:= DelaunayMesh[RandomReal[1, {50, 3}]]

Out[1]= [image]
```

Find its volume:

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

Out[2]= 0.618628
```

### Scope (41)

#### Regions in 1D (3)

A strictly 0D ``MeshRegion`` is a point set:

```wl
In[1]:= MeshRegion[{{0}, {1}, {2}}, Point[{{1}, {2}, {3}}]]

Out[1]= [image]
```

Label the points with ``HighlightMesh`` :

```wl
In[2]:= HighlightMesh[%, Labeled[0, "Index"]]

Out[2]= [image]
```

---

A strictly 1D ``MeshRegion`` is a collection of line segments:

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

Out[1]= [image]
```

Label the segments with ``HighlightMesh`` :

```wl
In[2]:= HighlightMesh[%, Labeled[1, "Index"]]

Out[2]= [image]
```

---

A ``MeshRegion`` can combine elements of different dimensions:

```wl
In[1]:= MeshRegion[{{0}, {1}, {2}}, {Point[{1}], Line[{2, 3}]}]

Out[1]= [image]
```

Separate them with ``DimensionalMeshComponents`` :

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

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

#### Regions in 2D (4)

A strictly 0D ``MeshRegion`` is a point set:

```wl
In[1]:= MeshRegion[Tuples[{0, 1, 2}, 2], Point[{List /@ Range[9]}]]

Out[1]= [image]
```

Label the points with ``HighlightMesh`` :

```wl
In[2]:= HighlightMesh[%, Labeled[0, "Index"]]

Out[2]= [image]
```

---

A strictly 1D ``MeshRegion`` is a collection of line segments:

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

Out[1]= [image]
```

Label the segments with ``HighlightMesh`` :

```wl
In[2]:= HighlightMesh[%, Labeled[1, "Index"]]

Out[2]= [image]
```

---

A strictly 2D ``MeshRegion`` is a collection of polygonal faces:

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

Out[1]= [image]
```

Label the faces with ``HighlightMesh`` :

```wl
In[2]:= HighlightMesh[%, Labeled[2, "Index"]]

Out[2]= [image]
```

---

A ``MeshRegion`` can combine elements of different dimensions:

```wl
In[1]:= ℛ = MeshRegion[{{0, 0}, {1, 0}, {2, 0}, {3, -1 / 2}, {3, 1 / 2}}, {Point[{1}], Line[{2, 3}], Triangle[{3, 4, 5}]}]

Out[1]= [image]
```

Separate them with ``DimensionalMeshComponents`` :

```wl
In[2]:= DimensionalMeshComponents[ℛ]

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

#### Regions in 3D (5)

A strictly 0D ``MeshRegion`` is a point set:

```wl
In[1]:= MeshRegion[Tuples[{0, 1}, 3], Point[{List /@ Range[8]}]]

Out[1]= [image]
```

Label the points with ``HighlightMesh`` :

```wl
In[2]:= HighlightMesh[%, Labeled[0, "Index"]]

Out[2]= [image]
```

---

A strictly 1D ``MeshRegion`` is a collection of line segments:

```wl
In[1]:= MeshRegion[{{0, 0, 0}, {1, 0, 0}, {0, 1, 0}, {0, 0, 1}}, Line[Union[Sort /@ Permutations[Range[4], {2}]]]]

Out[1]= [image]
```

Label the segments with ``HighlightMesh`` :

```wl
In[2]:= HighlightMesh[%, Labeled[1, "Index"]]

Out[2]= [image]
```

---

A strictly 2D ``MeshRegion`` is a collection of polygonal faces:

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

Out[1]= [image]
```

Label the faces with ``HighlightMesh`` :

```wl
In[2]:= HighlightMesh[%, Labeled[2, "Index"]]

Out[2]= [image]
```

---

A strictly 3D ``MeshRegion`` is a collection of polyhedral volumes:

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

Out[1]= [image]
```

Polyhedral volume cells include ``Tetrahedron``, ``Prism``, ``Pyramid``, and ``Hexahedron`` :

```wl
In[2]:= pts = {{0, 0, 0}, {1, 0, 0}, {1, 1, 0}, {0, 1, 0}, {0, 0, 1}, {1, 0, 1}, {1, 1, 1}, {0, 1, 1}, {0.5, 0.5, 1.5}, {1.5, 0, 0}, {1.5, 1, 0}, {1, -0.5, 0}};

In[3]:= MeshRegion[pts, {Hexahedron[{1, 2, 3, 4, 5, 6, 7, 8}], Pyramid[{5, 6, 7, 8, 9}], Prism[{2, 10, 6, 3, 11, 7}], Tetrahedron[{2, 10, 6, 12}]}]

Out[3]= [image]
```

---

A ``MeshRegion`` can combine elements of different dimensions:

```wl
In[1]:= MeshRegion[{{0, 0, 0}, {1, 0, 0}, {2, 0, 0}, {3, 0, 1 / 2}, {3, 0, -1 / 2}, {4, 1 / 2, 0}, {4, -1 / 2, 0}}, {Simplex[{1}], Simplex[{2, 3}], Simplex[{3, 4, 5}], Simplex[{4, 5, 6, 7}]}]

Out[1]= [image]
```

#### Presentation (11)

``MeshCellLabel`` can be used to label the parts of a ``MeshRegion`` :

```wl
In[1]:= MeshRegion[{{0, 0}, {1, 0}, {0, 1}}, Triangle[{1, 2, 3}], MeshCellLabel -> {0 -> "Index"}]

Out[1]= [image]
```

The labels do not have to be strings:

```wl
In[2]:= MeshRegion[{{0, 0}, {1, 0}, {0, 1}}, Triangle[{1, 2, 3}], MeshCellLabel -> {{1, 1} -> Red, {1, 2} -> Green, {1, 3} -> Blue}]

Out[2]= [image]
```

---

``Labeled`` can be used as a wrapper to label cells when constructing a ``MeshRegion`` :

```wl
In[1]:= MeshRegion[{{0, 0}, {1, 0}, {1, 1}, {0, 1}}, {Labeled[Triangle[{1, 2, 3}], "a"], Labeled[Triangle[{3, 4, 1}], "b"]}]

Out[1]= [image]
```

The labels do not need to be strings:

```wl
In[2]:= MeshRegion[{{0, 0}, {1, 0}, {1, 1}, {0, 1}}, {Labeled[Triangle[{1, 2, 3}], Sqrt[x ^ 2 + y ^ 2]], Labeled[Triangle[{3, 4, 1}], Red]}]

Out[2]= [image]
```

---

``MeshCellMarker`` can be used to mark parts of a ``MeshRegion`` :

```wl
In[1]:= MeshRegion[{{0, 0}, {1, 0}, {0, 1}}, Triangle[{1, 2, 3}], MeshCellMarker -> {{0, 1} -> 1, {0, 2} -> 2, {0, 3} -> 3}, MeshCellLabel -> {0 -> "Marker"}]

Out[1]= [image]
```

---

``MeshCellStyle`` can be used to set the ``Style`` of components of a ``MeshRegion`` :

```wl
In[1]:= MeshRegion[{{0, 0}, {1, 0}, {0, 1}}, Triangle[{1, 2, 3}], MeshCellStyle -> {{1, 1} -> {Thick, Black}, {1, 2} -> {Thick, Dashed, Green}, {1, 3} -> {Thickness[0.02], DotDashed, Blue}, {2, 1} -> LightRed}]

Out[1]= [image]
```

---

``Style`` can be used as a wrapper to style cells when constructing a ``MeshRegion`` :

```wl
In[1]:= MeshRegion[{{0, 0}, {1, 0}, {1, 1}, {0, 1}}, {Style[Polygon[{1, 2, 3}], Red], Style[Polygon[{3, 4, 1}], {Green, EdgeForm[Directive[Thick, Black]]}]}]

Out[1]= [image]
```

---

Use a theme to draw 0D cells:

```wl
In[1]:= MeshRegion[[image], PlotTheme -> "Points"]

Out[1]= [image]
```

---

Use a theme to draw 1D cells or a wireframe:

```wl
In[1]:= MeshRegion[[image], PlotTheme -> "Lines"]

Out[1]= [image]
```

---

Use a theme to draw 2D cells:

```wl
In[1]:= MeshRegion[[image], PlotTheme -> "Polygons"]

Out[1]= [image]
```

---

Use a theme to draw sampled points from mesh cells:

```wl
In[1]:= MeshRegion[[image], PlotTheme -> "SampledPoints"]

Out[1]= [image]
```

---

Use a theme to smooth shading:

```wl
In[1]:= MeshRegion[[image], PlotTheme -> "SmoothShading"]

Out[1]= [image]
```

---

Use a theme to draw normals for each 2D cell:

```wl
In[1]:= MeshRegion[[image], PlotTheme -> "FaceNormals"]

Out[1]= [image]
```

#### Region Properties (8)

Embedding dimension:

```wl
In[1]:= mr = DelaunayMesh[RandomReal[1, {20, 2}]];

In[2]:= RegionEmbeddingDimension[mr]

Out[2]= 2
```

Geometric dimension:

```wl
In[3]:= RegionDimension[mr]

Out[3]= 2
```

---

Point membership test:

```wl
In[1]:= mr = DiscretizeRegion[Disk[]];

In[2]:= {RegionMember[mr, {0, 0}], RegionMember[mr, {1, 1}]}

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

Visualize it:

```wl
In[3]:=
mf = RegionMember[mr];
pts = RandomReal[{-1, 1}, {500, 2}];
Show[mr, Graphics[{Red, Point[Select[pts, mf]], Black, Point[Select[pts, !mf[#]&]]}]]

Out[3]= [image]
```

---

Measure is ``ArcLength`` for a 1D mesh, ``Area`` for a 2D mesh, and ``Volume`` for a 3D mesh:

```wl
In[1]:= {mr1, mr2, mr3} = DelaunayMesh[RandomReal[1, {20, #}]]& /@ Range[3]

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

In[2]:= RegionDimension /@ {mr1, mr2, mr3}

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

In[3]:= RegionMeasure /@ {mr1, mr2, mr3}

Out[3]= {0.945592, 0.573698, 0.347091}
```

Compute and visualize the centroids of each:

```wl
In[4]:= {c1, c2, c3} = RegionCentroid /@ {mr1, mr2, mr3}

Out[4]= {{0.490255}, {0.482777, 0.514552}, {0.465341, 0.515973, 0.492784}}

In[5]:= {Show[mr1, Graphics[{Red, Point[Join[c1, {0}]]}]], Show[mr2, Graphics[{Red, Point[c2]}]], Show[HighlightMesh[mr3, Style[{2, All}, Opacity[0.2]]], Graphics3D[{Red, PointSize[Large], Point[c3]}]]}

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

---

Distance from a point:

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

In[2]:= {RegionDistance[mr, {0.5, 0.5}], RegionDistance[mr, {2, 2}]}

Out[2]= {0., 1.63181}
```

Visualize it:

```wl
In[3]:=
df = RegionDistance[mr];
{Plot3D[df[{x, y}], {x, -0.5, 1.5}, {y, -0.5, 1.5}, MeshFunctions -> {#3&}, Mesh -> 5], ContourPlot[df[{x, y}], {x, -1.5, 2.5}, {y, -1.5, 2.5}, Contours -> {{0.5, Red}, {1, Green}, {1.5, Blue}}]}

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

---

Signed distance from a point:

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

In[2]:= {SignedRegionDistance[mr, {0.5, 0.5}], SignedRegionDistance[mr, {2, 2}]}

Out[2]= {-0.304861, 1.7497}
```

Visualize it:

```wl
In[3]:=
sdf = SignedRegionDistance[mr];
Plot3D[sdf[{x, y}], {x, -0.5, 1.5}, {y, -0.5, 1.5}, MeshFunctions -> {#3&}, Mesh -> {{0}}, MeshShading -> {Red, Green}]

Out[3]= [image]
```

---

Nearest point in the region:

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

In[2]:= {RegionNearest[mr, {0.5, 0.5}], RegionNearest[mr, {2, 2}]}

Out[2]= {{0.5, 0.5}, {0.852959, 0.819235}}
```

Visualize it:

```wl
In[3]:=
pts = Table[{0.5, 0.5} + {Cos[k 2π / 16], Sin[k 2π / 16]}, {k, 0., 15}];
nst = RegionNearest[mr][pts];

In[4]:= Legended[Show[mr, Graphics[{{Thin, Gray, Line[Transpose[{pts, nst}]]}, {Red, Point[pts]}, {Blue, Point[nst]}}]], PointLegend[{Red, Blue}, {"start", "nearest"}]]

Out[4]= [image]
```

---

A ``MeshRegion`` is always bounded:

```wl
In[1]:= mr = DelaunayMesh[RandomReal[1, {20, 2}]];

In[2]:= BoundedRegionQ[mr]

Out[2]= True
```

Get its bounds:

```wl
In[3]:= rb = RegionBounds[mr]

Out[3]= {{0.0982832, 0.943947}, {0.0123276, 0.991361}}
```

Visualize the bounding box:

```wl
In[4]:= Show[Graphics[{EdgeForm[{Dashed, Red}], Opacity[0.1, Yellow], Cuboid@@Transpose[rb]}], mr]

Out[4]= [image]
```

---

``Integrate`` over a ``MeshRegion`` :

```wl
In[1]:= mr = MeshRegion[{{0, 0}, {1, 0}, {1, 1}, {0, 1}}, Polygon[{1, 2, 3, 4}]];

In[2]:= Integrate[x y, {x, y}∈mr]

Out[2]= 0.25
```

#### Mesh Properties (10)

``MeshCellCount`` returns the number of cells matching a given dimension or cell specification:

```wl
In[1]:= mr = DelaunayMesh[RandomReal[1, {20, 2}]]

Out[1]= [image]
```

Get the number of 1D cells:

```wl
In[2]:= MeshCellCount[mr, 1]

Out[2]= 50
```

When no cell specification is given, the value for each dimension is returned:

```wl
In[3]:= MeshCellCount[mr]

Out[3]= {20, 50, 31}
```

---

``MeshCells`` returns the cells in the mesh matching a given dimension or cell specification:

```wl
In[1]:= mr = DelaunayMesh[RandomReal[1, {8, 2}]]

Out[1]= [image]
```

Get the 1D cells:

```wl
In[2]:= MeshCells[mr, 1]

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

Individual cell indices or sets of cell indices can be used:

```wl
In[3]:= MeshCells[mr, {{1, 1}, {2, 1}}]

Out[3]= {Line[{6, 5}], Polygon[{6, 5, 1}]}
```

---

``MeshCellIndex`` gets the index of a cell or set of cells in a mesh:

```wl
In[1]:= mr = MeshRegion[{{0, 0}, {1, 0}, {0, 1}}, Polygon[{1, 2, 3}]]

Out[1]= [image]

In[2]:= MeshCellIndex[mr, {Polygon[{1, 2, 3}], Line[{2, 3}], Point[{3}]}]

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

---

``MeshCoordinates`` gets the coordinates of the mesh:

```wl
In[1]:= mr = DelaunayMesh[RandomReal[1, {8, 2}]]

Out[1]= [image]

In[2]:= MeshCoordinates[mr]

Out[2]= {{0.689017, 0.429454}, {0.933864, 0.634249}, {0.525205, 0.793568}, {0.800622, 0.132353}, {0.662234, 0.578814}, {0.987641, 0.0447295}, {0.74015, 0.808557}, {0.937802, 0.064082}}
```

This list of coordinates is what the ``MeshCells`` refer to:

```wl
In[3]:= MeshCells[mr, {2, 1}]

Out[3]= Polygon[{7, 5, 2}]
```

---

``MeshPrimitives`` returns the primitives that make up the mesh:

```wl
In[1]:= mr = DelaunayMesh[RandomReal[1, {8, 2}]]

Out[1]= [image]

In[2]:= MeshPrimitives[mr, 0]

Out[2]= {Point[{0.419071, 0.397984}], Point[{0.0387931, 0.972248}], Point[{0.279353, 0.144925}], Point[{0.952792, 0.0928779}], Point[{0.82125, 0.410204}], Point[{0.0857024, 0.403129}], Point[{0.577279, 0.984792}], Point[{0.155503, 0.566742}]}
```

Individual cell indices or sets of cell indices can be used:

```wl
In[3]:= MeshPrimitives[mr, {2, {1, 2, 3}}]

Out[3]= {Polygon[{{0.155503, 0.566742}, {0.0857024, 0.403129}, {0.419071, 0.397984}}], Polygon[{{0.577279, 0.984792}, {0.0387931, 0.972248}, {0.155503, 0.566742}}], Polygon[{{0.155503, 0.566742}, {0.0387931, 0.972248}, {0.0857024, 0.403129}}]}
```

---

``DimensionalMeshComponents`` separates out components of a mesh with different dimensions:

```wl
In[1]:= mr = MeshRegion[{{0, 0}, {1, 0}, {2, 0}, {3, -1 / 2}, {3, 1 / 2}}, {Point[{1}], Line[{2, 3}], Polygon[{3, 4, 5}]}]

Out[1]= [image]

In[2]:= DimensionalMeshComponents[mr]

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

---

``ConnectedMeshComponents`` separates out components of a mesh based on connectivity:

```wl
In[1]:= mr = DiscretizeRegion[RegionUnion[Disk[{0, 0}, 1], Disk[{3, 0}, 1]]]

Out[1]= [image]

In[2]:= ConnectedMeshComponents[mr]

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

---

``MeshCellMeasure`` can be used to get the measures of a set of cells in a mesh:

```wl
In[1]:= mr = DelaunayMesh[RandomReal[1, {20, 2}]]

Out[1]= [image]

In[2]:= AnnotationValue[{mr, {2, {1, 2, 3, 4, 5}}}, MeshCellMeasure]

Out[2]= {0.00535042, 0.0119022, 0.00671342, 0.0138227, 0.0959579}
```

The appropriate measure is used for each dimension:

```wl
In[3]:= AnnotationValue[{mr, {1, {8, 9, 10}}}, MeshCellMeasure]

Out[3]= {0.233776, 0.19071, 0.479291}
```

---

``MeshCellCentroid`` can be used to get the centroids of a set of cells in a mesh:

```wl
In[1]:= mr = DelaunayMesh[RandomReal[1, {20, 2}]]

Out[1]= [image]

In[2]:= c = AnnotationValue[{mr, {2, {1, 2, 3, 4, 5}}}, MeshCellCentroid]

Out[2]= {{0.270336, 0.402061}, {0.22749, 0.348216}, {0.529307, 0.342072}, {0.426674, 0.259251}, {0.253479, 0.560957}}
```

Visualize it:

```wl
In[3]:= Show[mr, Graphics[{Red, Point[c]}]]

Out[3]= [image]
```

---

``MeshCellQuality`` can be used to get the quality of a set of cells in a mesh:

```wl
In[1]:= mr = DelaunayMesh[RandomReal[1, {20, 2}]]

Out[1]= [image]

In[2]:= AnnotationValue[{mr, 2}, MeshCellQuality]

Out[2]= {0.728619, 0.887322, 0.145116, 0.873346, 0.949812, 0.477824, 0.209653, 0.732141, 0.0422191, 0.276794, 0.0596452, 0.258253, 0.853405, 0.921474, 0.765836, 0.860033, 0.69789, 0.55993, 0.844003, 0.640043, 0.880496, 0.578439, 0.628234, 0.0158909, 0.795322, 0.437773, 0.987626}
```

### Options (114)

#### AlignmentPoint (1)

Specify the position to be aligned in 3D ``Inset``, using $0,1$ coordinates:

```wl
In[1]:= Table[Graphics[{Inset[MeshRegion[{{0, 0}, {2, -1}, {2, 1}}, {Triangle[{1, 2, 3}]}, ImageSize -> 50, AlignmentPoint -> {a, 0}], {0, 0}]}, ImageSize -> 100, Axes -> True, Ticks -> None], {a, {0, 1 / 2, 1}}]

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

In[2]:= Table[Graphics[{Inset[MeshRegion[{{0, 0}, {2, -1}, {2, 1}}, {Triangle[{1, 2, 3}]}, ImageSize -> 50, AlignmentPoint -> {1 / 2, a}], {0, 0}]}, ImageSize -> 100, Axes -> True, Ticks -> None], {a, {0, 1 / 2, 1}}]

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

#### AspectRatio (1)

Use numerical values for ``AspectRatio`` :

```wl
In[1]:= Table[MeshRegion[{{0, 0}, {2, -1}, {2, 1}}, {Triangle[{1, 2, 3}]}, AspectRatio -> 1 / k], {k, 1, 3}]

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

#### Axes (2)

Draw all the axes:

```wl
In[1]:= MeshRegion[{{0, 0}, {2, -1}, {2, 1}}, {Triangle[{1, 2, 3}]}, Axes -> True]

Out[1]= [image]
```

---

Draw the $y$ axis but not the $x$ axis:

```wl
In[1]:= MeshRegion[{{0, 0}, {2, -1}, {2, 1}}, {Triangle[{1, 2, 3}]}, Axes -> {False, True}]

Out[1]= [image]
```

#### AxesEdge (2)

Choose the bounding box edges automatically to draw the axes:

```wl
In[1]:= MeshRegion[{{0, 0, 0}, {2, 0, 0}, {2, 2, 0}, {0, 2, 0}, {1, 1, 2}}, Pyramid[{1, 2, 3, 4, 5}], Boxed -> True, Axes -> True, AxesEdge -> Automatic]

Out[1]= [image]
```

---

Choose the bounding box edges automatically to draw the axes:

```wl
In[1]:= MeshRegion[{{0, 0, 0}, {2, 0, 0}, {2, 2, 0}, {0, 2, 0}, {1, 1, 2}}, Pyramid[{1, 2, 3, 4, 5}], Boxed -> True, Axes -> True, AxesEdge -> {{1, 1}, None, None}]

Out[1]= [image]
```

#### AxesLabel (2)

Place a label for the $y$ axis:

```wl
In[1]:= MeshRegion[{{0, 0}, {2, -1}, {2, 1}}, Triangle[{1, 2, 3}], Axes -> True, AxesLabel -> y]

Out[1]= [image]
```

---

Specify a label for each axis:

```wl
In[1]:= MeshRegion[{{0, 0}, {2, -1}, {2, 1}}, Triangle[{1, 2, 3}], Axes -> True, AxesLabel -> {x, y}]

Out[1]= [image]
```

#### AxesOrigin (2)

Determine where the axes cross automatically :

```wl
In[1]:= MeshRegion[{{0, 0}, {2, -1}, {2, 1}}, Triangle[{1, 2, 3}], Axes -> True, AxesOrigin -> Automatic]

Out[1]= [image]
```

---

Specify the axes' origin explicitly:

```wl
In[1]:= MeshRegion[{{0, 0}, {2, -1}, {2, 1}}, Triangle[{1, 2, 3}], Axes -> True, AxesOrigin -> {0, -1}]

Out[1]= [image]
```

#### AxesStyle (2)

Specify the overall axes style, including the ticks and the tick labels:

```wl
In[1]:= MeshRegion[{{0, 1}, {2, 0}, {2, 2}}, Triangle[{1, 2, 3}], Axes -> True, AxesStyle -> Directive[Orange, 12]]

Out[1]= [image]
```

---

Specify the style of each axis:

```wl
In[1]:= MeshRegion[{{0, 1}, {2, 0}, {2, 2}}, Triangle[{1, 2, 3}], Axes -> True, AxesStyle -> {Directive[Dashed, Red], Blue}]

Out[1]= [image]
```

#### Background (1)

Specify a background color:

```wl
In[1]:= MeshRegion[{{0, 1}, {2, 0}, {2, 2}}, Triangle[{1, 2, 3}], Background -> LightBlue]

Out[1]= [image]
```

#### BaselinePosition (3)

Align the center of a graphic with the baseline of the text:

```wl
In[1]:= {x, MeshRegion[{{0, 1}, {2, 0}, {2, 2}}, Triangle[{1, 2, 3}], ImageSize -> 50, BaselinePosition -> Center], y}

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

---

Specify the baseline of a graphic as a fraction of the height by using ``Scaled`` :

```wl
In[1]:= Table[{x, MeshRegion[{{0, 1}, {2, 0}, {2, 2}}, Triangle[{1, 2, 3}], ImageSize -> 50, BaselinePosition -> Scaled[b]]}, {b, {0, 0.5, 1}}]

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

---

Use the axis of a graphic as the baseline:

```wl
In[1]:= {x, MeshRegion[{{0, 1}, {2, 0}, {2, 2}}, Triangle[{1, 2, 3}], ImageSize -> 50, BaselinePosition -> Axis], y}

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

#### BaseStyle (2)

Set the starting style:

```wl
In[1]:= MeshRegion[{{0, 1}, {2, 0}, {2, 2}}, Triangle[{1, 2, 3}], BaseStyle -> Blue]

Out[1]= [image]
```

---

Set multiple starting styles:

```wl
In[1]:= MeshRegion[{{0, 1}, {2, 0}, {2, 2}}, Triangle[{1, 2, 3}], BaseStyle -> {Green, Thick, EdgeForm[Dashed]}]

Out[1]= [image]
```

#### Boxed (2)

Draw the edges of the bounding box:

```wl
In[1]:= MeshRegion[{{0, 0, 0}, {2, 0, 0}, {2, 2, 0}, {0, 2, 0}, {1, 1, 2}}, Pyramid[{1, 2, 3, 4, 5}], Boxed -> True]

Out[1]= [image]
```

---

Do not draw the edges of the bounding box:

```wl
In[1]:= MeshRegion[{{0, 0, 0}, {2, 0, 0}, {2, 2, 0}, {0, 2, 0}, {1, 1, 2}}, Pyramid[{1, 2, 3, 4, 5}], Boxed -> False]

Out[1]= [image]
```

#### BoxRatios (2)

Specify the ratios between the bounding box edges:

```wl
In[1]:= MeshRegion[{{0, 0, 0}, {2, 0, 0}, {2, 2, 0}, {0, 2, 0}, {1, 1, 2}}, Pyramid[{1, 2, 3, 4, 5}], Boxed -> True, BoxRatios -> {1, 2, 3}]

Out[1]= [image]
```

---

Use the actual coordinate values for the ratios:

```wl
In[1]:= MeshRegion[{{0, 0, 0}, {2, 0, 0}, {2, 2, 0}, {0, 2, 0}, {1, 1, 2}}, Pyramid[{1, 2, 3, 4, 5}], Boxed -> True, Axes -> True, BoxRatios -> Automatic]

Out[1]= [image]
```

#### BoxStyle (1)

Use dashed lines for the bounding box:

```wl
In[1]:= MeshRegion[{{0, 0, 0}, {2, 0, 0}, {2, 2, 0}, {0, 2, 0}, {1, 1, 2}}, Pyramid[{1, 2, 3, 4, 5}], Boxed -> True, BoxStyle -> Directive[Dashed]]

Out[1]= [image]
```

#### Epilog (1)

Draw a disk above the graphic, including the axes:

```wl
In[1]:= MeshRegion[{{0, 0}, {2, -1}, {2, 1}}, {Triangle[{1, 2, 3}]}, Axes -> True, Epilog -> {Blue, Disk[{1, 0}, .4]}]

Out[1]= [image]
```

#### FaceGrids (4)

Put grids on every face of a 3D graphic:

```wl
In[1]:= MeshRegion[{{0, 0, 0}, {2, 0, 0}, {2, 2, 0}, {0, 2, 0}, {1, 1, 2}}, Pyramid[{1, 2, 3, 4, 5}], Axes -> True, Boxed -> True, FaceGrids -> All]

Out[1]= [image]
```

---

Put grids on both $x$‐$y$ faces:

```wl
In[1]:= MeshRegion[{{0, 0, 0}, {2, 0, 0}, {2, 2, 0}, {0, 2, 0}, {1, 1, 2}}, Pyramid[{1, 2, 3, 4, 5}], Axes -> True, Boxed -> True, FaceGrids -> {{0, 0, 1}, {0, 0, -1}}]

Out[1]= [image]
```

---

Put face grids on the $y=y_{\text{\textit{min}}}$ plane:

```wl
In[1]:= MeshRegion[{{0, 0, 0}, {2, 0, 0}, {2, 2, 0}, {0, 2, 0}, {1, 1, 2}}, Pyramid[{1, 2, 3, 4, 5}], Axes -> True, Boxed -> True, FaceGrids -> {{0, -1, 0}}]

Out[1]= [image]
```

---

On the $y=y_{\text{\textit{min}}}$ plane, put grid lines on $x=1$, $z=\frac{2}{3}$, and $z=\frac{4}{3}$ :

```wl
In[1]:= MeshRegion[{{0, 0, 0}, {2, 0, 0}, {2, 2, 0}, {0, 2, 0}, {1, 1, 2}}, Pyramid[{1, 2, 3, 4, 5}], Axes -> True, Boxed -> True, FaceGrids -> {{{0, -1, 0}, {{1}, {2 / 3, 4 / 3}}}}]

Out[1]= [image]
```

#### FaceGridsStyle (1)

Specify the overall style of face grids:

```wl
In[1]:= MeshRegion[{{0, 0, 0}, {2, 0, 0}, {2, 2, 0}, {0, 2, 0}, {1, 1, 2}}, Pyramid[{1, 2, 3, 4, 5}], FaceGrids -> All, FaceGridsStyle -> Directive[Orange, Dashed]]

Out[1]= [image]
```

#### Frame (2)

Draw a frame around the whole graphic:

```wl
In[1]:= MeshRegion[{{0, 1}, {2, 0}, {2, 2}}, Triangle[{1, 2, 3}], Frame -> True]

Out[1]= [image]
```

---

Draw a frame on the left and the right edges:

```wl
In[1]:= MeshRegion[{{0, 1}, {2, 0}, {2, 2}}, Triangle[{1, 2, 3}], Frame -> {{True, True}, {False, False}}]

Out[1]= [image]
```

#### FrameLabel (2)

Specify frame labels for the bottom and the left edges:

```wl
In[1]:= MeshRegion[{{0, 1}, {2, 0}, {2, 2}}, Triangle[{1, 2, 3}], Frame -> True, FrameLabel -> {x, y}]

Out[1]= [image]
```

---

Specify labels for each edge:

```wl
In[1]:= MeshRegion[{{0, 1}, {2, 0}, {2, 2}}, Triangle[{1, 2, 3}], Frame -> True, FrameLabel -> {{a, b}, {c, d}}]

Out[1]= [image]
```

#### FrameStyle (2)

Specify the overall frame style:

```wl
In[1]:= MeshRegion[{{0, 1}, {2, 0}, {2, 2}}, Triangle[{1, 2, 3}], Frame -> True, FrameStyle -> Directive[Thick, Gray]]

Out[1]= [image]
```

---

Specify the style of each frame edge:

```wl
In[1]:= MeshRegion[{{0, 1}, {2, 0}, {2, 2}}, Triangle[{1, 2, 3}], Frame -> True, FrameStyle -> {{Thick, Directive[Thick, Dashed]}, {Blue, Red}}]

Out[1]= [image]
```

#### FrameTicks (3)

Put a frame, but no ticks:

```wl
In[1]:= MeshRegion[{{0, 1}, {2, 0}, {2, 2}}, Triangle[{1, 2, 3}], Frame -> True, FrameTicks -> None]

Out[1]= [image]
```

---

Tick mark labels on the bottom and the left frame edges:

```wl
In[1]:= MeshRegion[{{0, 1}, {2, 0}, {2, 2}}, Triangle[{1, 2, 3}], Frame -> True, FrameTicks -> Automatic]

Out[1]= [image]
```

---

Frame ticks on the bottom and the right edges:

```wl
In[1]:= MeshRegion[{{0, 1}, {2, 0}, {2, 2}}, Triangle[{1, 2, 3}], Frame -> True, FrameTicks -> {{None, Automatic}, {Automatic, None}}]

Out[1]= [image]
```

#### FrameTicksStyle (2)

Specify frame tick and frame tick label style:

```wl
In[1]:= MeshRegion[{{0, 1}, {2, 0}, {2, 2}}, Triangle[{1, 2, 3}], Frame -> True, FrameTicksStyle -> Directive[Orange, 12]]

Out[1]= [image]
```

---

Specify frame tick style for each edge:

```wl
In[1]:= MeshRegion[{{0, 1}, {2, 0}, {2, 2}}, Triangle[{1, 2, 3}], Frame -> True, FrameTicksStyle -> {{Black, Blue}, {Red, Green}}]

Out[1]= [image]
```

#### GridLines (3)

Put grids across a 2D graphic:

```wl
In[1]:= MeshRegion[{{0, 1}, {2, 0}, {2, 2}}, Triangle[{1, 2, 3}], GridLines -> Automatic]

Out[1]= [image]
```

---

Draw grid lines at specific positions:

```wl
In[1]:= MeshRegion[{{0, 1}, {2, 0}, {2, 2}}, Triangle[{1, 2, 3}], Axes -> True, GridLines -> {{.5, 1.5}, {.5, 1.5}}]

Out[1]= [image]
```

---

Specify the style of each grid:

```wl
In[1]:= MeshRegion[{{-1, 0}, {1, -1}, {1, 1}}, Triangle[{1, 2, 3}], Axes -> True, GridLines -> {{{-1, Orange}, {-.5, Dotted}, {.5, Dotted}, {1, Orange}}, {-1, {-.5, Dotted}, {.5, Dotted}, 1}}]

Out[1]= [image]
```

#### GridLinesStyle (1)

Specify the overall grid style:

```wl
In[1]:= MeshRegion[{{0, 1}, {2, 0}, {2, 2}}, Triangle[{1, 2, 3}], Axes -> True, GridLines -> Automatic, GridLinesStyle -> Directive[Red, Dotted]]

Out[1]= [image]
```

#### ImageMargins (3)

Allow no margins outside of ``ImageSize`` :

```wl
In[1]:= Framed[MeshRegion[{{0, 1}, {2, 0}, {2, 2}}, Triangle[{1, 2, 3}]]]

Out[1]= [image]
```

---

Have 20-point margins on all sides:

```wl
In[1]:= Framed[MeshRegion[{{0, 1}, {2, 0}, {2, 2}}, Triangle[{1, 2, 3}], ImageMargins -> 20]]

Out[1]= [image]
```

---

Draw grid lines at specific positions:

```wl
In[1]:= Framed[MeshRegion[{{0, 1}, {2, 0}, {2, 2}}, Triangle[{1, 2, 3}], ImageMargins -> {{5, 10}, {20, 30}}]]

Out[1]= [image]
```

#### ImagePadding (4)

Leave no padding outside the plot range:

```wl
In[1]:= MeshRegion[{{0, 1}, {2, 0}, {2, 2}}, Triangle[{1, 2, 3}], ImagePadding -> None, Frame -> True, FrameLabel -> {x, y}]

Out[1]= [image]
```

---

Leave enough padding for all objects and labels that are present:

```wl
In[1]:= Framed[MeshRegion[{{0, 1}, {2, 0}, {2, 2}}, Triangle[{1, 2, 3}], ImagePadding -> All, Frame -> True, FrameLabel -> {x, y}], FrameMargins -> 0]

Out[1]= [image]
```

---

Specify the same padding for all sides in printer's points:

```wl
In[1]:= Framed[MeshRegion[{{0, 1}, {2, 0}, {2, 2}}, Triangle[{1, 2, 3}], ImagePadding -> 40, Frame -> True]]

Out[1]= [image]
```

---

Specify the same padding for all sides in printer's points:

```wl
In[1]:= Framed[MeshRegion[{{0, 1}, {2, 0}, {2, 2}}, Triangle[{1, 2, 3}], ImagePadding -> {{40, 10}, {20, 5}}, Frame -> True]]

Out[1]= [image]
```

#### ImageSize (3)

Use predefined symbolic sizes:

```wl
In[1]:= Table[MeshRegion[{{0, 1}, {2, 0}, {2, 2}}, Triangle[{1, 2, 3}], ImageSize -> s], {s, {Tiny, Small}}]

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

---

Use an explicit image width:

```wl
In[1]:= {MeshRegion[{{0, 1}, {2, 0}, {2, 2}}, Triangle[{1, 2, 3}], ImageSize -> 100], MeshRegion[{{0, 2}, {2, 0}, {2, 4}}, Triangle[{1, 2, 3}], ImageSize -> 100]}

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

---

Use an explicit image width and height:

```wl
In[1]:= {MeshRegion[{{0, 1}, {2, 0}, {2, 2}}, Triangle[{1, 2, 3}], ImageSize -> {100, 100}], MeshRegion[{{0, 2}, {2, 0}, {2, 4}}, Triangle[{1, 2, 3}], ImageSize -> {100, 100}]}

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

#### LabelStyle (1)

Specify the overall style of all the label-like elements:

```wl
In[1]:= MeshRegion[{{0, 1}, {2, 0}, {2, 2}}, Triangle[{1, 2, 3}], Axes -> True, AxesLabel -> {x, y}, LabelStyle -> Orange]

Out[1]= [image]
```

#### Lighting (4)

Ambient light is uniformly applied to all the surfaces in the scene:

```wl
In[1]:= MeshRegion[{{0, 0, 0}, {2, 0, 0}, {2, 2, 0}, {0, 2, 0}, {1, 1, 2}}, Pyramid[{1, 2, 3, 4, 5}], Lighting -> {{"Ambient", Orange}}]

Out[1]= [image]
```

---

Directional lights with different colors:

```wl
In[1]:= Table[MeshRegion[{{0, 0, 0}, {2, 0, 0}, {2, 2, 0}, {0, 2, 0}, {1, 1, 2}}, Pyramid[{1, 2, 3, 4, 5}], Lighting -> {{"Directional", c, {{1.5, 0, 2}, {0, 0, 0}}}}], {c, {Red, Yellow, Blue}}]

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

---

Point lights with different colors:

```wl
In[1]:= Table[MeshRegion[{{0, 0, 0}, {2, 0, 0}, {2, 2, 0}, {0, 2, 0}, {1, 1, 2}}, Pyramid[{1, 2, 3, 4, 5}], Lighting -> {{"Point", c, {1.5, 0, 3}}}], {c, {Red, Yellow, Blue}}]

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

---

Spotlights with different colors:

```wl
In[1]:= Table[MeshRegion[{{0, 0, 0}, {2, 0, 0}, {2, 2, 0}, {0, 2, 0}, {1, 1, 2}}, Pyramid[{1, 2, 3, 4, 5}], Lighting -> {{"Spot", c, {{1, 1, 2.5}, {1, 1, 2}}, Pi / 8}}], {c, {Red, Yellow, Blue}}]

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

#### MeshCellHighlight (3)

``MeshCellHighlight`` allows you to specify highlighting for parts of a ``MeshRegion`` :

```wl
In[1]:=
MeshRegion[{{0, 0}, {1, 0}, {2, 1 / 2}, {2, -1 / 2}}, {Line[{1, 2}], Line[{2, 3}], Line[{3, 4}], Line[{4, 2}]}, 
	MeshCellHighlight -> {{1, All} -> Red, {0, All} -> Black}]

Out[1]= [image]
```

---

By making faces transparent, the internal structure of a 3D ``MeshRegion`` can be seen:

```wl
In[1]:= 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}]}, MeshCellHighlight -> {{2, All} -> Opacity[0.5, Orange]}]

Out[1]= [image]
```

---

Individual cells can be highlighted using their cell index:

```wl
In[1]:= MeshRegion[{{0}, {1}, {2}}, Line[{{1, 2, 3}}], MeshCellHighlight -> {{1, 1} -> {Thick, Red}, {1, 2} -> {Dashed, Black}}]

Out[1]= [image]
```

Or by the cell itself:

```wl
In[2]:= MeshRegion[{{0}, {1}, {2}}, Line[{{1, 2, 3}}], MeshCellHighlight -> {Line[{1, 2}] -> {Thick, Red}, Line[{2, 3}] -> {Dashed, Black}}]

Out[2]= [image]
```

#### MeshCellLabel (3)

``MeshCellLabel`` can be used to label parts of a ``MeshRegion`` :

```wl
In[1]:= MeshRegion[{{0}, {1}, {2}}, Point[{{1}, {2}, {3}}], MeshCellLabel -> {0 -> "Index"}]

Out[1]= [image]
```

---

Label the vertices and edges of a polygon:

```wl
In[1]:= MeshRegion[{{0, 0}, {1, 0}, {1, 1}, {0, 1}}, Polygon[{1, 2, 3, 4}], MeshCellLabel -> {0 -> "Index", 1 -> "Index"}]

Out[1]= [image]
```

---

Individual cells can be labeled using their cell index:

```wl
In[1]:= MeshRegion[{{0}, {1}, {2}}, Line[{{1, 2, 3}}], MeshCellLabel -> {{1, 1} -> "x", {1, 2} -> "y"}]

Out[1]= [image]
```

Or by the cell itself:

```wl
In[2]:= MeshRegion[{{0}, {1}, {2}}, Line[{{1, 2, 3}}], MeshCellLabel -> {Line[{1, 2}] -> "x", Line[{2, 3}] -> "y"}]

Out[2]= [image]
```

#### MeshCellMarker (1)

``MeshCellMarker`` can be used to assign values to parts of a ``MeshRegion`` :

```wl
In[1]:= MeshRegion[{{0}, {1}, {2}}, Point[{{1}, {2}, {3}}], MeshCellMarker -> {{0, 1} -> 1, {0, 2} -> 2, {0, 3} -> 3}]

Out[1]= [image]
```

Use ``MeshCellLabel`` to show the markers:

```wl
In[2]:= MeshRegion[{{0}, {1}, {2}}, Point[{{1}, {2}, {3}}], MeshCellMarker -> {{0, 1} -> 1, {0, 2} -> 2, {0, 3} -> 3}, MeshCellLabel -> {0 -> "Marker"}]

Out[2]= [image]
```

#### MeshCellShapeFunction (2)

``MeshCellShapeFunction`` allows you to specify functions for parts of a ``MeshRegion`` :

```wl
In[1]:=
MeshRegion[{{0, 0}, {1, 0}, {2, 1 / 2}, {2, -1 / 2}}, {Line[{1, 2}], Line[{2, 3}], Line[{3, 4}], Line[{4, 2}]}, 
	MeshCellShapeFunction -> {1 -> (Arrow[#]&), 0 -> (Disk[#, .1]&)}]

Out[1]= [image]
```

---

Individual cells can be drawn using their cell index:

```wl
In[1]:=
MeshRegion[{{0, 0}, {1, 0}, {2, 1 / 2}, {2, -1 / 2}}, {Line[{1, 2}], Line[{2, 3}], Line[{3, 4}], Line[{4, 2}]}, 
	MeshCellShapeFunction -> {{0, 1} -> (Disk[#, .1]&), {0, 2} -> (Disk[#, {.1, .05}]&)}]

Out[1]= [image]
```

Or by the cell itself:

```wl
In[2]:=
MeshRegion[{{0, 0}, {1, 0}, {2, 1 / 2}, {2, -1 / 2}}, {Line[{1, 2}], Line[{2, 3}], Line[{3, 4}], Line[{4, 2}]}, 
	MeshCellShapeFunction -> {Point[1] -> (Disk[#, .1]&), Point[2] -> (Disk[#, {.1, .05}]&)}]

Out[2]= [image]
```

#### MeshCellStyle (3)

``MeshCellStyle`` allows you to specify styling for parts of a ``MeshRegion`` :

```wl
In[1]:=
MeshRegion[{{0, 0}, {1, 0}, {2, 1 / 2}, {2, -1 / 2}}, {Line[{1, 2}], Line[{2, 3}], Line[{3, 4}], Line[{4, 2}]}, 
	MeshCellStyle -> {{1, All} -> Red, {0, All} -> Black}]

Out[1]= [image]
```

---

By making faces transparent, the internal structure of a 3D ``MeshRegion`` can be seen:

```wl
In[1]:= 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}]}, MeshCellStyle -> {{2, All} -> Opacity[0.5, Orange]}]

Out[1]= [image]
```

---

Individual cells can be styled using their cell index:

```wl
In[1]:= MeshRegion[{{0}, {1}, {2}}, Line[{{1, 2, 3}}], MeshCellStyle -> {{1, 1} -> {Thick, Red}, {1, 2} -> {Dashed, Black}}]

Out[1]= [image]
```

Or by the cell itself:

```wl
In[2]:= MeshRegion[{{0}, {1}, {2}}, Line[{{1, 2, 3}}], MeshCellStyle -> {Line[{1, 2}] -> {Thick, Red}, Line[{2, 3}] -> {Dashed, Black}}]

Out[2]= [image]
```

#### PlotLabel (2)

Display a label on the top of the graphic in ``TraditionalForm`` :

```wl
In[1]:= MeshRegion[{{0, 1}, {2, 0}, {2, 2}}, Triangle[{1, 2, 3}], PlotLabel -> x ^ 2 + y ^ 2 == 1]

Out[1]= [image]
```

---

Use ``Style`` and other typesetting functions to modify how the label appears:

```wl
In[1]:= MeshRegion[{{-1, 0}, {1, -1}, {1, 1}}, Triangle[{1, 2, 3}], PlotLabel -> Style[Framed[x ^ 2 + y ^ 2 == 1], 16, Red, Background -> Yellow]]

Out[1]= [image]
```

#### PlotRange (3)

Display all objects:

```wl
In[1]:= MeshRegion[{{0, 1}, {2, 0}, {2, 2}}, Triangle[{1, 2, 3}], Frame -> True, PlotRange -> All]

Out[1]= [image]
```

---

Explicitly choose $x$ and $y$ ranges:

```wl
In[1]:= MeshRegion[{{-1, 0}, {1, -1}, {1, 1}}, Triangle[{1, 2, 3}], PlotRange -> {{-1, 1}, {0, 1}}, Frame -> True]

Out[1]= [image]
```

Force clipping at the ``PlotRange`` :

```wl
In[2]:= MeshRegion[{{-1, 0}, {1, -1}, {1, 1}}, Triangle[{1, 2, 3}], PlotRange -> {{-1, 1}, {0, 1}}, PlotRangeClipping -> True, Frame -> True]

Out[2]= [image]
```

---

``PlotRange -> s`` is equivalent to ``PlotRange -> {{-s, s}, {-s, s}}`` :

```wl
In[1]:= MeshRegion[{{-2, 0}, {2, -2}, {2, 2}}, Triangle[{1, 2, 3}], Frame -> True, PlotRange -> 1]

Out[1]= [image]
```

#### PlotRangeClipping (2)

Allow graphics objects to spread beyond ``PlotRange`` :

```wl
In[1]:= MeshRegion[{{-2, 0}, {2, -2}, {2, 2}}, Triangle[{1, 2, 3}], Frame -> True, PlotRange -> 1, PlotRangeClipping -> False]

Out[1]= [image]
```

---

Clip all graphics objects at ``PlotRange`` :

```wl
In[1]:= MeshRegion[{{-2, 0}, {2, -2}, {2, 2}}, Triangle[{1, 2, 3}], Frame -> True, PlotRange -> 1, PlotRangeClipping -> True]

Out[1]= [image]
```

#### PlotRangePadding (3)

Include 1 coordinate unit of padding on all sides:

```wl
In[1]:= MeshRegion[{{0, 1}, {2, 0}, {2, 2}}, Triangle[{1, 2, 3}], PlotRangePadding -> 1, Frame -> True]

Out[1]= [image]
```

---

Include padding using ``Scaled`` coordinates:

```wl
In[1]:= MeshRegion[{{0, 1}, {2, 0}, {2, 2}}, Triangle[{1, 2, 3}], PlotRangePadding -> Scaled[0.1], Frame -> True]

Out[1]= [image]
```

---

Specify different padding on each side:

```wl
In[1]:= MeshRegion[{{0, 1}, {2, 0}, {2, 2}}, Triangle[{1, 2, 3}], PlotRangePadding -> {{0.5, 1}, {0.3, 0.3}}, Frame -> True]

Out[1]= [image]
```

#### PlotRegion (3)

The contents of a graphic use the whole region:

```wl
In[1]:= MeshRegion[{{0, 1}, {2, 0}, {2, 2}}, Triangle[{1, 2, 3}], Frame -> True, FrameTicks -> False, Background -> LightBlue]

Out[1]= [image]
```

---

Limit the contents of the graphic to the middle half of the region in each direction:

```wl
In[1]:= MeshRegion[{{0, 1}, {2, 0}, {2, 2}}, Triangle[{1, 2, 3}], Frame -> True, FrameTicks -> False, PlotRegion -> {{0.25, 0.75}, {0.25, 0.75}}, Background -> LightBlue]

Out[1]= [image]
```

---

``ImagePadding`` can also be used to add padding around a graphic:

```wl
In[1]:= MeshRegion[{{0, 1}, {2, 0}, {2, 2}}, Triangle[{1, 2, 3}], Frame -> True, FrameTicks -> False, ImagePadding -> 30, Background -> LightBlue]

Out[1]= [image]
```

#### PlotTheme (9)

##### Base Themes (2)

---

Use a common base theme:

```wl
In[1]:= MeshRegion[{{0, 0, 0}, {2, 0, 0}, {2, 2, 0}, {0, 2, 0}, {1, 1, 2}}, Pyramid[{1, 2, 3, 4, 5}], PlotTheme -> "Detailed"]

Out[1]= [image]
```

---

Use a monochrome theme:

```wl
In[1]:= MeshRegion[{{0, 0, 0}, {2, 0, 0}, {2, 2, 0}, {0, 2, 0}, {1, 1, 2}}, Pyramid[{1, 2, 3, 4, 5}], PlotTheme -> "Monochrome"]

Out[1]= [image]
```

##### Feature Themes (7)

---

Use a theme to draw 0D cells:

```wl
In[1]:= MeshRegion[{{0, 0, 0}, {2, 0, 0}, {2, 2, 0}, {0, 2, 0}, {1, 1, 2}}, Pyramid[{1, 2, 3, 4, 5}], PlotTheme -> "Points"]

Out[1]= [image]
```

---

Use a theme to draw 1D cells or a wireframe:

```wl
In[1]:= MeshRegion[{{0, 0, 0}, {2, 0, 0}, {2, 2, 0}, {0, 2, 0}, {1, 1, 2}}, Pyramid[{1, 2, 3, 4, 5}], PlotTheme -> "Lines"]

Out[1]= [image]
```

---

Use a theme to draw 2D cells:

```wl
In[1]:= MeshRegion[{{0, 0, 0}, {2, 0, 0}, {2, 2, 0}, {0, 2, 0}, {1, 1, 2}}, Pyramid[{1, 2, 3, 4, 5}], PlotTheme -> "Polygons"]

Out[1]= [image]
```

---

Use a theme to draw sampled points from mesh cells:

```wl
In[1]:= MeshRegion[{{0, 0, 0}, {2, 0, 0}, {2, 2, 0}, {0, 2, 0}, {1, 1, 2}}, Pyramid[{1, 2, 3, 4, 5}], PlotTheme -> "SampledPoints"]

Out[1]= [image]
```

---

Use a theme to draw points as spheres and lines as tubes:

```wl
In[1]:= MeshRegion[{{0, 0, 0}, {2, 0, 0}, {2, 2, 0}, {0, 2, 0}, {1, 1, 2}}, Pyramid[{1, 2, 3, 4, 5}], PlotTheme -> "SphereAndTube"]

Out[1]= [image]
```

---

Use a theme to smooth shading:

```wl
In[1]:= MeshRegion[{{0, 0, 0}, {2, 0, 0}, {2, 2, 0}, {0, 2, 0}, {1, 1, 2}}, Pyramid[{1, 2, 3, 4, 5}], PlotTheme -> "SmoothShading"]

Out[1]= [image]
```

---

Use a theme to draw normals for each 2D cell:

```wl
In[1]:= MeshRegion[{{0, 0, 0}, {2, 0, 0}, {2, 2, 0}, {0, 2, 0}, {1, 1, 2}}, Pyramid[{1, 2, 3, 4, 5}], PlotTheme -> "FaceNormals"]

Out[1]= [image]
```

#### Prolog (1)

Define a simple graphic to use as a background:

```wl
In[1]:= bg = Graphics[Polygon[{{0, 0}, {1, 0}, {1, 1}, {0, 1}}, VertexColors -> {Orange, Orange, White, White}], AspectRatio -> Full];
```

Use it in multiple mesh regions:

```wl
In[2]:= MeshRegion[{{0, 1}, {2, 0}, {2, 2}}, Triangle[{1, 2, 3}], Prolog -> Inset[bg, Scaled[{0, 0}], Scaled[{0, 0}]]]

Out[2]= [image]

In[3]:= MeshRegion[{{0, 0}, {1, 0}, {2, 1 / 2}, {2, -1 / 2}}, {Line[{1, 2}], Line[{2, 3}], Line[{3, 4}], Line[{4, 2}]}, Prolog -> Inset[bg, Scaled[{0, 0}], Scaled[{0, 0}]]]

Out[3]= [image]
```

#### RotateLabel (2)

Specify that vertical frame labels should be rotated:

```wl
In[1]:= MeshRegion[{{0, 1}, {2, 0}, {2, 2}}, Triangle[{1, 2, 3}], Frame -> True, FrameLabel -> {None, "y axis"}, RotateLabel -> True]

Out[1]= [image]
```

---

Specify that vertical frame labels should not be rotated:

```wl
In[1]:= MeshRegion[{{0, 1}, {2, 0}, {2, 2}}, Triangle[{1, 2, 3}], Frame -> True, FrameLabel -> {None, "y axis"}, RotateLabel -> False]

Out[1]= [image]
```

#### SphericalRegion (2)

Make a sequence of images be consistently sized, independent of orientation:

```wl
In[1]:= Table[MeshRegion[{{0, 0, 0}, {2, 0, 0}, {2, 2, 0}, {0, 2, 0}, {1, 1, 2}}, Pyramid[{1, 2, 3, 4, 5}], SphericalRegion -> True, ImageSize -> 80, ViewPoint -> 3.{ Sin[t], Cos[t], 1}], {t, 0, 4}]

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

---

Without ``SphericalRegion``, each image is made as big as possible:

```wl
In[1]:= Table[MeshRegion[{{0, 0, 0}, {2, 0, 0}, {2, 2, 0}, {0, 2, 0}, {1, 1, 2}}, Pyramid[{1, 2, 3, 4, 5}], ImageSize -> 80, ViewPoint -> 3.{ Sin[t], Cos[t], 1}], {t, 0, 4}]

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

#### Ticks (3)

Draw the axes but no tick marks:

```wl
In[1]:= MeshRegion[{{0, 1}, {2, 0}, {2, 2}}, Triangle[{1, 2, 3}], Axes -> True, Ticks -> None]

Out[1]= [image]
```

---

Place tick marks automatically:

```wl
In[1]:= MeshRegion[{{0, 1}, {2, 0}, {2, 2}}, Triangle[{1, 2, 3}], Axes -> True, Ticks -> Automatic]

Out[1]= [image]
```

---

Draw tick marks at specific positions:

```wl
In[1]:= MeshRegion[{{0, 1}, {2, 0}, {2, 2}}, Triangle[{1, 2, 3}], Ticks -> {{1, 2, 3}, {1, 3}}, Axes -> True]

Out[1]= [image]
```

#### TicksStyle (2)

Specify the styles of the ticks and tick labels:

```wl
In[1]:= MeshRegion[{{0, 1}, {2, 0}, {2, 2}}, Triangle[{1, 2, 3}], Axes -> True, TicksStyle -> Directive[Red, Bold]]

Out[1]= [image]
```

---

Specify the styles of $x$ and $y$ axis ticks separately:

```wl
In[1]:= MeshRegion[{{0, 1}, {2, 0}, {2, 2}}, Triangle[{1, 2, 3}], Axes -> True, TicksStyle -> {Directive[Red, Bold], Directive[Blue, 12]}]

Out[1]= [image]
```

#### ViewAngle (1)

Use a specific angle for a simulated camera:

```wl
In[1]:= Table[MeshRegion[{{0, 0, 0}, {2, 0, 0}, {2, 2, 0}, {0, 2, 0}, {1, 1, 2}}, Pyramid[{1, 2, 3, 4, 5}], ViewAngle -> d °], {d, {20, 35, 50}}]

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

#### ViewCenter (1)

Place the top-right corner of the object at the center of the final image:

```wl
In[1]:= Framed[MeshRegion[{{0, 0, 0}, {2, 0, 0}, {2, 2, 0}, {0, 2, 0}, {1, 1, 2}}, Pyramid[{1, 2, 3, 4, 5}], ViewCenter -> {1, .5, .5}, SphericalRegion -> True]]

Out[1]= [image]
```

#### ViewMatrix (1)

Orthographic view of a mesh region from the negative $z$ direction:

```wl
In[1]:= MeshRegion[{{0, 0, 0}, {2, 0, 0}, {2, 2, 0}, {0, 2, 0}, {1, 1, 2}}, Pyramid[{1, 2, 3, 4, 5}], ViewMatrix -> {TransformationMatrix[RescalingTransform[{{-1, 1}, {-1, 1}, {-1, 1}}]], {{1, 0, 0, 0}, {0, 1, 0, 0}, {0, 0, -1, 0}, {0, 0, 0, 1}}}]

Out[1]= [image]
```

#### ViewPoint (3)

Specify the view point using the special scaled coordinates:

```wl
In[1]:= MeshRegion[{{0, 0, 0}, {2, 0, 0}, {2, 2, 0}, {0, 2, 0}, {1, 1, 2}}, Pyramid[{1, 2, 3, 4, 5}], ViewPoint -> {Pi, Pi / 2, 2}]

Out[1]= [image]
```

---

Use symbolic view points:

```wl
In[1]:=
{MeshRegion[{{0, 0, 0}, {2, 0, 0}, {2, 2, 0}, {0, 2, 0}, {1, 1, 2}}, Pyramid[{1, 2, 3, 4, 5}], ViewPoint -> Front], 
	MeshRegion[{{0, 0, 0}, {2, 0, 0}, {2, 2, 0}, {0, 2, 0}, {1, 1, 2}}, Pyramid[{1, 2, 3, 4, 5}], ViewPoint -> Top]}

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

---

Specify orthographic views:

```wl
In[1]:=
{MeshRegion[{{0, 0, 0}, {2, 0, 0}, {2, 2, 0}, {0, 2, 0}, {1, 1, 2}}, Pyramid[{1, 2, 3, 4, 5}], ViewPoint -> {0, -Infinity, 0}], 
	MeshRegion[{{0, 0, 0}, {2, 0, 0}, {2, 2, 0}, {0, 2, 0}, {1, 1, 2}}, Pyramid[{1, 2, 3, 4, 5}], ViewPoint -> {0, 0, Infinity}]}

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

#### ViewRange (2)

By default, the range is sufficient to include all the objects:

```wl
In[1]:= MeshRegion[{{0, 0, 0}, {2, 0, 0}, {2, 2, 0}, {0, 2, 0}, {1, 1, 2}}, Pyramid[{1, 2, 3, 4, 5}], ViewPoint -> {1, 0, 1.5}, SphericalRegion -> True]

Out[1]= [image]
```

---

Specify the minimum and maximum distances from the camera to be included:

```wl
In[1]:= MeshRegion[{{0, 0, 0}, {2, 0, 0}, {2, 2, 0}, {0, 2, 0}, {1, 1, 2}}, Pyramid[{1, 2, 3, 4, 5}], ViewPoint -> {1, 0, 1.5}, ViewRange -> {3.5, 7.2}, SphericalRegion -> True]

Out[1]= [image]
```

#### ViewVector (1)

Specify the view vectors using ordinary coordinates:

```wl
In[1]:= MeshRegion[{{0, 0, 0}, {2, 0, 0}, {2, 2, 0}, {0, 2, 0}, {1, 1, 2}}, Pyramid[{1, 2, 3, 4, 5}], ViewVector -> {{5, -5, 5}, {5, 0, -5}}]

Out[1]= [image]
```

#### ViewVertical (2)

Use the $x$ axis direction as the vertical direction in the final image:

```wl
In[1]:= MeshRegion[{{0, 0, 0}, {2, 0, 0}, {2, 2, 0}, {0, 2, 0}, {1, 1, 2}}, Pyramid[{1, 2, 3, 4, 5}], ViewVertical -> {1, 0, 0}]

Out[1]= [image]
```

---

Various views of vertical directions:

```wl
In[1]:= Table[MeshRegion[{{0, 0, 0}, {2, 0, 0}, {2, 2, 0}, {0, 2, 0}, {1, 1, 2}}, Pyramid[{1, 2, 3, 4, 5}], ViewVertical -> v], {v, {{1, 0, 1}, {.5, 0, 1}, {0, -.5, 1}, {0, -1, 1}}}]

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

### Applications (9)

#### Curves (4)

Extract the lines from a ``MeshRegion`` to make a wireframe mesh:

```wl
In[1]:= ℛ = VoronoiMesh[RandomReal[1, {50, 2}]]

Out[1]= [image]
```

The indices given in ``MeshCells`` correspond to ``MeshCoordinates`` :

```wl
In[2]:= {pts, lines} = {MeshCoordinates[ℛ], MeshCells[ℛ, 1]};

In[3]:= wireframe = MeshRegion[pts, lines]

Out[3]= [image]
```

Compare properties:

```wl
In[4]:= RegionDimension /@ {ℛ, wireframe}

Out[4]= {2, 1}

In[5]:= Area /@ {ℛ, wireframe}

Out[5]= {2.0428, 0}

In[6]:= ArcLength /@ {ℛ, wireframe}

Out[6]= {∞, 23.0082}
```

---

Compute the perimeter of a regular polygon:

```wl
In[1]:=
RegularLineMesh[n_Integer] := 
	MeshRegion[Table[{Cos[k 2π / n], Sin[k 2π / n]}, {k, n}], Line[Append[Range[n], 1]]]

In[2]:= rl = Table[RegularLineMesh[n], {n, 3, 10}]

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

Compute perimeter lengths:

```wl
In[3]:= ArcLength /@ rl

Out[3]= {5.19615, 5.65685, 5.87785, 6., 6.07437, 6.12293, 6.15636, 6.18034}
```

The perimeter approaches $2\pi$ as the number of sides goes to infinity:

```wl
In[4]:= Table[ArcLength[RegularLineMesh[n]], {n, {10, 10 ^ 2, 10 ^ 3}}]

Out[4]= {6.18034, 6.28215, 6.28317}
```

---

Create a mesh region of a Koch curve using a Lindenmayer system:

```wl
In[1]:= ProductionString[n_] := Characters@Nest[StringReplace[#, {"F" -> "F-F+F+F-F"}]&, "F", n - 1];
```

Define a function for interpreting characters in the production string to coordinates using turtle graphics:

```wl
In[2]:= Turtle[pts_, d_]["+"] := Turtle[pts, RotateRight[d]]

In[3]:= Turtle[pts_, d_]["-"] := Turtle[pts, RotateLeft[d]]

In[4]:= Turtle[{pp___, pt_}, d : {dxdy_, ___}]["F"] := Turtle[{pp, pt, pt + dxdy}, d]
```

Initial parameters for interpreting the production string:

```wl
In[5]:=
start = {0, 0};
dirs = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};
```

Compute coordinates of the Koch curve from the production string:

```wl
In[6]:= pts = Table[First@Fold[#1[#2]&, Turtle[{start}, dirs], ProductionString[n]], {n, 4}];
```

Generate mesh regions from the coordinates:

```wl
In[7]:= curves = Table[MeshRegion[p, Line[Range@Length@p]], {p, pts}]

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

Find a formula for the length of the Koch curve at iteration $n$ :

```wl
In[8]:= ArcLength /@ curves

Out[8]= {1., 5., 25., 125.}

In[9]:= FindSequenceFunction[Rationalize[%], n]

Out[9]= 5^-1 + n
```

---

Convert a graph to a ``MeshRegion``:

```wl
In[1]:=
GraphMesh[g_ ? GraphQ] := 
	MeshRegion[GraphEmbedding[g], Line[{##}]&@@@EdgeList[UndirectedGraph[g]]]
```

Some 2D embedded graphs:

```wl
In[2]:= GraphMesh /@ {StarGraph[7], WheelGraph[7], CycleGraph[7], GridGraph[{5, 5}], CompleteKaryTree[4]}

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

You can compute with these as geometric regions:

```wl
In[3]:= ArcLength /@ %

Out[3]= {6., 12., 6.07437, 40., 13.4868}
```

Some 3D embedded graphs:

```wl
In[4]:= GraphMesh /@ Graph3D /@ {StarGraph[11], CycleGraph[7], GridGraph[{5, 5, 5}], CompleteKaryTree[4]}

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

You can still compute with them:

```wl
In[5]:= ArcLength /@ %

Out[5]= {10., 6.07437, 298.276, 13.4868}
```

You can, for instance, compute the curve integral across these curves:

```wl
In[6]:= NIntegrate[x^2y^2z^2, {x, y, z}∈[image]]

Out[6]= 156061.
```

#### Surfaces (3)

Create a surface mesh by extruding a 2D curve mesh:

```wl
In[1]:=
GraphSurfaceMesh[g_ ? GraphQ] := 
	RegionProduct[MeshRegion[GraphEmbedding[g], Line[{##}]&@@@EdgeList[UndirectedGraph[g]]], MeshRegion[{{0}, {1}}, Line[{1, 2}]]]
```

Some examples with planar layouts:

```wl
In[2]:= GraphSurfaceMesh /@ {StarGraph[7], WheelGraph[7], CycleGraph[7], GridGraph[{5, 5}], CompleteKaryTree[4]}

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

You can compute with the resulting regions, in this case computing surface integrals:

```wl
In[3]:= NIntegrate[x^2y^2z^2, {x, y, z}∈[image]]

Out[3]= 0.225
```

---

Directly generate a rectangular grid mesh. Here ``IndexFlatten`` flattens out the position index in the same way that ``Flatten`` would flatten it:

```wl
In[1]:= IndexFlatten[i_List, d_List] := 1 + FoldList[Times, 1, Most[Reverse[d]]].Reverse[(i - 1)]

In[2]:=
GridMesh[{{l1_, l2_}, {u1_, u2_}}, {k1_, k2_}] := 
	Module[{pa, ia, re}, 
	pa = Table[{x, y}, {x, l1, u1, (u1 - l1) / k1}, {y, l2, u2, (u2 - l2) / k2}];
	re = {{1, 1}, {2, 1}, {2, 2}, {1, 2}};
	ia = Table[IndexFlatten[#, {k1, k2} + 1]& /@ TranslationTransform[{dx, dy}][re], {dx, 0, k1 - 1}, {dy, 0, k2 - 1}];
	MeshRegion[Flatten[pa, 1], Polygon[Flatten[ia, 1]]]
	]

In[3]:= GridMesh[{{0, 0}, {1, 1}}, {3, 3}]

Out[3]= [image]
```

Alternatively, generate the same mesh region as the product of 1D meshes:

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

Out[4]= [image]

In[5]:= RegionProduct[mr1d, mr1d]

Out[5]= [image]
```

---

Generalize the direct method above to generate a mesh region corresponding to a pattern matrix:

```wl
In[1]:= IndexFlatten[i_List, d_List] := 1 + FoldList[Times, 1, Most[Reverse[d]]].Reverse[(i - 1)]

In[2]:=
PatternGridMesh[a_List] /; MatrixQ[a] := 
	Module[{m, n, pa, ia, re}, 
	{m, n} = Dimensions[a];
	pa = Table[{x, y}, {x, 0, m}, {y, 0, n}];
	re = {{1, 1}, {2, 1}, {2, 2}, {1, 2}};
	ia = Table[IndexFlatten[#, {m, n} + 1]& /@ TranslationTransform[ind - 1][re], {ind, Position[a, 1]}];
	MeshRegion[Flatten[pa, 1], Polygon[ia]]
	]
```

Some simple patterns:

```wl
In[3]:= PatternGridMesh[{{1, 0}, {0, 1}}]

Out[3]= [image]
```

More involved patterns:

```wl
In[4]:= PatternGridMesh[Table[If[Mod[i, 4] == 2 && Mod[j, 4] == 2, 0, 1], {i, 11}, {j, 11}]]

Out[4]= [image]

In[5]:= PatternGridMesh[CellularAutomaton[30, {{1}, 0}, 50]]

Out[5]= [image]
```

#### Volumes (2)

Directly generate a rectangular grid mesh. Here ``IndexFlatten`` flattens out the position index in the same way that ``Flatten`` would flatten it:

```wl
In[1]:= IndexFlatten[i_List, d_List] := 1 + FoldList[Times, 1, Most[Reverse[d]]].Reverse[(i - 1)]

In[2]:=
GridMesh[{{l1_, l2_, l3_}, {u1_, u2_, u3_}}, {k1_, k2_, k3_}] := 
	Module[{pa, ia, re}, 
	pa = Table[{x, y, z}, {x, l1, u1, (u1 - l1) / k1}, {y, l2, u2, (u2 - l2) / k2}, {z, l3, u3, (u3 - l3) / k3}];
	re = {{1, 1, 1}, {2, 1, 1}, {2, 2, 1}, {1, 2, 1}, {1, 1, 2}, {2, 1, 2}, {2, 2, 2}, {1, 2, 2}};
	ia = Table[IndexFlatten[#, {k1, k2, k3} + 1]& /@ TranslationTransform[{dx, dy, dz}][re], {dx, 0, k1 - 1}, {dy, 0, k2 - 1}, {dz, 0, k3 - 1}];
	MeshRegion[Flatten[pa, 2], Hexahedron[Flatten[ia, 2]]]
	]

In[3]:= GridMesh[{{0, 0, 0}, {1, 1, 1}}, {3, 3, 3}]

Out[3]= [image]
```

Alternatively, generate the same mesh region as the product of 1D meshes:

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

Out[4]= [image]

In[5]:= RegionProduct[mr1d, mr1d, mr1d]

Out[5]= [image]
```

---

Generalize the direct method above to generate a mesh region corresponding to a pattern matrix:

```wl
In[1]:= IndexFlatten[i_List, d_List] := 1 + FoldList[Times, 1, Most[Reverse[d]]].Reverse[(i - 1)]

In[2]:=
PatternGridMesh[a_List] /; ArrayQ[a] && ArrayDepth[a] == 3 := 
	Module[{m, n, p, pa, ia, re}, 
	{m, n, p} = Dimensions[a];
	pa = Table[{x, y, z}, {x, 0, m}, {y, 0, n}, {z, 0, p}];
	re = {{1, 1, 1}, {2, 1, 1}, {2, 2, 1}, {1, 2, 1}, {1, 1, 2}, {2, 1, 2}, {2, 2, 2}, {1, 2, 2}};
	ia = Table[IndexFlatten[#, {m, n, p} + 1]& /@ TranslationTransform[ind - 1][re], {ind, Position[a, 1]}];
	MeshRegion[Flatten[pa, 2], Hexahedron[ia]]
	]
```

A simple pattern:

```wl
In[3]:=
PatternGridMesh[{{{1, 1, 1}, {1, 0, 1}, {1, 1, 1}}, 
	{{1, 1, 1}, {1, 0, 1}, {1, 1, 1}}, {{1, 1, 1}, {1, 0, 1}, {1, 1, 1}}}]

Out[3]= [image]
```

More involved patterns:

```wl
In[4]:= PatternGridMesh[CellularAutomaton[{14, {2, 1}, {1, 1}}, {{{1}}, 0}, 10]]

Out[4]= [image]
```

Use the idea above to construct a Seidel mesh, i.e. a mesh region with tunnels going in every direction without crossing:

```wl
In[5]:=
SeidelMesh[{r_, s_, t_}] := 
	PatternGridMesh[Table[If[Mod[i, 4] == 2 && Mod[j, 4] == 2 || Mod[i, 4] == 0 && Mod[k, 4] == 0 || Mod[j, 4] == 0 && Mod[k, 4] == 2, 0, 1], {i, 3 + r 4}, {j, 3 + s 4}, {k, 3 + t 4}]]

In[6]:= SeidelMesh[{1, 1, 1}]

Out[6]= [image]
```

By converting to a boundary mesh and styling it, it becomes easier to comprehend:

```wl
In[7]:= HighlightMesh[BoundaryMesh@SeidelMesh[{2, 2, 2}], {Style[1, None], Style[2, Opacity[0.5]]}]

Out[7]= [image]

In[8]:= HighlightMesh[BoundaryMesh@SeidelMesh[{4, 4, 4}], {Style[1, None], Style[2, Opacity[0.5]]}]

Out[8]= [image]
```

### Properties & Relations (9)

``MeshRegion`` can have any geometric dimension:

```wl
In[1]:=
point = MeshRegion[{{0, 0}}, {Point[1]}];
line = MeshRegion[{{0, 0}, {1, 1}}, {Line[{1, 2}]}];
polygon = MeshRegion[{{0, 0}, {1, 0}, {1, 1}}, {Polygon[{1, 2, 3}]}];
polytope = MeshRegion[{{0, 0, 0}, {1, 0, 0}, {0, 1, 0}, {0, 0, 1}}, {Tetrahedron[{1, 2, 3, 4}]}];

In[2]:= RegionDimension /@ {point, line, polygon, polytope}

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

---

``MeshRegion`` is always bounded:

```wl
In[1]:= ℛ = MeshRegion[{{0, 0}, {1, 0}, {0, 1}}, Polygon[{1, 2, 3}]];
```

Use ``BoundedRegionQ`` to test and ``RegionBounds`` for actual bounds:

```wl
In[2]:= {BoundedRegionQ[ℛ], rr = RegionBounds[ℛ]}

Out[2]= {True, {{0., 1.}, {0., 1.}}}

In[3]:= Show[ℛ, Graphics[{EdgeForm[Directive[Dashed, Red]], Yellow, Opacity[0.1], Cuboid@@Transpose[rr]}]]

Out[3]= [image]
```

---

``MeshRegionQ`` can be used to test whether a region is a ``MeshRegion`` :

```wl
In[1]:= ℛ = MeshRegion[{{0, 0}, {1, 0}, {0, 1}}, Polygon[{1, 2, 3}]]

Out[1]= [image]

In[2]:= MeshRegionQ[ℛ]

Out[2]= True
```

---

Use ``DelaunayMesh`` to create a ``MeshRegion`` from a set of points:

```wl
In[1]:= {p2, p3} = RandomReal[1, {20, #}]& /@ {2, 3};

In[2]:= DelaunayMesh /@ {p2, p3}

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

---

Use ``TriangulateMesh`` to convert a ``BoundaryMeshRegion`` to a ``MeshRegion`` :

```wl
In[1]:= ℛ = BoundaryMeshRegion[{{0, 0}, {1, 0}, {1, 1}}, Line[{1, 2, 3, 1}]]

Out[1]= [image]

In[2]:= TriangulateMesh[ℛ]

Out[2]= [image]
```

---

Use ``DiscretizeRegion`` to convert any region to ``MeshRegion`` :

```wl
In[1]:= DiscretizeRegion[ImplicitRegion[x ^ 2 + y ^ 2 ≤ 1, {x, y}]]

Out[1]= [image]
```

---

Use ``DiscretizeGraphics`` to convert ``Graphics`` to ``MeshRegion`` :

```wl
In[1]:= g = Graphics[{Orange, Disk[{2, 2}], Brown, Rectangle[{0, 0}, {2, 2}], Line[{{0, 0}, {4, 0}}]}]

Out[1]= [image]

In[2]:= DiscretizeGraphics[g]

Out[2]= [image]

In[3]:= MeshRegionQ[%]

Out[3]= True
```

---

Use ``Show`` to convert any ``MeshRegion`` to ``Graphics`` :

```wl
In[1]:= ℛ = MeshRegion[{{0, 0}, {1, 0}, {0, 1}}, Polygon[{1, 2, 3}]]

Out[1]= [image]

In[2]:= Show[ℛ]//InputForm
```

Out[2]//InputForm=
Graphics[GraphicsComplex[{{0., 0.}, {1., 0.}, {0., 1.}}, 
  {Directive[{Hue[0.6, 0.3, 0.95], EdgeForm[{Hue[0.6, 0.3, 0.75]}]}], 
   {Annotation[Polygon[{{1, 2, 3}}], "Geometry"]}}]]

---

``MeshRegion`` is usually more memory intensive than ``BoundaryMeshRegion`` :

```wl
In[1]:=
pts = RandomReal[1, {50, 2}];
ℛ1 = DelaunayMesh[pts];
ℛ2 = BoundaryMesh[ℛ1];

In[2]:= {ℛ1, ℛ2}

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

In[3]:= ByteCount /@ {ℛ1, ℛ2}

Out[3]= {121864, 1832}
```

## See Also

* [`BoundaryMeshRegion`](https://reference.wolfram.com/language/ref/BoundaryMeshRegion.en.md)
* [`DiscretizeRegion`](https://reference.wolfram.com/language/ref/DiscretizeRegion.en.md)
* [`DiscretizeGraphics`](https://reference.wolfram.com/language/ref/DiscretizeGraphics.en.md)
* [`DelaunayMesh`](https://reference.wolfram.com/language/ref/DelaunayMesh.en.md)
* [`VoronoiMesh`](https://reference.wolfram.com/language/ref/VoronoiMesh.en.md)
* [`SierpinskiMesh`](https://reference.wolfram.com/language/ref/SierpinskiMesh.en.md)
* [`TriangulateMesh`](https://reference.wolfram.com/language/ref/TriangulateMesh.en.md)
* [`FindMeshDefects`](https://reference.wolfram.com/language/ref/FindMeshDefects.en.md)
* [`MeshRegionQ`](https://reference.wolfram.com/language/ref/MeshRegionQ.en.md)
* [`MeshCoordinates`](https://reference.wolfram.com/language/ref/MeshCoordinates.en.md)
* [`MeshCells`](https://reference.wolfram.com/language/ref/MeshCells.en.md)
* [`MeshCellIndex`](https://reference.wolfram.com/language/ref/MeshCellIndex.en.md)
* [`MeshPrimitives`](https://reference.wolfram.com/language/ref/MeshPrimitives.en.md)
* [`Printout3D`](https://reference.wolfram.com/language/ref/Printout3D.en.md)
* [`3DS`](https://reference.wolfram.com/language/ref/format/3DS.en.md)
* [`STL`](https://reference.wolfram.com/language/ref/format/STL.en.md)
* [`OBJ`](https://reference.wolfram.com/language/ref/format/OBJ.en.md)

## Related Guides

* [Mesh-Based Geometric Regions](https://reference.wolfram.com/language/guide/MeshRegions.en.md)
* [Geometric Computation](https://reference.wolfram.com/language/guide/GeometricComputation.en.md)
* [Plane Geometry](https://reference.wolfram.com/language/guide/PlaneGeometry.en.md)
* [Solid Geometry](https://reference.wolfram.com/language/guide/SolidGeometry.en.md)
* [WDF (Wolfram Data Framework)](https://reference.wolfram.com/language/guide/WDFWolframDataFramework.en.md)
* [Partial Differential Equations](https://reference.wolfram.com/language/guide/PDEModelingAndAnalysis.en.md)
* [Systems Modeling](https://reference.wolfram.com/language/guide/SystemsModeling.en.md)

## History

* [Introduced in 2014 (10.0)](https://reference.wolfram.com/language/guide/SummaryOfNewFeaturesIn100.en.md) \| [Updated in 2015 (10.2)](https://reference.wolfram.com/language/guide/SummaryOfNewFeaturesIn102.en.md) ▪ [2017 (11.2)](https://reference.wolfram.com/language/guide/SummaryOfNewFeaturesIn112.en.md) ▪ [2022 (13.1)](https://reference.wolfram.com/language/guide/SummaryOfNewFeaturesIn131.en.md)