Home > lattice > survey > atgeometry.m

atgeometry

PURPOSE ^

ATGEOMETRY Computes the 2-D position of all elements (no vertical bend)

SYNOPSIS ^

function [posdata,radius] = atgeometry(ring,varargin)

DESCRIPTION ^

ATGEOMETRY Computes the 2-D position of all elements (no vertical bend)

POSDATA=ATGEOMETRY(RING,REFPTS)

RING:     AT structure
REFPTS: observation points (array of indexes or logical mask)
        The allowed range is 1 to length(RING)+1
        Defaults to 1:length(RING)+1

POSDATA:Structure array, same length as REFPTS, with 5 fields:
           x, y, angle, long, trans

[POSDATA,RADIUS]=ATGEOMETRY(RING,REFPTS)
       Outputs the machine radius at the beginning of the lattice.
       Meaningful if RING is a cell of a periodic lattice.

POSDATA=ATGEOMETRY(RING,REFPTS,OFFSET)
       Start at x=offset(1), y=offset(2)
       a scalar offset value is equivalent to [0 OFFSET]

POSDATA=ATGEOMETRY(...,'centered')
       The offset is set as [0 RADIUS 0]

POSDATA=ATGEOMETRY(...,'Hangle',h_angle)
       Set the initial trajectory angle


See also: ATGEOMETRY3

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function  [posdata,radius] = atgeometry(ring,varargin)
0002 %ATGEOMETRY Computes the 2-D position of all elements (no vertical bend)
0003 %
0004 %POSDATA=ATGEOMETRY(RING,REFPTS)
0005 %
0006 %RING:     AT structure
0007 %REFPTS: observation points (array of indexes or logical mask)
0008 %        The allowed range is 1 to length(RING)+1
0009 %        Defaults to 1:length(RING)+1
0010 %
0011 %POSDATA:Structure array, same length as REFPTS, with 5 fields:
0012 %           x, y, angle, long, trans
0013 %
0014 %[POSDATA,RADIUS]=ATGEOMETRY(RING,REFPTS)
0015 %       Outputs the machine radius at the beginning of the lattice.
0016 %       Meaningful if RING is a cell of a periodic lattice.
0017 %
0018 %POSDATA=ATGEOMETRY(RING,REFPTS,OFFSET)
0019 %       Start at x=offset(1), y=offset(2)
0020 %       a scalar offset value is equivalent to [0 OFFSET]
0021 %
0022 %POSDATA=ATGEOMETRY(...,'centered')
0023 %       The offset is set as [0 RADIUS 0]
0024 %
0025 %POSDATA=ATGEOMETRY(...,'Hangle',h_angle)
0026 %       Set the initial trajectory angle
0027 %
0028 %
0029 %See also: ATGEOMETRY3
0030 
0031 [thetac,args]=getoption(varargin,'Hangle',0);
0032 centered=getflag(args,'centered');
0033 [refpts,offset]=parseargs({1:length(ring)+1,[0 0]},args);
0034 xc=0;
0035 yc=0;
0036 if isscalar(offset)
0037     yc=offset;
0038 else
0039     xc=offset(1);
0040     yc=offset(2);
0041 end
0042 [xx,yy,txy,lg,tr]=cellfun(@incr,[{struct()};ring]);    % Add a dummy element to get the origin
0043 radius=-(yc+xc/tan(thetac));
0044 if centered
0045     yy=yy+radius;
0046 end
0047 posdata=struct('x',num2cell(xx(refpts)),'y',num2cell(yy(refpts)),...
0048     'angle',num2cell(txy(refpts)),'long',num2cell(lg(refpts)),...
0049     'trans',num2cell(tr(refpts)));
0050 
0051     function varargout=incr(elem)
0052         if isfield(elem,'BendingAngle') && elem.BendingAngle ~= 0
0053             ang=0.5*elem.BendingAngle;
0054             thetac=thetac-ang;
0055             L=elem.Length/ang*sin(ang);
0056             xc=xc+L*cos(thetac);
0057             yc=yc+L*sin(thetac);
0058             thetac=thetac-ang;
0059         elseif isfield(elem,'Length')
0060             L=elem.Length;
0061             xc=xc+L*cos(thetac);
0062             yc=yc+L*sin(thetac);
0063         end
0064         c=cos(thetac); s=sin(thetac);
0065         lgtr=[xc yc]*[c -s;s c];
0066         varargout={xc,yc,thetac,lgtr(1),lgtr(2)};
0067     end
0068 end

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