# How to calculate the area of all the subareas in a mesh?

I have used Voronoi mesh to generate a mesh of a group of random numbers,

pts = RandomReal[{-1, 1}, {8, 2}];
mesh = VoronoiMesh[pts]


So, it will generate a graph similar to this:

I want to calculate the area of each mesh grid. Is there any function that can be used to do that? Thanks.

• Area /@ MeshPrimitives[mesh,2] Commented Jun 23, 2016 at 23:54

This is a MeshRegion,

SeedRandom[420];
pts = RandomReal[{-1, 1}, {8, 2}];
mesh = VoronoiMesh[pts]


You could get the individual polygons with MeshPrimitives and then use Area to find the area. This was my first thought, but the comments below made me realize it is much faster to use the built-in functions PropertyValue and MeshCellMeasure. So at the expense of a longer code, this is what we'll use

PropertyValue[{mesh, 2}, MeshCellMeasure]
(* {0.439766, 0.51057, 0.373666, 0.494299, 0.734753, 0.387787,
1.10474, 1.01007} *)


As pointed out by J.M. can get the same thing with the built-in, but slightly longer, PropertyValue[{mesh, 2}, MeshCellMeasure]. You can label the cells with the area using HighlightMesh

HighlightMesh[mesh,
MapIndexed[Labeled[{2, First@#2}, #1] &,
PropertyValue[{mesh, 2}, MeshCellMeasure]]]


• PropertyValue[{mesh, 2}, MeshCellMeasure] will also return the list of areas. Commented Jun 24, 2016 at 0:23
• Thanks, I never look for a built-in when I can work out how to do something. Commented Jun 24, 2016 at 1:01
• Using the MeshCellMeasure approach will be faster for large computations, as it does not have to call the evaluator. Commented Jun 24, 2016 at 2:12
• @JasonB, no they are calculated when requested. But then they are computed in one go. In the Area approach each is cell is passed to Area and that is equivalent to calling the evaluator. Possibly calling Area /@... will also unpack the data. Commented Jun 24, 2016 at 2:18
• @JasonB, basically internally MeshCellMeasure calls a C code version of Area[allcells]. On top level things were a bit better if one could call something like Area[MeshPrimitives[mesh, 2][[All, 1]]] Commented Jun 24, 2016 at 2:38