


CLOSESTSEGMENT - find the closest segment of a profile
This routine find the segment of the profile A that is the closest
to (xi,yi) and return the number of the profile and the number of
the first point belonging to this closest segment
Usage:
[profsel indsel]=closestsegment(A,numprofiles,xi,yi)

0001 function [profsel indsel]=closestsegment(A,numprofiles,xi,yi) 0002 %CLOSESTSEGMENT - find the closest segment of a profile 0003 % 0004 % This routine find the segment of the profile A that is the closest 0005 % to (xi,yi) and return the number of the profile and the number of 0006 % the first point belonging to this closest segment 0007 % 0008 % Usage: 0009 % [profsel indsel]=closestsegment(A,numprofiles,xi,yi) 0010 0011 %loop over the middles of each profile, find the closest to (xi,yi) 0012 profsel=0; 0013 indsel=0; 0014 first=1; 0015 for i=1:numprofiles, 0016 if length(A(i).x)>1 0017 middles=[(A(i).x(1:end-1)+A(i).x(2:end))/2 (A(i).y(1:end-1)+A(i).y(2:end))/2]; 0018 distance=(xi-middles(:,1)).^2+(yi-middles(:,2)).^2; 0019 [newdistance p]=min(distance); 0020 if (first | (newdistance<olddistance)), 0021 first=0; 0022 indsel=p; 0023 profsel=i; 0024 olddistance=newdistance; 0025 end 0026 end 0027 end 0028 end