fabien van mook

all packages "fvm-*"

package "fvm-geometry"

function file "polygon3dcalc.m"

Function o = polygon3dcalc(points,faces)
         o = polygon3dcalc(points,faces,isclosed)
         o = polygon3dcalc(points,faces,isclosed,volumes)

calculates:
-- area of each surface,
-- perimeter length of each surface,
-- unit normal vector of each surface,
-- centroid of each volume,
-- volume (quantity) of each volume,
given the surfaces described by triangles and quadrangles.

The input structures must be organised like this:
  points.(<pointid>).xyz = [<xp>,<yp>,<zp>];
and:
  faces.(<faceid>).vertices = {<pointid>, ...};
and either:
  faces.(<faceid>).volume = <volumeid>
or:
  volumes.(<volumeid>).faces = {<faceid>, ...};
where <pointid>, <faceid> and <volumeid> are strings
to identify points (vertices), surfaces and volumes 
respectively.

If structure volumes is given, all faces.(<faceid>).volume 
(silently) are ignored.
If structure volumes is not given, and if a particular
surface has no faces.(<faceid>).volume, this surface is
not accounted for in the volume calculations.

The output structure o is a structure organised like this:
  o.faces.(<faceid>).area = A;
  o.faces.(<faceid>).perimeter = L;
  o.faces.(<faceid>).normal = [<xn>,<yn>,<zn>];
  o.volumes.(<volumeid>).centroid = [<xc>,<yc>,<zc>];
  o.volumes.(<volumeid>).volume = V;

A surface is normally described by a list of 3 or 4 vertices,
but a larger number is possible.

The ordre of the vertices of a surface must follow the rule:
counter-clockwise direction as seen when one is at a point
above the front side of the surface and looks towards the 
surface.

If the last mentioned vertex in the list of vertices for
a surface is the same as the first vertex, the third input
argument isclosed must be set to true or set to the 
string "closed".

The normal of a surface points outwards from the front side
of the surface.

The calculation of the volume does not depend on its convex
or concave shape. (See Nürnberg 2013.) The normals of each
surface which bound a volume, must point outwards from the
volume.

Messages are written via function mssg(). Errors do not
cause a abrupt stop.

References:
  Clarke, J.A. (2001). "Energy simulation in building
  design." 2nd edition. Oxford (UK): Butterworth-Heinemann.
  Pages 212-214.

  Robert Nürnberg (2013). "Calculating the volume and
  centroid of a polyhedron in 3d."
  http://wwwf.imperial.ac.uk/~rn/centroid.pdf

  Paul Bourke. "Polygons and meshes : In what follows 
  are various notes and algorithms dealing with polygons 
  and meshes." Written between 1987-2018.
  http://paulbourke.net/geometry/polygonmesh/

(c) 2026 fabien van mook

2026.08.20 release of this file within package "fvm-geometry" under GNU GPLv3+