Home > bioelectromagnetism > mesh_edges.m

mesh_edges

PURPOSE ^

mesh_edges - Calculate edge lengths of triangulation

SYNOPSIS ^

function edge = mesh_edges(FV)

DESCRIPTION ^

 mesh_edges - Calculate edge lengths of triangulation
 
 edge = mesh_edges(FV)
 
 FV.vertices   - vertices of mesh, Nx3 Cartesian XYZ
 FV.faces      - triangulation of vertices
 
 edge          - edge lengths, indexed by vertex 
                 number (sparse NxN matrix)

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function edge = mesh_edges(FV)
0002 
0003 % mesh_edges - Calculate edge lengths of triangulation
0004 %
0005 % edge = mesh_edges(FV)
0006 %
0007 % FV.vertices   - vertices of mesh, Nx3 Cartesian XYZ
0008 % FV.faces      - triangulation of vertices
0009 %
0010 % edge          - edge lengths, indexed by vertex
0011 %                 number (sparse NxN matrix)
0012 %
0013 
0014 % $Revision: 1.1 $ $Date: 2004/11/12 01:32:35 $
0015 
0016 %
0017 % Licence:  GNU GPL, no implied or express warranties
0018 % History:  07/2002, Darren.Weber_at_radiology.ucsf.edu
0019 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0020 
0021 tic;
0022 fprintf('...searching for mesh edges...');
0023 
0024 nvertex = size(FV.vertices,1);
0025 nface   = size(FV.faces,1);
0026 
0027 % the 'edge' matrix is the connectivity of all vertices
0028 edge = sparse(nvertex,nvertex);
0029 
0030 for f = 1:nface,
0031     
0032     % compute the length of all triangle edges (Diff is [3x3])
0033     Diff = [FV.vertices(FV.faces(f,[1 2 3]),:) - FV.vertices(FV.faces(f,[2 3 1]),:)];
0034     Norm = sqrt( sum(Diff.^2, 2) );
0035     
0036     edge(FV.faces(f,1),FV.faces(f,2)) = Norm(1);
0037     edge(FV.faces(f,2),FV.faces(f,3)) = Norm(2);
0038     edge(FV.faces(f,3),FV.faces(f,1)) = Norm(3);
0039     
0040     % make sure that all edges are symmetric
0041     edge(FV.faces(f,2),FV.faces(f,1)) = Norm(1);
0042     edge(FV.faces(f,3),FV.faces(f,2)) = Norm(2);
0043     edge(FV.faces(f,1),FV.faces(f,3)) = Norm(3);
0044 end
0045 
0046 t=toc;
0047 fprintf('done (%5.2f sec).\n',t);
0048 
0049 return

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