CYL2CART Convert cylindrical to cartesian coordinates. CART = cyl2cart(CYL) convert the 3D cylindrical coordinates of points CYL (given by [THETA R Z] where THETA, R, and Z have the same size) into cartesian coordinates CART, given by [X Y Z]. The transforms is the following : X = R*cos(THETA); Y = R*sin(THETA); Z remains inchanged. CART = cyl2cart(THETA, R, Z) provides coordinates as 3 different parameters Example cyl2cart([-1 0 2]) gives : 4.7124 1.0000 2.0000 See also angles3d, cart2pol, cart2sph2, cart2cyl ------ Author: David Legland e-mail: david.legland@jouy.inra.fr Created: 2006-03-23 Copyright 2006 INRA - CEPIA Nantes - MIAJ (Jouy-en-Josas).
0001 function varargout = cyl2cart(varargin) 0002 %CYL2CART Convert cylindrical to cartesian coordinates. 0003 % 0004 % CART = cyl2cart(CYL) 0005 % convert the 3D cylindrical coordinates of points CYL (given by 0006 % [THETA R Z] where THETA, R, and Z have the same size) into cartesian 0007 % coordinates CART, given by [X Y Z]. 0008 % The transforms is the following : 0009 % X = R*cos(THETA); 0010 % Y = R*sin(THETA); 0011 % Z remains inchanged. 0012 % 0013 % CART = cyl2cart(THETA, R, Z) 0014 % provides coordinates as 3 different parameters 0015 % 0016 % Example 0017 % cyl2cart([-1 0 2]) 0018 % gives : 4.7124 1.0000 2.0000 0019 % 0020 % See also angles3d, cart2pol, cart2sph2, cart2cyl 0021 % 0022 % 0023 % ------ 0024 % Author: David Legland 0025 % e-mail: david.legland@jouy.inra.fr 0026 % Created: 2006-03-23 0027 % Copyright 2006 INRA - CEPIA Nantes - MIAJ (Jouy-en-Josas). 0028 0029 % process input parameters 0030 if length(varargin)==1 0031 var = varargin{1}; 0032 theta = var(:,1); 0033 r = var(:,2); 0034 z = var(:,3); 0035 elseif length(varargin)==3 0036 theta = varargin{1}; 0037 r = varargin{2}; 0038 z = varargin{3}; 0039 end 0040 0041 % convert coordinates 0042 dim = size(theta); 0043 x = reshape(r(:).*cos(theta(:)), dim); 0044 y = reshape(r(:).*sin(theta(:)), dim); 0045 0046 % process output parameters 0047 if nargout==0 ||nargout==1 0048 if length(dim)>2 || dim(2)>1 0049 varargout{1} = {x y z}; 0050 else 0051 varargout{1} = [x y z]; 0052 end 0053 elseif nargout==3 0054 varargout{1} = x; 0055 varargout{2} = y; 0056 varargout{3} = z; 0057 end