ADDED mttroot/mtt/bin/trans/m/adjbond.m Index: mttroot/mtt/bin/trans/m/adjbond.m ================================================================== --- /dev/null +++ mttroot/mtt/bin/trans/m/adjbond.m @@ -0,0 +1,27 @@ +function [index,distance] = adjbond(point,arrow_end,other_end); +% adjbond: Determines the bond closest to the point +% [index,distance] = adjbond(point,arrow_end,other_end); + + +% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% %% Version control history +% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% %% $Id$ +% %% $Log$ +% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + + +[n,m] = size(other_end); +one = ones(n,1); +arrow_distance = length2d(one*point - arrow_end); +min_arrow_distance = min(arrow_distance); + +other_distance = length2d(one*point - other_end); +min_other_distance = min(other_distance); + +min_distance = min([arrow_distance; other_distance]); + +adjacent = [arrow_distance, other_distance] == min_distance*[one one]; +[index,n] = getindex(adjacent,1); +distance = min_distance; + ADDED mttroot/mtt/bin/trans/m/adjcomp.m Index: mttroot/mtt/bin/trans/m/adjcomp.m ================================================================== --- /dev/null +++ mttroot/mtt/bin/trans/m/adjcomp.m @@ -0,0 +1,33 @@ +function indices = adjcomp(arrow_end,other_end,components); +% adjcomp: Determines the two components at each end of the bond + + + +% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% %% Version control history +% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% %% $Id$ +% %% $Log$ +% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + + +[n,m] = size(components); +one = ones(n,1); + +arrow_distance = length2d(one*arrow_end - components(:,1:2)); +min_arrow_distance = min(arrow_distance); + +other_distance = length2d(one*other_end - components(:,1:2)); +min_other_distance = min(other_distance); + +arrow_adjacent = arrow_distance==min_arrow_distance*one; +other_adjacent = other_distance==min_other_distance*one; +[index,n] = getindex([arrow_adjacent,other_adjacent],1); + +if index(1,2)==1 + indices = index(1:2,1)'; +else + indices = index(2:-1:1,1)'; +end; + + ADDED mttroot/mtt/bin/trans/m/getindex.m Index: mttroot/mtt/bin/trans/m/getindex.m ================================================================== --- /dev/null +++ mttroot/mtt/bin/trans/m/getindex.m @@ -0,0 +1,46 @@ +function [index, n, otherindex, m] = getindex(array,value); +% Finds the n indices of the elements of array equal to value +% otherindex contains indeces of the the m other elements. + + +% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% %% Version control history +% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% %% $Id$ +% %% $Log$ +% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +[N,M] = size(array); +n=0; m=0; +for i=1:N + for j = 1:M + if array(i,j)==value + n=n+1; + index(n,:) = [i j]; + else + m=m+1; + otherindex(m,:) = [i j]; + end; + end; +end; + + +if (M==1)&(n>0) + index = index(:,1); +end; + +if (M==1)&(m>0) + otherindex = otherindex(:,1); +end; + +% Octave doesn't like empty matrices +if n==0 + index=0; +end; + +if m==0 + otherindex=0; +end; + + +