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