Surface area of a polyhedral mesh. S = meshSurfaceArea(V, F) S = meshSurfaceArea(V, E, F) Computes the surface area of the mesh specified by vertex array V and face array F. Vertex array is a NV-by-3 array of coordinates. Face array can be a NF-by-3 or NF-by-4 numeric array, or a Nf-by-1 cell array, containing vertex indices of each face. This functions iterates on faces, extract vertices of the current face, and computes the sum of face areas. This function assumes faces are coplanar and convex. If faces are all triangular, the function "trimeshSurfaceArea" should be more efficient. Example % compute the surface of a unit cube (should be equal to 6) [v f] = createCube; meshSurfaceArea(v, f) ans = 6 See also meshes3d, trimeshSurfaceArea, meshVolume, meshFaceAreas, meshFacePolygons, polygonArea3d
0001 function area = meshSurfaceArea(varargin) 0002 % Surface area of a polyhedral mesh. 0003 % 0004 % S = meshSurfaceArea(V, F) 0005 % S = meshSurfaceArea(V, E, F) 0006 % Computes the surface area of the mesh specified by vertex array V and 0007 % face array F. Vertex array is a NV-by-3 array of coordinates. 0008 % Face array can be a NF-by-3 or NF-by-4 numeric array, or a Nf-by-1 cell 0009 % array, containing vertex indices of each face. 0010 % 0011 % This functions iterates on faces, extract vertices of the current face, 0012 % and computes the sum of face areas. 0013 % 0014 % This function assumes faces are coplanar and convex. If faces are all 0015 % triangular, the function "trimeshSurfaceArea" should be more efficient. 0016 % 0017 % 0018 % Example 0019 % % compute the surface of a unit cube (should be equal to 6) 0020 % [v f] = createCube; 0021 % meshSurfaceArea(v, f) 0022 % ans = 0023 % 6 0024 % 0025 % See also 0026 % meshes3d, trimeshSurfaceArea, meshVolume, meshFaceAreas, 0027 % meshFacePolygons, polygonArea3d 0028 % 0029 0030 % ------ 0031 % Author: David Legland 0032 % e-mail: david.legland@inrae.fr 0033 % Created: 2010-10-13, using Matlab 7.9.0.529 (R2009b) 0034 % Copyright 2010 INRA - Cepia Software Platform. 0035 0036 % parse input arguments 0037 [vertices, faces] = parseMeshData(varargin{:}); 0038 0039 % pre-compute normals 0040 normals = normalizeVector3d(meshFaceNormals(vertices, faces)); 0041 0042 % init accumulator 0043 area = 0; 0044 0045 0046 if isnumeric(faces) 0047 % iterate on faces in a numeric array 0048 for i = 1:size(faces, 1) 0049 poly = vertices(faces(i, :), :); 0050 area = area + polyArea3d(poly, normals(i,:)); 0051 end 0052 0053 else 0054 % iterate on faces in a cell array 0055 for i = 1:length(faces) 0056 poly = vertices(faces{i}, :); 0057 area = area + polyArea3d(poly, normals(i,:)); 0058 end 0059 end 0060 0061 0062 function a = polyArea3d(v, normal) 0063 0064 nv = size(v, 1); 0065 v0 = repmat(v(1,:), nv, 1); 0066 products = sum(cross(v-v0, v([2:end 1], :)-v0, 2), 1); 0067 a = abs(dot(products, normal, 2))/2;