({{, (RefLink[ArrayMesh, paclet:ref/ArrayMesh])[array] 
generates a mesh region from an array of rank d in which each cell has a geometric dimension d and represents a nonzero value of the array.}})

OpenersNotesSection(Spacer1)Details and Options

(RefLink[ArrayMesh, paclet:ref/ArrayMesh]) is generated from a grid where cells are intervals, squares, or cubes, and grid points are uniformly spaced integer points.

(RefLink[ArrayMesh, paclet:ref/ArrayMesh]) arranges successive rows of array down and successive columns across.

(RefLink[ArrayMesh, paclet:ref/ArrayMesh]) has the same options as (RefLink[MeshRegion, paclet:ref/MeshRegion]), with the following additions:

(RefLink[ArrayMesh, paclet:ref/ArrayMesh]) works with (RefLink[SparseArray, paclet:ref/SparseArray]) objects.

OpenersPrimaryExamplesSection(Spacer1)Examples  (40)

OpenersExampleSection0(Spacer1)Basic Examples  (3)

A 1D array mesh:

ArrayMesh[{1,0,1,1,0,1}]

A 2D array mesh:

ArrayMesh[{{1,1,0,1},{1,1,1,1},{0,1,0,1}}]

A 3D array mesh:

ArrayMesh[{{{1,1},{1,1},{1,0}},{{0,1},{1,1},{0,0}}}]

OpenersExampleSection1(Spacer1)Scope  (2)

Create a 1D array mesh:

ArrayMesh[{1,1,0,0,1}]

2D array mesh:

ArrayMesh[{{1,1,0,1},{1,1,1,1},{0,1,0,1}}]

3D array mesh:

ArrayMesh[{{{1,1},{1,1},{1,0}},{{0,1},{1,1},{0,0}}}]

(RefLink[ArrayMesh, paclet:ref/ArrayMesh]) works on (RefLink[SparseArray, paclet:ref/SparseArray]):

ArrayMesh[SparseArray[{{x_,y_}/;Abs[x-y]<2->1},{3,3}]]

OpenersExampleSection2(Spacer1)Options  (14)

OpenersExampleSubsection0(Spacer1)DataRange  (1)

(RefLink[DataRange, paclet:ref/DataRange]) allows you to specify the range of mesh coordinates to generate:

ArrayMesh[{{1,0},{1,1}}]

MeshCoordinates[%]

Specify a different range:

ArrayMesh[{{1,0},{1,1}},DataRange->{{0,1},{0,2}}]

MeshCoordinates[%]

OpenersExampleSubsection1(Spacer1)DataReversed  (1)

(RefLink[DataReversed, paclet:ref/DataReversed]) allows you to reverse the order of rows:

ArrayMesh[{{1,0,0},{1,1,0},{1,0,1},{1,1,1}}]

Reverse the order of rows:

ArrayMesh[{{1,0,0},{1,1,0},{1,0,1},{1,1,1}},DataReversed->True]

OpenersExampleSubsection2(Spacer1)MeshCellHighlight  (2)

(RefLink[MeshCellHighlight, paclet:ref/MeshCellHighlight]) allows you to specify highlighting for parts of an (RefLink[ArrayMesh, paclet:ref/ArrayMesh]):

ArrayMesh[{{1,0},{1,1}},MeshCellHighlight->{{1,All}->Red,{0,All}->Black}]

Individual cells can be highlighted using their cell index:

ArrayMesh[{{1,0},{1,1}},MeshCellHighlight->{{1,1}->{Thick,Red},{1,2}->{Dashed,Black}}]

Or by the cell itself:

ArrayMesh[{{1,0},{1,1}},MeshCellHighlight->{Line[{4,6}]->{Thick,Red},Line[{5,6}]->{Dashed,Black}}]

OpenersExampleSubsection3(Spacer1)MeshCellLabel  (2)

(RefLink[MeshCellLabel, paclet:ref/MeshCellLabel]) can be used to label parts of an (RefLink[ArrayMesh, paclet:ref/ArrayMesh]):

ArrayMesh[{{1,0},{1,1}},MeshCellLabel->{0->"Index"}]

Individual cells can be labeled using their cell index:

ArrayMesh[{{1,0},{1,1}},MeshCellLabel->{{1,2}->"x",{1,1}->"y"}]

Or by the cell itself:

ArrayMesh[{{1,0},{1,1}},MeshCellLabel->{Line[{5,6}]->"x",Line[{4,6}]->"y"}]

OpenersExampleSubsection4(Spacer1)MeshCellMarker  (1)

(RefLink[MeshCellMarker, paclet:ref/MeshCellMarker]) can be used to assign values to parts of an (RefLink[ArrayMesh, paclet:ref/ArrayMesh]):

ArrayMesh[{{1,0}},MeshCellMarker->{{0,1}->1,{0,2}->2,{0,3}->3,{0,4}->4}]

Use (RefLink[MeshCellLabel, paclet:ref/MeshCellLabel]) to show the markers:

ArrayMesh[{{1,0}},MeshCellMarker->{{0,1}->1,{0,2}->2,{0,3}->3,{0,4}->4},MeshCellLabel->{0->"Marker"}]

OpenersExampleSubsection5(Spacer1)MeshCellShapeFunction  (2)

(RefLink[MeshCellShapeFunction, paclet:ref/MeshCellShapeFunction]) can be used to assign values to parts of an (RefLink[ArrayMesh, paclet:ref/ArrayMesh]):

ArrayMesh[{{{1,0}}},MeshCellShapeFunction->{1->(Tube[#1,.1]&)}]

Individual cells can be drawn using their cell index:

ArrayMesh[{{{1,0}}},MeshCellShapeFunction->{{1,4}->(Tube[#1,.1]&)}]

Or by the cell itself:

ArrayMesh[{{{1,0}}},MeshCellShapeFunction->{Line[{1,2}]->(Tube[#1,.1]&)}]

OpenersExampleSubsection6(Spacer1)MeshCellStyle  (3)

(RefLink[MeshCellStyle, paclet:ref/MeshCellStyle]) allows you to specify styling for parts of an (RefLink[ArrayMesh, paclet:ref/ArrayMesh]):

ArrayMesh[{{1,0}},MeshCellStyle->{{1,All}->Red,{0,All}->Black}]

Individual cells can be highlighted using their cell index:

ArrayMesh[{{1,0}},MeshCellStyle->{{1,1}->{Thick,Red},{1,2}->{Dashed,Black}}]

Or by the cell itself:

ArrayMesh[{{1,0}},MeshCellStyle->{Line[{3,4}]->{Thick,Red},Line[{2,4}]->{Dashed,Black}}]

Give explicit color directives to specify colors for individual cells:

ArrayMesh[{{1,0,0,1},{1,1,0,1},{1,0,1,1}},MeshCellStyle->{{2,All}->Black,{2,1}->Red,{2,{2,3}}->Pink}]

OpenersExampleSubsection7(Spacer1)PlotTheme  (2)

Use a theme with grid lines and a legend:

ArrayMesh[{{1,0},{1,1}},PlotTheme->"Detailed"]

Use a theme to draw a wireframe:

ArrayMesh[{{1,0},{1,1}},PlotTheme->"Lines"]

OpenersExampleSection3(Spacer1)Applications  (15)

OpenersExampleSubsection8(Spacer1)Cellular Automaton  (5)

A two-dimensional cellular automaton evolution:

ArrayMesh[CellularAutomaton[30,{{1},0},50]]

Show a sequence of steps in the evolution of a 3D cellular automaton:

ArrayMesh /@ CellularAutomaton[{14,{2,1},{1,1,1}},{{{{1}}},0},10]

Use an outer-totalistic 2D cellular automaton to generate a maze-like pattern:

ArrayMesh[CellularAutomaton[{746,{2,{{2,2,2},{2,1,2},{2,2,2}}},{1,1}},{{Table[1,{7}]},0},{{{150}}}]]

Show a "glider" in the Game of Life:

c=CellularAutomaton[{224,{2,{{2,2,2},{2,1,2},{2,2,2}}},{1,1}},{{{0,1,0},{0,0,1},{1,1,1}},0},8];

glider=(First/@Position[Flatten[#],1])&/@c;

ArrayMesh[ConstantArray[1,{5,5}],MeshCellStyle->{{1,All}->Black,{2,All}->White,{2,#}->Black}]&/@glider

Patterns generated by a sequence of 2D nine-neighbor rules:

Table[ArrayMesh[CellularAutomaton[{i, {2, 1}, {1, 1}},{{{1}},0},{{{30}}}]],{i,2,20,4}]

Mean cell values:

Table[ArrayMesh[Mean[CellularAutomaton[{i, {2, 1}, {1, 1}},{{{1}},0},10]]],{i,2,20,4}]

OpenersExampleSubsection9(Spacer1)Image  (2)

Convert a 2D image to a (RefLink[MeshRegion, paclet:ref/MeshRegion]):

img=;

Cells and styles:

cells=ImageData[img];

style=MapIndexed[{2,First[#2]}->GrayLevel[#1] &,Flatten[cells]];

The mesh:

ArrayMesh[cells,MeshCellStyle->style]

Convert a 3D image:

img=Image3D[RandomReal[1,{2,3,4}],ColorFunction->GrayLevel]

Cells and styles:

cells=Transpose[ImageData[img],{2,3,1}];

style=MapIndexed[{3,First[#2]}->GrayLevel[#1] &,Flatten[cells]];

The mesh:

ArrayMesh[cells,MeshCellStyle->style]

OpenersExampleSubsection10(Spacer1)Pattern  (2)

Generate a simple 2D pattern:

ArrayMesh[Table[If[Mod[i,4]==2&&Mod[j,4]==2,0,1],{i,11},{j,11}]]

3D pattern:

ArrayMesh[{{{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}}}]

More involved patterns:

ArrayMesh[CellularAutomaton[{14, {2, 1}, {1, 1}},{{{1}},0},10]]

Construct a Seidel mesh, i.e. a mesh region with tunnels going in every direction without crossing:

SeidelMesh[{r_,s_,t_}]:=ArrayMesh[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}]]

SeidelMesh[{1,1,1}]

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

HighlightMesh[BoundaryMesh[%],{Style[1,None],Style[2,Opacity[0.5]]}]

OpenersExampleSubsection11(Spacer1)SubstitutionSystem  (4)

A 1D Cantor mesh:

ArrayMesh[{1,0,1,0,0,0,1,0,1}]

Length of the Cantor set at each stage:

Table[Rationalize[RegionMeasure[ArrayMesh[n]]],{n,SubstitutionSystem[{1->{1,0,1},0->{0,0,0}},{1},5]}]

The formula:

FindSequenceFunction[%,n]

Steps in constructing a Cantor set:

ArrayMesh[{#}]&/@SubstitutionSystem[{1->{1,0,1},0->{0,0,0}},{1},3]

Create an analogous 2D nested object:

ArrayMesh/@SubstitutionSystem[{1->{{1,1,1},{1,0,1},{1,1,1}},0->ConstantArray[0,{3,3}]},{{1}},3]

3D Menger sponge:

ArrayMesh/@SubstitutionSystem[{1->1-CrossMatrix[{1,1,1}],0->ConstantArray[0,{3,3,3}]},{{{1}}},3]

OpenersExampleSubsection12(Spacer1)Game Design  (2)

Build a 2D chessboard:

m=Join@@ConstantArray[{{0,1,0,1,0,1,0,1},{1,0,1,0,1,0,1,0}},4];

p=First/@Position[Flatten[m],1];

style={{1,All}->{Thick,Black},{2,All}->White,{2,#}&/@p->Black};

r=ArrayMesh[ConstantArray[1,{8,8}],MeshCellStyle->style]

3D chessboard:

m=Join@@ConstantArray[{{{0},{1},{0},{1},{0},{1},{0},{1}},{{1},{0},{1},{0},{1},{0},{1},{0}}},4];

p=First/@Position[Flatten[m],1];

style={{1,All}->{Thick,Black},{3,All}->White,{3,#}&/@p->Black};

r=ArrayMesh[ConstantArray[1,{8,8,1}],MeshCellStyle->style]

Generate tetrominoes, shapes composed of four squares each:

reg = ArrayMesh /@ {(({{1, 0, 0, 0}, {1, 0, 0, 0}, {1, 0, 0, 0}, {1, 0, 0, 0}})),(({{1, 1, 0, 0}, {0, 1, 0, 0}, {0, 1, 0, 0}, {0, 0, 0, 0}})),(({{1, 1, 0, 0}, {1, 0, 0, 0}, {1, 0, 0, 0}, {0, 0, 0, 0}})),(({{0, 1, 0, 0}, {1, 1, 0, 0}, {0, 1, 0, 0}, {0, 0, 0, 0}})),(({{1, 0, 0, 0}, {1, 1, 0, 0}, {0, 1, 0, 0}, {0, 0, 0, 0}})),(({{1, 1, 0, 0}, {1, 1, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}})),(({{1, 1, 0, 0}, {0, 1, 1, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}))}

Color tetrominoes:

col=ColorData[97,"ColorList"];

Table[MeshRegion[reg[[i]],MeshCellStyle-> {2-> col[[i]]}],{i,7}]

OpenersExampleSection4(Spacer1)Properties & Relations  (6)

The output of (RefLink[ArrayMesh, paclet:ref/ArrayMesh]) is always a full-dimensional (RefLink[MeshRegion, paclet:ref/MeshRegion]):

ArrayMesh[RandomInteger[1,{3,4}]]

{MeshRegionQ[%],RegionDimension[%]}

(RefLink[ArrayMesh, paclet:ref/ArrayMesh]) consists of intervals in 1D:

ArrayMesh[{1,1,0,0,1}]

MeshCells[%,RegionDimension[%]]

Rectangles in 2D:

ArrayMesh[{{0,0,1,1},{0,1,1,0},{1,0,0,0}}]

MeshCells[%,RegionDimension[%]]

Hexahedrons in 3D:

ArrayMesh[{{{1,0},{0,1}}}]

MeshCells[%,RegionDimension[%]]

(RefLink[ArrayPlot, paclet:ref/ArrayPlot]) can be used to generate a plot:

arr={{0,1,1,0},{1,0,1,0},{1,1,0,1}};

ArrayMesh[arr]

Show plot:

ArrayPlot[arr]

(RefLink[MatrixPlot, paclet:ref/MatrixPlot]) can be used to generate a plot:

arr={{0,1,1,0},{1,0,1,0},{1,1,0,1}};

ArrayMesh[arr]

Show plot:

MatrixPlot[arr]

Find a boundary mesh region by using (RefLink[BoundaryMesh, paclet:ref/BoundaryMesh]):

BoundaryMesh[ArrayMesh[{{0,1,1,0},{1,0,1,0},{1,1,0,1}}]]

(RefLink[DataRange, paclet:ref/DataRange])-> range is equivalent to using (RefLink[RescalingTransform, paclet:ref/RescalingTransform])[{...}, range]:

ArrayMesh[{{1,0},{1,1}},DataRange->{{1,2},{1,3}},Frame->True]

Use (RefLink[RescalingTransform, paclet:ref/RescalingTransform]):

box =TransformedRegion[ArrayMesh[{{1,0},{1,1}}],RescalingTransform[{{0,2},{0,2}},{{1,2},{1,3}}]];

MeshRegion[box,Frame->True]

({{DocumentationFooterIconsRelatedFunction.png, ({{See Also}, {(RefLink[ArrayPlot, paclet:ref/ArrayPlot])  ▪  (RefLink[MatrixPlot, paclet:ref/MatrixPlot])  ▪  (RefLink[ArrayFlatten, paclet:ref/ArrayFlatten])  ▪  (RefLink[MeshRegion, paclet:ref/MeshRegion])  ▪  (RefLink[BoundaryMeshRegion, paclet:ref/BoundaryMeshRegion])  ▪  (RefLink[CellularAutomaton, paclet:ref/CellularAutomaton])}})}})

({{DocumentationFooterIconsRelatedGuide.png, ({{Related Guides}, {▪(RefLinkPlain[Mesh-Based Geometric Regions, paclet:guide/MeshRegions])}, {▪(RefLinkPlain[Geometric Computation, paclet:guide/GeometricComputation])}})}})