---
title: "CantorMesh"
language: "en"
type: "Symbol"
summary: "CantorMesh[n] gives a mesh region representing the n\\[Null]^th-step Cantor set. CantorMesh[n, d] gives the n\\[Null]^th-step Cantor set in dimension d."
keywords: 
- Cantor set
- Cantor ternary set
- Cantor dust
canonical_url: "https://reference.wolfram.com/language/ref/CantorMesh.html"
source: "Wolfram Language Documentation"
related_guides: 
  - 
    title: "Mesh-Based Geometric Regions"
    link: "https://reference.wolfram.com/language/guide/MeshRegions.en.md"
  - 
    title: "Iterated Maps & Fractals"
    link: "https://reference.wolfram.com/language/guide/IteratedMapsAndFractals.en.md"
related_functions: 
  - 
    title: "CantorStaircase"
    link: "https://reference.wolfram.com/language/ref/CantorStaircase.en.md"
  - 
    title: "SierpinskiMesh"
    link: "https://reference.wolfram.com/language/ref/SierpinskiMesh.en.md"
  - 
    title: "ArrayMesh"
    link: "https://reference.wolfram.com/language/ref/ArrayMesh.en.md"
  - 
    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: "KaryTree"
    link: "https://reference.wolfram.com/language/ref/KaryTree.en.md"
---
# CantorMesh

CantorMesh[n] gives a mesh region representing the n$$^{\text{th}}$$-step Cantor set. 

CantorMesh[n, d] gives the n$$^{\text{th}}$$-step Cantor set in dimension d.

## Details and Options

* ``CantorMesh`` is also known as Cantor dust.

* ``CantorMesh[n]`` is generated from the unit interval by repeatedly removing the middle third of the subsequent cells.  »

[image]

* ``CantorMesh[n]`` is equivalent to ``CantorMesh[n, 1]``.

* ``CantorMesh`` has the same options as ``MeshRegion``, with the following additions:

[`DataRange`](https://reference.wolfram.com/language/ref/DataRange.en.md) 	[`Automatic`](https://reference.wolfram.com/language/ref/Automatic.en.md)	the range of mesh coordinates to generate

---

## Examples (28)

### Basic Examples (2)

A 1D Cantor mesh:

```wl
In[1]:= CantorMesh[2]

Out[1]= [image]
```

Lengths of the approximations to the Cantor mesh:

```wl
In[2]:= Table[RegionMeasure[CantorMesh[n]], {n, 5}]//Rationalize

Out[2]= {(2/3), (4/9), (8/27), (16/81), (32/243)}
```

The formula:

```wl
In[3]:= FindSequenceFunction[%, n]

Out[3]= ((2/3))^n
```

---

A 2D Cantor mesh:

```wl
In[1]:= CantorMesh[1, 2]

Out[1]= [image]
```

A 3D Cantor mesh:

```wl
In[2]:= CantorMesh[1, 3]

Out[2]= [image]
```

### Scope (4)

A 1D Cantor mesh:

```wl
In[1]:= CantorMesh[2]

Out[1]= [image]
```

---

A 2D Cantor mesh:

```wl
In[1]:= CantorMesh[2, 2]

Out[1]= [image]
```

---

A 3D Cantor mesh:

```wl
In[1]:= CantorMesh[2, 3]

Out[1]= [image]
```

---

The $n$$$^{\text{th}}$$ approximation to the Cantor set:

```wl
In[1]:= Table[CantorMesh[n], {n, 0, 5}]//Column

Out[1]= [image]
```

### Options (13)

#### DataRange (1)

``DataRange`` allows you to specify the range of mesh coordinates to generate :

```wl
In[1]:= CantorMesh[1, 2]

Out[1]= [image]

In[2]:= RegionBounds[%]

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

Specify a different range:

```wl
In[3]:= CantorMesh[1, 2, DataRange -> {{0, 1}, {0, 2}}]

Out[3]= [image]

In[4]:= RegionBounds[%]

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

#### MeshCellHighlight (2)

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

```wl
In[1]:= CantorMesh[0, 2, MeshCellHighlight -> {{1, All} -> Red, {0, All} -> Black}]

Out[1]= [image]
```

---

Individual cells can be highlighted using their cell index:

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

Out[1]= [image]
```

Or by the cell itself:

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

Out[2]= [image]
```

#### MeshCellLabel (2)

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

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

Out[1]= [image]
```

---

Individual cells can be labeled using their cell index:

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

Out[1]= [image]
```

Or by the cell itself:

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

Out[2]= [image]
```

#### MeshCellMarker (1)

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

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

Out[1]= [image]
```

Use ``MeshCellLabel`` to show the markers:

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

Out[2]= [image]
```

#### MeshCellShapeFunction (2)

``MeshCellShapeFunction`` can be used to assign values to parts of a ``CantorMesh`` :

```wl
In[1]:= CantorMesh[0, 3, MeshCellShapeFunction -> {1 -> (Tube[#1, .1]&)}]

Out[1]= [image]
```

---

Individual cells can be drawn using their cell index:

```wl
In[1]:= CantorMesh[0, 3, MeshCellShapeFunction -> {{1, 2} -> (Tube[#1, .1]&)}]

Out[1]= [image]
```

Or by the cell itself:

```wl
In[2]:= CantorMesh[0, 3, MeshCellShapeFunction -> {Line[{5, 7}] -> (Tube[#1, .1]&)}]

Out[2]= [image]
```

#### MeshCellStyle (3)

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

```wl
In[1]:= CantorMesh[0, 2, MeshCellStyle -> {{1, All} -> Red, {0, All} -> Black}]

Out[1]= [image]
```

---

Individual cells can be highlighted using their cell index:

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

Out[1]= [image]
```

Or by the cell itself:

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

Out[2]= [image]
```

---

Give explicit color directives to specify colors for individual cells:

```wl
In[1]:= CantorMesh[1, 2, MeshCellStyle -> {{2, All} -> Black, {2, 1} -> Red, {2, {2, 3}} -> Pink}]

Out[1]= [image]
```

#### PlotTheme (2)

Use a theme with grid lines and a legend:

```wl
In[1]:= CantorMesh[1, 2, PlotTheme -> "Detailed"]

Out[1]= [image]
```

---

Use a theme to draw a wireframe:

```wl
In[1]:= CantorMesh[1, 2, PlotTheme -> "Lines"]

Out[1]= [image]
```

### Applications (4)

The Cantor set is generated from the unit interval by repeatedly removing the middle third of the cells:

```wl
In[1]:= Column[{CantorMesh[0], CantorMesh[1], CantorMesh[2], CantorMesh[3]}]

Out[1]=
[image]
[image]
[image]
[image]
```

In 2D:

```wl
In[2]:= Row[{CantorMesh[0, 2], CantorMesh[1, 2], CantorMesh[2, 2]}, Spacer[60]]

Out[2]= [image]Spacer[60][image]Spacer[60][image]
```

In 3D:

```wl
In[3]:= Row[{CantorMesh[0, 3], CantorMesh[1, 3], CantorMesh[2, 3]}, Spacer[60]]

Out[3]= [image]Spacer[60][image]Spacer[60][image]
```

---

Find the length of the Cantor mesh:

```wl
In[1]:= Table[RegionMeasure[CantorMesh[k]], {k, 5}]//Rationalize

Out[1]= {(2/3), (4/9), (8/27), (16/81), (32/243)}
```

The general formula:

```wl
In[2]:= FindSequenceFunction[%, n]

Out[2]= ((2/3))^n
```

---

Find the measure of the 2D Cantor mesh:

```wl
In[1]:= Table[RegionMeasure[CantorMesh[k, 2]], {k, 5}]//Rationalize

Out[1]= {(4/9), (16/81), (64/729), (256/6561), (1024/59049)}
```

The general formula:

```wl
In[2]:= FindSequenceFunction[%, n]

Out[2]= ((4/9))^n
```

---

Find the measure of the 3D Cantor mesh:

```wl
In[1]:= Table[{k, RegionMeasure[CantorMesh[k, 3]]}, {k, 0, 3}]//Rationalize

Out[1]= {{0, 1}, {1, (8/27)}, {2, (64/729)}, {3, (512/19683)}}
```

The general formula:

```wl
In[2]:= FindSequenceFunction[%, n]

Out[2]= ((27/8))^-n
```

### Properties & Relations (4)

The output of ``CantorMesh`` is always a full-dimensional ``MeshRegion`` :

```wl
In[1]:= CantorMesh[3, 2]

Out[1]= [image]

In[2]:= {MeshRegionQ[%], RegionDimension[%]}

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

---

``CantorMesh`` consists of intervals in 1D:

```wl
In[1]:= CantorMesh[2]

Out[1]= [image]

In[2]:= MeshCells[%, RegionDimension[%]]

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

Rectangles in 2D:

```wl
In[3]:= CantorMesh[1, 2]

Out[3]= [image]

In[4]:= MeshCells[%, RegionDimension[%]]

Out[4]= {Polygon[{1, 5, 6, 2}], Polygon[{3, 7, 8, 4}], Polygon[{9, 13, 14, 10}], Polygon[{11, 15, 16, 12}]}
```

Hexahedrons in 3D:

```wl
In[5]:= CantorMesh[0, 3]

Out[5]= [image]

In[6]:= MeshCells[%, RegionDimension[%]]

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

---

The total length removed of the Cantor set is 1:

```wl
In[1]:= Table[RegionMeasure[CantorMesh[n]] / 2, {n, 5}]//Rationalize

Out[1]= {(1/3), (2/9), (4/27), (8/81), (16/243)}
```

Guess the general formula:

```wl
In[2]:= FindSequenceFunction[%, i]

Out[2]= 2^-1 + i 3^-i

In[3]:= Limit[Sum[%, {i, 1, n}], n -> Infinity]

Out[3]= 1
```

---

``DataRange -> range`` is equivalent to using ``RescalingTransform[{…}, range]`` :

```wl
In[1]:= CantorMesh[1, 2, DataRange -> {{1, 2}, {1, 3}}, Frame -> True]

Out[1]= [image]
```

Use ``RescalingTransform`` :

```wl
In[2]:= box  = TransformedRegion[CantorMesh[1, 2], RescalingTransform[{{0, 1}, {0, 1}}, {{1, 2}, {1, 3}}]];

In[3]:= MeshRegion[box, Frame -> True]

Out[3]= [image]
```

### Possible Issues (1)

``CantorMesh`` can be too large to generate:

```wl
In[1]:= CantorMesh[20, 3]
```

CantorMesh::nomem: The current computation was aborted because there was insufficient memory available to complete the computation.

```wl
Out[1]= CantorMesh[20, 3]
```

## See Also

* [`CantorStaircase`](https://reference.wolfram.com/language/ref/CantorStaircase.en.md)
* [`SierpinskiMesh`](https://reference.wolfram.com/language/ref/SierpinskiMesh.en.md)
* [`ArrayMesh`](https://reference.wolfram.com/language/ref/ArrayMesh.en.md)
* [`MeshRegion`](https://reference.wolfram.com/language/ref/MeshRegion.en.md)
* [`BoundaryMeshRegion`](https://reference.wolfram.com/language/ref/BoundaryMeshRegion.en.md)
* [`KaryTree`](https://reference.wolfram.com/language/ref/KaryTree.en.md)

## Related Guides

* [Mesh-Based Geometric Regions](https://reference.wolfram.com/language/guide/MeshRegions.en.md)
* [Iterated Maps & Fractals](https://reference.wolfram.com/language/guide/IteratedMapsAndFractals.en.md)

## History

* [Introduced in 2017 (11.1)](https://reference.wolfram.com/language/guide/SummaryOfNewFeaturesIn111.en.md)