Home > pubtools > atsurvey2spos.m

atsurvey2spos

PURPOSE ^

returns closest lattics s coordinates to xycoord points

SYNOPSIS ^

function [s,distance]=atsurvey2spos(r,xycoord,varargin)

DESCRIPTION ^

 returns closest lattics s coordinates to xycoord points 
 
 input:
   r: AT lattice
   xycoord: 2xN vector of [x,y] cartesian coordinates
   'slices', value: number of slices to split r 
                   (more slices = more precision, longer computation time)
   
 output:
   s: 1xN vector of s positions in r, closest to xycoord
   distance: 1xN vector of distances of s to xycoord
 
see also: distance2curve

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function [s,distance]=atsurvey2spos(r,xycoord,varargin)
0002 % returns closest lattics s coordinates to xycoord points
0003 %
0004 % input:
0005 %   r: AT lattice
0006 %   xycoord: 2xN vector of [x,y] cartesian coordinates
0007 %   'slices', value: number of slices to split r
0008 %                   (more slices = more precision, longer computation time)
0009 %
0010 % output:
0011 %   s: 1xN vector of s positions in r, closest to xycoord
0012 %   distance: 1xN vector of distances of s to xycoord
0013 %
0014 %see also: distance2curve
0015 
0016 % parse inputs
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 % split lattice
0030 rs=splitlattice(r,npts);
0031 G=atgeometry(rs,1:length(rs)+1);
0032 
0033 % lattice cartesian coordinates
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

Generated on Thu 24-Aug-2017 18:47:33 by m2html © 2005