Function Repository Resource:

PolygonArea3D

Source Notebook

Compute the area of a planar 2D polygon using 3D points

Contributed by: Ed Pegg Jr and Jan Mangaldan

ResourceFunction["PolygonArea3D"][poly]

computes the area of the three-dimensional polygon poly.

Details

The polygon poly can be specified as a list of points or using Polygon or Triangle.

Examples

Basic Examples (2) 

Find the area of a 3D triangle:

In[1]:=
ResourceFunction[
 "PolygonArea3D"][{{8, -9, 16}, {11, -9, 12}, {-10, -9, -8}}]
Out[1]=

Find the area of the faces of a tetrahedron:

In[2]:=
ResourceFunction["PolygonArea3D"] /@ Subsets[{{0, 0, 0}, {0, 0, 6}, {0, 8, 6}, {6, 2, 9}}, {3}]
Out[2]=

Scope (3) 

Specify the polygon using Polygon:

In[3]:=
ResourceFunction["PolygonArea3D"][
 Polygon[{{8, -9, 16}, {11, -9, 12}, {-10, -9, -8}}]]
Out[3]=

Specify the polygon using Triangle:

In[4]:=
ResourceFunction["PolygonArea3D"][
 Triangle[{{0, 0, 0}, {1, 0, 0}, {0, 1, 1}}]]
Out[4]=

Calculate the areas for faces of a dodecahedron:

In[5]:=
vert = PolyhedronData["Dodecahedron", "VertexCoordinates"];
face = PolyhedronData["Dodecahedron", "FaceIndices"];
Union[Table[
  RootReduce[
   ResourceFunction["PolygonArea3D"][vert[[face[[k]]]]]], {k, 1, 12}]]
Out[7]=

Properties and Relations (2) 

Find the area of one face of the d120:

In[8]:=
vert = PolyhedronData["DisdyakisTriacontahedron", "VertexCoordinates"];
face = PolyhedronData["DisdyakisTriacontahedron", "FaceIndices"];
N[ResourceFunction["PolygonArea3D"][vert[[face[[1]]]]]]
Out[9]=

Measure the areas of all 120 faces with TriangleArea3D and get the time required:

In[10]:=
Timing[Union[
  Table[N[ResourceFunction["PolygonArea3D"][vert[[face[[k]]]]]], {k, 1, 120}]]]
Out[10]=

Measure the areas of all 120 faces with RegionMeasure and get the time required:

In[11]:=
Timing[Union[
  Table[N[RegionMeasure[Triangle[vert[[face[[k]]]]]]], {k, 1, 120}]]]
Out[11]=

Measure the areas of all 120 faces with the HeronFormula and get the time required:

In[12]:=
Timing[Union[Table[ResourceFunction["HeronFormula"][
    EuclideanDistance @@ # & /@ N[Subsets[vert[[face[[k]]]], {2}]]], {k, 1, 120}]]]
Out[12]=

Timings with exact values:

In[13]:=
Timing[Union[
  Table[RootReduce[
    ResourceFunction["PolygonArea3D"][vert[[face[[k]]]]]], {k, 1, 120}]]]
Out[13]=
In[14]:=
Timing[Union[
  Table[RootReduce[RegionMeasure[Triangle[vert[[face[[k]]]]]]], {k, 1,
     120}]]]
Out[14]=

PolygonArea3D cannot find the area of a triangle with a variable:

In[15]:=
ResourceFunction[
 "PolygonArea3D"][{{8, -9, 16}, {11, -9, 12}, {-10, -9, x}}]
Out[15]=

RegionMeasure can find the area of a triangle with a variable:

In[16]:=
RegionMeasure[Triangle[{{8, -9, 16}, {11, -9, 12}, {-10, -9, x}}]]
Out[16]=

Possible Issues (2) 

Point order matters. Find the area of a larger polygon:

In[17]:=
pts = {{1, 6, 8}, {1, 8, 6}, {2, 9, 4}, {4, 9, 2}, {6, 8, 1}, {8, 6, 1}, {9, 4, 2}, {9, 2, 4}, {8, 1, 6}, {6, 1, 8}, {4, 2, 9}, {2, 4, 9}};
ResourceFunction["PolygonArea3D"][pts]
Out[18]=

Show the polygon:

In[19]:=
Graphics3D[Polygon[pts], Boxed -> False, ImageSize -> Small]
Out[19]=

Calculate the area of the points in a different order:

In[20]:=
pts2 = Flatten[Permutations[#] & /@ {{1, 6, 8}, {2, 4, 9}}, 1];
ResourceFunction["PolygonArea3D"][pts2]
Out[21]=

Show the polygon:

In[22]:=
Graphics3D[Polygon[pts2], Boxed -> False, ImageSize -> Small]
Out[22]=

The following points are not planar:

In[23]:=
pts = {{0, 0, 0}, {0, 1, 0}, {1, 1, 1}, {1, 0, 0}};
ResourceFunction["SimplexVolume"][pts]
Out[24]=

Therefore, this computed area is spurious:

In[25]:=
ResourceFunction[
 "PolygonArea3D"][{{0, 0, 0}, {0, 1, 0}, {1, 1, 1}, {1, 0, 0}}]
Out[25]=

Requirements

Wolfram Language 13.0 (December 2021) or above

Version History

  • 1.0.0 – 25 October 2023

Related Resources

License Information