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{x}, @var{y}] =} pol2cart (@var{theta}, @var{r}) |
|
22 ## @deftypefnx {Function File} {[@var{x}, @var{y}, @var{z}] =} pol2cart (@var{theta}, @var{r}, @var{z}) |
3803
|
23 ## Transform polar or cylindrical to cartesian coordinates. |
|
24 ## @var{theta}, @var{r} (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). |
5642
|
27 ## @seealso{cart2pol, cart2sph, sph2cart} |
3803
|
28 ## @end deftypefn |
|
29 |
|
30 ## Author: Kai Habel <kai.habel@gmx.de> |
|
31 ## Adapted-by: jwe |
|
32 |
|
33 function [X, Y, Z] = pol2cart (Theta, R, Z) |
|
34 |
|
35 if (nargin < 2 || nargin > 3) |
|
36 error ("pol2cart: number of arguments must be 2 or 3"); |
|
37 endif |
|
38 |
|
39 if (nargin == 2 && nargout > 2) |
|
40 error ("pol2cart: number of output arguments must not be greater than number of input arguments"); |
|
41 endif |
|
42 |
4030
|
43 if ((! (ismatrix (Theta) && ismatrix (R))) |
6898
|
44 || ((! size_equal (Theta, R)) && (! isscalar (Theta)) && (! isscalar (R))) |
|
45 || (nargin == 3 |
|
46 && ((! ismatrix(Z)) |
|
47 || ( (! isscalar(Z)) |
|
48 && ( (!(isscalar(R) || size_equal (R, Z))) || (!(isscalar(Theta) || size_equal (Theta, Z))) ) |
|
49 ) |
|
50 ) |
|
51 ) |
|
52 ) |
|
53 error ("pol2cart: arguments must be matrices of same size or scalar"); |
3803
|
54 endif |
|
55 |
|
56 X = cos (Theta) .* R; |
|
57 Y = sin (Theta) .* R; |
|
58 |
|
59 endfunction |