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}, @var{z}] =} sph2cart (@var{theta}, @var{phi}, @var{r}) |
3803
|
21 ## Transform spherical to cartesian coordinates. |
|
22 ## @var{x}, @var{y} and @var{z} must be of same shape. |
|
23 ## @var{theta} describes the angle relative to the x-axis. |
|
24 ## @var{phi} is the angle relative to the xy-plane. |
|
25 ## @var{r} is the distance to the origin (0, 0, 0). |
5642
|
26 ## @seealso{pol2cart, cart2pol, cart2sph} |
3803
|
27 ## @end deftypefn |
|
28 |
|
29 ## Author: Kai Habel <kai.habel@gmx.de> |
|
30 ## Adapted-by: jwe |
|
31 |
|
32 function [X, Y, Z] = sph2cart (Theta, Phi, R) |
|
33 |
|
34 if (nargin != 3) |
6046
|
35 print_usage (); |
3803
|
36 endif |
|
37 |
4030
|
38 if ((! (ismatrix (Theta) && ismatrix (Phi) && ismatrix (R))) |
6157
|
39 || (! size_equal (Theta, Phi)) |
|
40 || (! size_equal (Theta, R))) |
3803
|
41 error ("sph2cart: arguments must be matrices of same size"); |
|
42 endif |
|
43 |
|
44 X = R .* cos (Phi) .* cos (Theta); |
|
45 Y = R .* cos (Phi) .* sin (Theta); |
|
46 Z = R .* sin (Phi); |
|
47 |
|
48 endfunction |