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
   angles3d, cart2pol, cart2sph2

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
0021 %   angles3d, cart2pol, cart2sph2
0022 %
0023 
0024 % ------
0025 % Author: David Legland
0026 % E-mail: david.legland@inrae.fr
0027 % Created: 2006-03-23
0028 % Copyright 2006-2024 INRA - CEPIA Nantes - MIAJ (Jouy-en-Josas)
0029 
0030 % process input parameters
0031 if isscalar(varargin)
0032     var = varargin{1};
0033     x = var(:,1);
0034     y = var(:,2);
0035     z = var(:,3);
0036 elseif length(varargin)==3
0037     x = varargin{1};
0038     y = varargin{2};
0039     z = varargin{3};
0040 end
0041 
0042 % convert coordinates
0043 dim = size(x);
0044 theta = reshape(mod(atan2(y(:), x(:))+2*pi, 2*pi), dim);
0045 r = reshape(sqrt(x(:).*x(:) + y(:).*y(:)), dim);
0046 
0047 % process output parameters
0048 if nargout==0 ||nargout==1
0049     if length(dim)>2 || dim(2)>1
0050         varargout{1} = {theta r z};
0051     else
0052         varargout{1} = [theta r z];
0053     end
0054 elseif nargout==3
0055     varargout{1} = theta;
0056     varargout{2} = r;
0057     varargout{3} = z;
0058 end

Generated on Thu 21-Nov-2024 11:30:22 by m2html © 2003-2022