mesh_vertex_distance - Calculates spherical intervertex distances (arc length). Usage: [distances] = mesh_vertex_distance(vertices) Notes: vertices is an Nx3 matrix of rectangular Cartesian coordinates with a centroid at (0,0,0). If the centroid is elsewhere, all vertex points are internally shifted to adjust the centroid because the arc length method employed assumes a centroid at (0,0,0). Sphere radius is estimated by the average radius from (xo,yo,zo) to any 2 pairs of vertices. It will vary from one pair to another, but this method works well for small theta (eg, nearest neighbours). Returns a matrix for paired electrode arc length estimates. The matrix is a full matrix, but the upper triange is zeros.
0001 function [distances] = mesh_vertex_distance(vertices) 0002 0003 % mesh_vertex_distance - Calculates spherical intervertex distances (arc length). 0004 % 0005 % Usage: [distances] = mesh_vertex_distance(vertices) 0006 % 0007 % Notes: vertices is an Nx3 matrix of rectangular Cartesian coordinates 0008 % with a centroid at (0,0,0). If the centroid is elsewhere, all 0009 % vertex points are internally shifted to adjust the centroid 0010 % because the arc length method employed assumes a 0011 % centroid at (0,0,0). 0012 % 0013 % Sphere radius is estimated by the average radius from 0014 % (xo,yo,zo) to any 2 pairs of vertices. It will vary 0015 % from one pair to another, but this method works well for 0016 % small theta (eg, nearest neighbours). 0017 % 0018 % Returns a matrix for paired electrode arc length estimates. 0019 % The matrix is a full matrix, but the upper triange is zeros. 0020 % 0021 0022 % $Revision: 1.1 $ $Date: 2004/11/12 01:32:35 $ 0023 0024 % Author: Darren.Weber_at_radiology.ucsf.edu 0025 % Created: 18/05/00 - linear distance 0026 % Modified: 24/06/01 - spherical arc length (should be OK for small theta 0027 % but for large theta, elliptical arc length may be 0028 % preferable). 0029 % 0030 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0031 0032 fprintf('%s\n', 'Calculating inter-vertex spherical arc length.'); 0033 0034 % check centroid, unless input parameters defined 0035 mean = mean(vertices); 0036 xo = mean(1); 0037 yo = mean(2); 0038 zo = mean(3); 0039 0040 % define vertices A,B, given centroid (xo,yo,zo) 0041 A = [ (vertices(:,1)-xo) (vertices(:,2)-yo) (vertices(:,3)-zo) ]; 0042 0043 A_len = sqrt( sum(A.^2,2) ); % length of vertex vector A 0044 0045 % Initialise distances matrix 0046 distances = zeros(length(vertices)); 0047 0048 progress_bar('init'); 0049 for a=1:length(vertices), 0050 0051 progress = a / length(vertices); 0052 progress_bar('set',progress); 0053 0054 Aa = A(a,:); 0055 Al = A_len(a); % length of vertex vector Aa 0056 0057 r = (Al + A_len(a:end))/2; % estimate sphere radius from Al and B_len 0058 dotAB = zeros(length(A)-a,1); 0059 for i=a:length(A), dotAB(i-(a-1),1) = dot(Aa,A(i,:)); end 0060 theta = acos( dotAB ./ (Al * A_len(a:end)) ); 0061 arc_len = r .* theta; % arc length = radius * theta 0062 distances(a:length(A),a) = arc_len; 0063 0064 %for b=a:length(vertices), 0065 % Bb = A(b,:); 0066 % Bl = A_len(b); % length of vertex vector Bb 0067 % if( Aa == Bb ), 0068 % arc_len = 0; % no distance from vertex to itself 0069 % else 0070 % r = (Al + Bl)/2; % estimate sphere radius from A_len and B_len 0071 % theta = acos( dot(Aa,Bb) / (Al * Bl) ); % Angle between A & B, in radians 0072 % arc_len = r * theta; % arc length = radius * theta 0073 % end 0074 % distances(a,b) = arc_len; 0075 %end 0076 end 0077 distances = real(distances); 0078 0079 progress_bar('clear'); 0080 0081 return