Line | |
---|
1 | function [profsel indsel]=closestsegment(A,numprofiles,xi,yi)
|
---|
2 | %CLOSESTSEGMENT - find the closest segment of a profile
|
---|
3 | %
|
---|
4 | % This routine find the segment of the profile A that is the closest
|
---|
5 | % to (xi,yi) and return the number of the profile and the number of
|
---|
6 | % the first point belonging to this closest segment
|
---|
7 | %
|
---|
8 | % Usage:
|
---|
9 | % [profsel indsel]=closestsegment(A,numprofiles,xi,yi)
|
---|
10 |
|
---|
11 | %loop over the middles of each profile, find the closest to (xi,yi)
|
---|
12 | profsel=0;
|
---|
13 | indsel=0;
|
---|
14 | first=1;
|
---|
15 | for i=1:numprofiles,
|
---|
16 | if length(A(i).x)>1
|
---|
17 | 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];
|
---|
18 | distance=(xi-middles(:,1)).^2+(yi-middles(:,2)).^2;
|
---|
19 | [newdistance p]=min(distance);
|
---|
20 | if (first | (newdistance<olddistance)),
|
---|
21 | first=0;
|
---|
22 | indsel=p;
|
---|
23 | profsel=i;
|
---|
24 | olddistance=newdistance;
|
---|
25 | end
|
---|
26 | end
|
---|
27 | end
|
---|
28 | end
|
---|
Note:
See
TracBrowser
for help on using the repository browser.