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@inrae.fr
0018 % Created: 2018-06-21, using Matlab 9.4.0.813654 (R2018a)
0019 % Copyright 2018-2024 INRA - Cepia Software Platform
0020 
0021 if isnumeric(faces)
0022     % trimesh or quadmesh
0023     nf = size(faces, 1);
0024     areas = zeros(nf, 1);
0025     if size(vertices, 2) == 2
0026         % planar case
0027         for f = 1:nf
0028             areas(f,:) = polygonArea(vertices(faces(f,:), :));
0029         end
0030     else
0031         % 3D case
0032         if size(faces, 2) == 3
0033             % For triangular meshes, uses accelerated method
0034             v1 = vertices(faces(:,1), :);
0035             v12 = vertices(faces(:,2), :) - v1;
0036             v13 = vertices(faces(:,3), :) - v1;
0037             areas = vectorNorm3d(crossProduct3d(v12, v13))/2;
0038             
0039         else
0040             % for quad (or larger) meshes, use slower but more precise method
0041             for f = 1:nf
0042                 areas(f) = polygonArea3d(vertices(faces(f,:), :));
0043             end
0044         end
0045     end
0046     
0047 else
0048     % mesh with faces stored as cell array
0049     nf = length(faces);
0050     areas = zeros(nf, 1);
0051     if size(vertices, 2) == 2
0052         % planar case
0053         for f = 1:nf
0054             areas(f) = polygonArea(vertices(faces{f}, :));
0055         end
0056     else
0057         % 3D case
0058         for f = 1:nf
0059             areas(f) = polygonArea3d(vertices(faces{f}, :));
0060         end
0061     end
0062 end
0063

Generated on Thu 21-Nov-2024 11:30:22 by m2html © 2003-2022