Home > matGeom > meshes3d > meshFaceAreas.m

meshFaceAreas

PURPOSE ^

MESHFACEAREAS Surface area of each face of a mesh.

SYNOPSIS ^

function areas = meshFaceAreas(vertices, faces)

DESCRIPTION ^

MESHFACEAREAS Surface area of each face of a mesh.

   areas = meshFaceAreas(vertices, faces)

   Example
     [v, f] = createOctahedron;
     meshFaceAreas(v, f)'
     ans =
         1.7321  1.7321  1.7321  1.7321  1.7321  1.7321  1.7321  1.7321

   See also
     meshes3d, meshSurfaceArea, meshFaceCentroids

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function areas = meshFaceAreas(vertices, faces)
0002 %MESHFACEAREAS Surface area of each face of a mesh.
0003 %
0004 %   areas = meshFaceAreas(vertices, faces)
0005 %
0006 %   Example
0007 %     [v, f] = createOctahedron;
0008 %     meshFaceAreas(v, f)'
0009 %     ans =
0010 %         1.7321  1.7321  1.7321  1.7321  1.7321  1.7321  1.7321  1.7321
0011 %
0012 %   See also
0013 %     meshes3d, meshSurfaceArea, meshFaceCentroids
0014  
0015 % ------
0016 % Author: David Legland
0017 % e-mail: david.legland@inra.fr
0018 % Created: 2018-06-21,    using Matlab 9.4.0.813654 (R2018a)
0019 % Copyright 2018 INRA - Cepia Software Platform.
0020 
0021 
0022 if isnumeric(faces)
0023     % trimesh or quadmesh
0024     nf = size(faces, 1);
0025     areas = zeros(nf, 1);
0026     if size(vertices, 2) == 2
0027         % planar case
0028         for f = 1:nf
0029             areas(f,:) = polygonArea(vertices(faces(f,:), :));
0030         end
0031     else
0032         % 3D case
0033         if size(faces, 2) == 3
0034             % For triangular meshes, uses accelerated method
0035             v1 = vertices(faces(:,1), :);
0036             v12 = vertices(faces(:,2), :) - v1;
0037             v13 = vertices(faces(:,3), :) - v1;
0038             areas = vectorNorm3d(crossProduct3d(v12, v13))/2;
0039             
0040         else
0041             % for quad (or larger) meshes, use slower but more precise method
0042             for f = 1:nf
0043                 areas(f) = polygonArea3d(vertices(faces(f,:), :));
0044             end
0045         end
0046     end
0047     
0048 else
0049     % mesh with faces stored as cell array
0050     nf = length(faces);
0051     areas = zeros(nf, 1);
0052     if size(vertices, 2) == 2
0053         % planar case
0054         for f = 1:nf
0055             areas(f) = polygonArea(vertices(faces{f}, :));
0056         end
0057     else
0058         % 3D case
0059         for f = 1:nf
0060             areas(f) = polygonArea3d(vertices(faces{f}, :));
0061         end
0062     end
0063 end
0064

Generated on Wed 16-Feb-2022 15:10:47 by m2html © 2003-2019