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 |
7016
|
7 ## the Free Software Foundation; either version 3 of the License, or (at |
|
8 ## your option) any later version. |
3803
|
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 |
7016
|
16 ## along with Octave; see the file COPYING. If not, see |
|
17 ## <http://www.gnu.org/licenses/>. |
3803
|
18 |
|
19 ## -*- texinfo -*- |
5610
|
20 ## @deftypefn {Function File} {[@var{theta}, @var{r}] =} cart2pol (@var{x}, @var{y}) |
|
21 ## @deftypefnx {Function File} {[@var{theta}, @var{r}, @var{z}] =} cart2pol (@var{x}, @var{y}, @var{z}) |
3803
|
22 ## Transform cartesian to polar or cylindrical coordinates. |
|
23 ## @var{x}, @var{y} (and @var{z}) must be of same shape. |
|
24 ## @var{theta} describes the angle relative to the x - axis. |
|
25 ## @var{r} is the distance to the z - axis (0, 0, z). |
5642
|
26 ## @seealso{pol2cart, cart2sph, sph2cart} |
3803
|
27 ## @end deftypefn |
|
28 |
|
29 ## Author: Kai Habel <kai.habel@gmx.de> |
|
30 ## Adapted-by: jwe |
|
31 |
|
32 function [Theta, R, Z] = cart2pol (X, Y, Z) |
|
33 |
|
34 if (nargin < 2 || nargin > 3) |
|
35 error ("cart2pol: number of arguments must be 2 or 3"); |
|
36 endif |
|
37 |
|
38 if (nargin == 2 && nargout > 2) |
|
39 error ("cart2pol: number of output arguments must not be greater than number of input arguments"); |
|
40 endif |
|
41 |
6786
|
42 if (! (ismatrix (X) && ismatrix (Y)) |
|
43 || ! size_equal (X, Y) |
|
44 || (nargin == 3 && ! (size_equal (X, Z) && ismatrix (Z)))) |
3803
|
45 error ("cart2pol: arguments must be matrices of same size"); |
|
46 endif |
|
47 |
|
48 Theta = atan2 (Y, X); |
|
49 R = sqrt (X .^ 2 + Y .^ 2); |
|
50 |
|
51 endfunction |