MeshCellCount[mreg]
gives a list {c0,c1,…} of counts cd of cells of dimension d in the mesh region mreg.
MeshCellCount[mreg,d]
gives the total count of cells of dimension d.
MeshCellCount[mreg,cellspec]
gives the total count of cells specified by cellspec.
MeshCellCount
MeshCellCount[mreg]
gives a list {c0,c1,…} of counts cd of cells of dimension d in the mesh region mreg.
MeshCellCount[mreg,d]
gives the total count of cells of dimension d.
MeshCellCount[mreg,cellspec]
gives the total count of cells specified by cellspec.
Details
- MeshCellCount counts the cells in each dimension.
- The mesh region mreg can be either MeshRegion or BoundaryMeshRegion.
- The cell specification cellspec follows the standard form {dim,indexes} and is specifically described in the reference pages for MeshRegion and BoundaryMeshRegion.
Examples
open all close allBasic Examples (2)
Count the cells in each dimension for a MeshRegion in 2D:
ℛ = MeshRegion[{{0, 0}, {1, 0}, {1, 1}, {0, 1}}, Polygon[{1, 2, 3, 4}]]MeshCellCount[ℛ]MeshCellCount[ℛ, 1]Count the cells in each dimension for a BoundaryMeshRegion in 3D:
ℛ = ConvexHullMesh[RandomReal[1, {10, 3}]]Only the boundary surfaces are cells:
MeshCellCount[ℛ]Scope (8)
Count the cells in each dimension for a MeshRegion in 1D:
ℛ = MeshRegion[{{0}, {1}, {2}}, {Line[{1, 2}], Point[3]}]MeshCellCount[ℛ]MeshCellCount[ℛ, 0]Count the cells in each dimension for a MeshRegion in 2D:
ℛ = MeshRegion[{{0, 0}, {1, 0}, {1, 1}, {0, 1}}, Polygon[{1, 2, 3, 4}]]MeshCellCount[ℛ]MeshCellCount[ℛ, 1]Count the cells in each dimension for a MeshRegion in 3D:
ℛ = MeshRegion[{{0, 0, 0}, {2, 0, 0}, {2, 2, 0}, {0, 2, 0}, {1, 1, 2}}, Tetrahedron[{{1, 2, 3, 5}, {1, 3, 4, 5}}], MeshCellStyle -> 2 -> Opacity[0.3]]MeshCellCount[ℛ]MeshCellCount[ℛ, 2]Count the cells in each dimension for a BoundaryMeshRegion in 1D:
ℛ = ConvexHullMesh[RandomReal[1, {5, 1}]]Only the boundary points are cells:
MeshCellCount[ℛ]Count the cells in each dimension for a BoundaryMeshRegion in 2D:
ℛ = ConvexHullMesh[RandomReal[1, {5, 2}]]Only the boundary curves are cells:
MeshCellCount[ℛ]Count the cells in each dimension for a BoundaryMeshRegion in 3D:
ℛ = ConvexHullMesh[RandomReal[1, {10, 3}]]Only the boundary surfaces are cells:
MeshCellCount[ℛ]Use All to count the number of cells regardless of dimension:
ℛ = DelaunayMesh[RandomReal[1, {20, 2}]]The number of cells is equal to the sum of the cells in each dimension:
MeshCellCount[ℛ, All] == Total@MeshCellCount[ℛ]Works with large mesh regions:
ℛ = DiscretizeRegion[Disk[], MaxCellMeasure -> 10 ^ -5];MeshCellCount[ℛ]Properties & Relations (5)
MeshCellCount corresponds to the lengths cell lists in MeshCells:
mr = MeshRegion[{{0, 0}, {1, 0}, {0, 1}}, Triangle[{1, 2, 3}]]{MeshCellCount[mr], Length /@ MeshCells[mr, All]}MeshCellCount is typically larger than the number of cells used in MeshRegion:
mr = MeshRegion[{{0, 0}, {1, 0}, {0, 1}}, Triangle[{1, 2, 3}]]The additional cells are points and edges for the triangle:
MeshCellCount[mr]MeshCells[mr, All]An
-dimensional simplex has
cells in total:
s[n_] := MeshRegion[Prepend[Table[UnitVector[n, i], {i, n}], Table[0, {n}]], Simplex[Range[n + 1]]]Table[Labeled[s[i], {2^i + 1 - 1, Total@MeshCellCount[s[i]]}], {i, 1, 3}]MeshCellCount for a BoundaryMeshRegion in 2D:
ℛ = ConvexHullMesh[RandomReal[1, {5, 2}]]The vertex and edge count satisfy
:
{v, e} = MeshCellCount[ℛ]v - e == 0Even with holes it satisfies the same relation:
ℛ = BoundaryMeshRegion[{{0, 0}, {3, 0}, {3, 3}, {0, 3}, {1, 1}, {2, 1}, {2, 2}, {1, 2}}, Line[{1, 2, 3, 4, 1}], Line[{5, 6, 7, 8, 5}]]{v, e} = MeshCellCount[ℛ]v - e == 0MeshCellCount for a BoundaryMeshRegion in 3D satisfies Euler's formula
:
ℛ = ConvexHullMesh[RandomReal[1, {15, 3}]]{v, e, f} = MeshCellCount[ℛ]v - e + f == 2With
voids you have the relation
:
pts = {{0, 0, 0}, {0, 1, 0}, {1, 1, 0}, {1, 0, 0}, {0, 0, 1}, {0, 1, 1}, {1, 1, 1}, {1, 0, 1}};
pts1 = ScalingTransform[{3, 3, 3}][pts];
pts2 = TranslationTransform[{1, 1, 1}][pts];
hex = {{2, 3, 4, 1}, {1, 4, 8, 5}, {4, 3, 7, 8}, {3, 2, 6, 7}, {2, 1, 5, 6}, {5, 8, 7, 6}};ℛ = BoundaryMeshRegion[Join[pts1, pts2], Polygon[hex], Polygon[hex + 8], MeshCellStyle -> Opacity[0.3]]{v, e, f} = MeshCellCount[ℛ]v - e + f == 2(1 + 1)Related Guides
History
Text
Wolfram Research (2014), MeshCellCount, Wolfram Language function, https://reference.wolfram.com/language/ref/MeshCellCount.html.
CMS
Wolfram Language. 2014. "MeshCellCount." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/MeshCellCount.html.
APA
Wolfram Language. (2014). MeshCellCount. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/MeshCellCount.html
BibTeX
@misc{reference.wolfram_2026_meshcellcount, author="Wolfram Research", title="{MeshCellCount}", year="2014", howpublished="\url{https://reference.wolfram.com/language/ref/MeshCellCount.html}", note=[Accessed: 13-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_meshcellcount, organization={Wolfram Research}, title={MeshCellCount}, year={2014}, url={https://reference.wolfram.com/language/ref/MeshCellCount.html}, note=[Accessed: 13-June-2026]}