Home > bioelectromagnetism > mesh_face_area.m

mesh_face_area

PURPOSE ^

mesh_face_area - Calculate face area

SYNOPSIS ^

function [faceArea] = mesh_face_area(FV)

DESCRIPTION ^

 mesh_face_area - Calculate face area
 
 [area] = mesh_face_area(FV)
 
 FV.vertices   - vertices of mesh, Nx3 Cartesian XYZ
 FV.faces      - triangulation of vertices (Mx3 matrix)
 
 area          - face area (Mx1 array)

 If the lengths of the three sides are known then Heron's formula
 can be used: sqrt(s*(s-a)*(s-b)*(s-c)) (where a, b, c are the sides
 of the triangle, and s = (a + b + c)/2 is half of its perimeter).

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [faceArea] = mesh_face_area(FV)
0002 
0003 % mesh_face_area - Calculate face area
0004 %
0005 % [area] = mesh_face_area(FV)
0006 %
0007 % FV.vertices   - vertices of mesh, Nx3 Cartesian XYZ
0008 % FV.faces      - triangulation of vertices (Mx3 matrix)
0009 %
0010 % area          - face area (Mx1 array)
0011 %
0012 % If the lengths of the three sides are known then Heron's formula
0013 % can be used: sqrt(s*(s-a)*(s-b)*(s-c)) (where a, b, c are the sides
0014 % of the triangle, and s = (a + b + c)/2 is half of its perimeter).
0015 %
0016 
0017 % $Revision: 1.1 $ $Date: 2004/11/12 01:32:35 $
0018 
0019 %
0020 % Licence:  GNU GPL, no implied or express warranties
0021 % History:  05/2004, Darren.Weber_at_radiology.ucsf.edu
0022 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0023 
0024 tic;
0025 fprintf('...calculating face area...');
0026 
0027 nface   = size(FV.faces,1);
0028 
0029 faceArea = zeros(nface,1);
0030 
0031 for f = 1:nface,
0032     
0033     % get the vertex index numbers into FV.vertices
0034     vertex_index1 = FV.faces(f,1);
0035     vertex_index2 = FV.faces(f,2);
0036     vertex_index3 = FV.faces(f,3);
0037     
0038     % get the vertex coordinates in Cartesian XYZ
0039     vertex1 = FV.vertices(vertex_index1,:);
0040     vertex2 = FV.vertices(vertex_index2,:);
0041     vertex3 = FV.vertices(vertex_index3,:);
0042     
0043     % face surface area
0044     % If the lengths of the three sides are known then Heron's formula
0045     % can be used: sqrt(s*(s-a)*(s-b)*(s-c)) (where a, b, c are the sides
0046     % of the triangle, and s = (a + b + c)/2 is half of its perimeter).
0047     
0048     % a is the distance from vertex1 to vertex2
0049     a = sqrt ( sum( ( vertex2 - vertex1 ).^2 ) );
0050     % b is the distance from vertex2 to vertex3
0051     b = sqrt ( sum( ( vertex3 - vertex2 ).^2 ) );
0052     % c is the distance from vertex3 to vertex1
0053     c = sqrt ( sum( ( vertex1 - vertex3 ).^2 ) );
0054     
0055     s = (a + b + c)/2;
0056     
0057     faceArea(f) = sqrt(s*(s-a)*(s-b)*(s-c));
0058     
0059 end
0060 
0061 t=toc;
0062 fprintf('done (%5.2f sec).\n',t);
0063 
0064 return

Generated on Mon 15-Aug-2005 15:36:19 by m2html © 2003