0001 function [s,distance]=atsurvey2spos(r,xycoord,varargin)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017 p = inputParser;
0018 defaultslices = 10^5;
0019
0020 addRequired(p,'r',@iscell);
0021 addRequired(p,'xycoord',@isnumeric);
0022 addOptional(p,'slices',defaultslices,@isnumeric);
0023
0024 parse(p,r,xycoord,varargin{:});
0025 r = p.Results.r;
0026 mapxy = p.Results.xycoord;
0027 npts= p.Results.slices;
0028
0029
0030 rs=splitlattice(r,npts);
0031 G=atgeometry(rs,1:length(rs)+1);
0032
0033
0034 rx=[G.x];
0035 ry=[G.y];
0036 curvexy=[rx;ry]';
0037
0038 [xy,distance,~] = distance2curve(curvexy,mapxy,'linear');
0039
0040 indmin=arrayfun(@(x)find(curvexy(:,1)>x,1,'first'),xy(:,1));
0041
0042 s=findspos(rs,indmin);
0043
0044 end
0045
0046
0047 function rsplit=splitlattice(ring0,npts)
0048 elmlength=findspos(ring0,1+length(ring0))/npts;
0049 r2=cellfun(@(a)splitelem(a,elmlength),ring0,'UniformOutput',false);
0050 rsplit=cat(1,r2{:});
0051 end
0052
0053 function newelems=splitelem(elem,elmlength)
0054 if isfield(elem,'Length') && elem.Length > 0
0055 nslices=ceil(elem.Length/elmlength);
0056 newelems=atdivelem(elem,ones(1,nslices)./nslices);
0057 else
0058 newelems={elem};
0059 end
0060 end