Home > lattice > survey > atgeometry3.m

atgeometry3

PURPOSE ^

ATGEOMETRY3 Computes the 3-D position of all elements

SYNOPSIS ^

function posdata = atgeometry3(ring,varargin)

DESCRIPTION ^

ATGEOMETRY3 Computes the 3-D position of all elements

POSDATA=ATGEOMETRY3(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 3 fields:
           x, y, z

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

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

POSDATA=ATGEOMETRY3(...,'Vangle',h_angle)
       Set the initial vertical trajectory angle

See also: ATGEOMETRY

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function  posdata = atgeometry3(ring,varargin)
0002 %ATGEOMETRY3 Computes the 3-D position of all elements
0003 %
0004 %POSDATA=ATGEOMETRY3(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 3 fields:
0012 %           x, y, z
0013 %
0014 %POSDATA=ATGEOMETRY3(RING,REFPTS,OFFSET)
0015 %       Start at x=offset(1), y=offset(2), z=offset(3)
0016 %       a scalar offset value is equivalent to [0 OFFSET 0]
0017 %
0018 %POSDATA=ATGEOMETRY3(...,'Hangle',h_angle)
0019 %       Set the initial horizontal trajectory angle
0020 %
0021 %POSDATA=ATGEOMETRY3(...,'Vangle',h_angle)
0022 %       Set the initial vertical trajectory angle
0023 %
0024 %See also: ATGEOMETRY
0025 
0026 [hangle,args]=getoption(varargin,'Hangle',0);
0027 [vangle,args]=getoption(args,'Vangle',0);
0028 [refpts,offset]=parseargs({1:length(ring)+1,[0 0 0]},args);
0029 conv=eye(3);
0030 hkick(hangle);
0031 vkick(vangle);
0032 xyzc=[0;0;0];
0033 if isscalar(offset)
0034     xyzc(2)=offset;
0035 else
0036     xyzc(1:length(offset))=offset';
0037 end
0038 [xx,yy,zz]=cellfun(@incr,[{struct()};ring]);    % Add a dummy element to get the origin
0039 posdata=struct('x',num2cell(xx(refpts)),'y',num2cell(yy(refpts)),...
0040     'z',num2cell(zz(refpts)));
0041 
0042     function varargout=incr(elem)
0043         if isfield(elem,'R1')
0044             rots(elem.R1);
0045         end
0046         if isfield(elem,'BendingAngle')
0047             ang=0.5*elem.BendingAngle;
0048             L=elem.Length/ang*sin(ang);
0049             hkick(-ang);
0050             xyzc=xyzc+conv*[L;0;0];
0051             hkick(-ang);
0052         elseif isfield(elem,'Length')
0053             L=elem.Length;
0054             xyzc=xyzc+conv*[L;0;0];
0055         end
0056         if isfield(elem,'R2')
0057             rots(elem.R2);
0058         end
0059         varargout=num2cell(xyzc');
0060     end
0061     function rots(R)
0062         cns=R(1,1);
0063         sns=R(1,3);
0064         conv=conv*[1 0 0;0 cns -sns;0 sns cns];
0065     end
0066     function hkick(ang)
0067         cns=cos(ang);
0068         sns=sin(ang);
0069         conv=conv*[cns -sns 0;sns cns 0;0 0 1];
0070     end
0071     function vkick(ang)
0072         cns=cos(ang);
0073         sns=sin(ang);
0074         conv=conv*[cns 0 -sns;0 1 0;sns 0 cns];
0075     end
0076 end
0077

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