3803
|
1 ## Copyright (C) 2000 Kai Habel |
|
2 ## |
|
3 ## This file is part of Octave. |
|
4 ## |
|
5 ## Octave is free software; you can redistribute it and/or modify it |
|
6 ## under the terms of the GNU General Public License as published by |
|
7 ## the Free Software Foundation; either version 2, or (at your option) |
|
8 ## any later version. |
|
9 ## |
|
10 ## Octave is distributed in the hope that it will be useful, but |
|
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
13 ## General Public License for more details. |
|
14 ## |
|
15 ## You should have received a copy of the GNU General Public License |
|
16 ## along with Octave; see the file COPYING. If not, write to the Free |
5307
|
17 ## Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
|
18 ## 02110-1301, USA. |
3803
|
19 |
|
20 ## -*- texinfo -*- |
5610
|
21 ## @deftypefn {Function File} {[@var{theta}, @var{r}] =} cart2pol (@var{x}, @var{y}) |
|
22 ## @deftypefnx {Function File} {[@var{theta}, @var{r}, @var{z}] =} cart2pol (@var{x}, @var{y}, @var{z}) |
3803
|
23 ## Transform cartesian to polar or cylindrical coordinates. |
|
24 ## @var{x}, @var{y} (and @var{z}) must be of same shape. |
|
25 ## @var{theta} describes the angle relative to the x - axis. |
|
26 ## @var{r} is the distance to the z - axis (0, 0, z). |
|
27 ## @end deftypefn |
5053
|
28 ## |
3803
|
29 ## @seealso{pol2cart, cart2sph, sph2cart} |
|
30 |
|
31 ## Author: Kai Habel <kai.habel@gmx.de> |
|
32 ## Adapted-by: jwe |
|
33 |
|
34 function [Theta, R, Z] = cart2pol (X, Y, Z) |
|
35 |
|
36 if (nargin < 2 || nargin > 3) |
|
37 error ("cart2pol: number of arguments must be 2 or 3"); |
|
38 endif |
|
39 |
|
40 if (nargin == 2 && nargout > 2) |
|
41 error ("cart2pol: number of output arguments must not be greater than number of input arguments"); |
|
42 endif |
|
43 |
4030
|
44 if ((! (ismatrix (X) && ismatrix (Y))) |
3803
|
45 || (size (X) != size (Y)) |
4030
|
46 || (nargin == 3 && (! (size (X) == size (Z) && ismatrix (Z))))) |
3803
|
47 error ("cart2pol: arguments must be matrices of same size"); |
|
48 endif |
|
49 |
|
50 Theta = atan2 (Y, X); |
|
51 R = sqrt (X .^ 2 + Y .^ 2); |
|
52 |
|
53 endfunction |