TRIMESHSURFACEAREA Surface area of a triangular mesh. S = trimeshSurfaceArea(V, F) S = trimeshSurfaceArea(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 is a NF-by-3, containing vertex indices of each face. Example % Compute area of an octahedron (equal to 2*sqrt(3)*a*a, with % a = sqrt(2) in this case) [v f] = createOctahedron; trimeshSurfaceArea(v, f) ans = 6.9282 % triangulate a compute area of a unit cube [v f] = createCube; f2 = triangulateFaces(f); trimeshSurfaceArea(v, f2) ans = 6 See also meshes3d, meshSurfaceArea, trimeshMeanBreadth, triangulateFaces
0001 function area = trimeshSurfaceArea(v, e, f) 0002 %TRIMESHSURFACEAREA Surface area of a triangular mesh. 0003 % 0004 % S = trimeshSurfaceArea(V, F) 0005 % S = trimeshSurfaceArea(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 is a NF-by-3, containing vertex indices of each face. 0009 % 0010 % Example 0011 % % Compute area of an octahedron (equal to 2*sqrt(3)*a*a, with 0012 % % a = sqrt(2) in this case) 0013 % [v f] = createOctahedron; 0014 % trimeshSurfaceArea(v, f) 0015 % ans = 0016 % 6.9282 0017 % 0018 % % triangulate a compute area of a unit cube 0019 % [v f] = createCube; 0020 % f2 = triangulateFaces(f); 0021 % trimeshSurfaceArea(v, f2) 0022 % ans = 0023 % 6 0024 % 0025 % See also 0026 % meshes3d, meshSurfaceArea, trimeshMeanBreadth, triangulateFaces 0027 0028 % ------ 0029 % Author: David Legland 0030 % e-mail: david.legland@inra.fr 0031 % Created: 2011-08-26, using Matlab 7.9.0.529 (R2009b) 0032 % Copyright 2011 INRA - Cepia Software Platform. 0033 0034 % check input number 0035 if nargin == 2 0036 f = e; 0037 end 0038 0039 % compute two direction vectors, using first vertex of each face as origin 0040 v1 = v(f(:, 2), :) - v(f(:, 1), :); 0041 v2 = v(f(:, 3), :) - v(f(:, 1), :); 0042 0043 % area of each triangle is half the cross product norm 0044 vn = vectorNorm3d(crossProduct3d(v1, v2)); 0045 0046 % sum up and normalize 0047 area = sum(vn) / 2;