Home > matGeom > geom3d > cart2cyl.m

cart2cyl

PURPOSE ^

CART2CYL Convert cartesian to cylindrical coordinates.

SYNOPSIS ^

function varargout = cart2cyl(varargin)

DESCRIPTION ^

CART2CYL  Convert cartesian to cylindrical coordinates.

   CYL = cart2cyl(POINT)
   convert the 3D cartesian coordinates of points POINT (given by [X Y Z]
   where X, Y, Z have the same size) into cylindrical coordinates CYL,
   given by [THETA R Z]. 
   THETA is the arctangent of the ratio Y/X (between 0 and 2*PI)
   R     can be computed using sqrt(X^2+Y^2)
   Z     keeps the same value.
   The size of THETA, and R is the same as the size of X, Y and Z.

   CYL = cart2cyl(X, Y, Z)
   provides coordinates as 3 different parameters

   Example
   cart2cyl([-1 0 2])
   gives : 4.7124    1.0000     2.0000

   See also agles3d, cart2pol, cart2sph2


 ------
 Author: David Legland
 e-mail: david.legland@jouy.inra.fr
 Created: 2006-03-23
 Copyright 2006 INRA - CEPIA Nantes - MIAJ (Jouy-en-Josas).

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function varargout = cart2cyl(varargin)
0002 %CART2CYL  Convert cartesian to cylindrical coordinates.
0003 %
0004 %   CYL = cart2cyl(POINT)
0005 %   convert the 3D cartesian coordinates of points POINT (given by [X Y Z]
0006 %   where X, Y, Z have the same size) into cylindrical coordinates CYL,
0007 %   given by [THETA R Z].
0008 %   THETA is the arctangent of the ratio Y/X (between 0 and 2*PI)
0009 %   R     can be computed using sqrt(X^2+Y^2)
0010 %   Z     keeps the same value.
0011 %   The size of THETA, and R is the same as the size of X, Y and Z.
0012 %
0013 %   CYL = cart2cyl(X, Y, Z)
0014 %   provides coordinates as 3 different parameters
0015 %
0016 %   Example
0017 %   cart2cyl([-1 0 2])
0018 %   gives : 4.7124    1.0000     2.0000
0019 %
0020 %   See also agles3d, cart2pol, cart2sph2
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     x = var(:,1);
0033     y = var(:,2);
0034     z = var(:,3);
0035 elseif length(varargin)==3
0036     x = varargin{1};
0037     y = varargin{2};
0038     z = varargin{3};
0039 end
0040 
0041 % convert coordinates
0042 dim = size(x);
0043 theta = reshape(mod(atan2(y(:), x(:))+2*pi, 2*pi), dim);
0044 r = reshape(sqrt(x(:).*x(:) + y(:).*y(:)), dim);
0045 
0046 % process output parameters
0047 if nargout==0 ||nargout==1
0048     if length(dim)>2 || dim(2)>1
0049         varargout{1} = {theta r z};
0050     else
0051         varargout{1} = [theta r z];
0052     end
0053 elseif nargout==3
0054     varargout{1} = theta;
0055     varargout{2} = r;
0056     varargout{3} = z;
0057 end

Generated on Wed 16-Feb-2022 15:10:47 by m2html © 2003-2019