annotate scripts/general/cart2sph.m @ 6786:bb5958d3510a

[project @ 2007-07-23 17:28:15 by jwe]
author jwe
date Mon, 23 Jul 2007 17:28:15 +0000
parents 5ce6ecc1377b
children 93c65f2a5668
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3803
63c75bc3db82 [project @ 2001-02-28 08:24:40 by jwe]
jwe
parents:
diff changeset
1 ## Copyright (C) 2000 Kai Habel
63c75bc3db82 [project @ 2001-02-28 08:24:40 by jwe]
jwe
parents:
diff changeset
2 ##
63c75bc3db82 [project @ 2001-02-28 08:24:40 by jwe]
jwe
parents:
diff changeset
3 ## This file is part of Octave.
63c75bc3db82 [project @ 2001-02-28 08:24:40 by jwe]
jwe
parents:
diff changeset
4 ##
63c75bc3db82 [project @ 2001-02-28 08:24:40 by jwe]
jwe
parents:
diff changeset
5 ## Octave is free software; you can redistribute it and/or modify it
63c75bc3db82 [project @ 2001-02-28 08:24:40 by jwe]
jwe
parents:
diff changeset
6 ## under the terms of the GNU General Public License as published by
63c75bc3db82 [project @ 2001-02-28 08:24:40 by jwe]
jwe
parents:
diff changeset
7 ## the Free Software Foundation; either version 2, or (at your option)
63c75bc3db82 [project @ 2001-02-28 08:24:40 by jwe]
jwe
parents:
diff changeset
8 ## any later version.
63c75bc3db82 [project @ 2001-02-28 08:24:40 by jwe]
jwe
parents:
diff changeset
9 ##
63c75bc3db82 [project @ 2001-02-28 08:24:40 by jwe]
jwe
parents:
diff changeset
10 ## Octave is distributed in the hope that it will be useful, but
63c75bc3db82 [project @ 2001-02-28 08:24:40 by jwe]
jwe
parents:
diff changeset
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of
63c75bc3db82 [project @ 2001-02-28 08:24:40 by jwe]
jwe
parents:
diff changeset
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
63c75bc3db82 [project @ 2001-02-28 08:24:40 by jwe]
jwe
parents:
diff changeset
13 ## General Public License for more details.
63c75bc3db82 [project @ 2001-02-28 08:24:40 by jwe]
jwe
parents:
diff changeset
14 ##
63c75bc3db82 [project @ 2001-02-28 08:24:40 by jwe]
jwe
parents:
diff changeset
15 ## You should have received a copy of the GNU General Public License
63c75bc3db82 [project @ 2001-02-28 08:24:40 by jwe]
jwe
parents:
diff changeset
16 ## along with Octave; see the file COPYING. If not, write to the Free
5307
4c8a2e4e0717 [project @ 2005-04-26 19:24:27 by jwe]
jwe
parents: 5053
diff changeset
17 ## Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
4c8a2e4e0717 [project @ 2005-04-26 19:24:27 by jwe]
jwe
parents: 5053
diff changeset
18 ## 02110-1301, USA.
3803
63c75bc3db82 [project @ 2001-02-28 08:24:40 by jwe]
jwe
parents:
diff changeset
19
63c75bc3db82 [project @ 2001-02-28 08:24:40 by jwe]
jwe
parents:
diff changeset
20 ## -*- texinfo -*-
5610
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents: 5307
diff changeset
21 ## @deftypefn {Function File} {[@var{theta}, @var{phi}, @var{r}] =} cart2sph (@var{x}, @var{y}, @var{z})
3803
63c75bc3db82 [project @ 2001-02-28 08:24:40 by jwe]
jwe
parents:
diff changeset
22 ## Transform cartesian to spherical coordinates.
63c75bc3db82 [project @ 2001-02-28 08:24:40 by jwe]
jwe
parents:
diff changeset
23 ## @var{x}, @var{y} and @var{z} must be of same shape.
63c75bc3db82 [project @ 2001-02-28 08:24:40 by jwe]
jwe
parents:
diff changeset
24 ## @var{theta} describes the angle relative to the x - axis.
63c75bc3db82 [project @ 2001-02-28 08:24:40 by jwe]
jwe
parents:
diff changeset
25 ## @var{phi} is the angle relative to the xy - plane.
63c75bc3db82 [project @ 2001-02-28 08:24:40 by jwe]
jwe
parents:
diff changeset
26 ## @var{r} is the distance to the origin (0, 0, 0).
5642
2618a0750ae6 [project @ 2006-03-06 21:26:48 by jwe]
jwe
parents: 5610
diff changeset
27 ## @seealso{pol2cart, cart2pol, sph2cart}
3803
63c75bc3db82 [project @ 2001-02-28 08:24:40 by jwe]
jwe
parents:
diff changeset
28 ## @end deftypefn
63c75bc3db82 [project @ 2001-02-28 08:24:40 by jwe]
jwe
parents:
diff changeset
29
63c75bc3db82 [project @ 2001-02-28 08:24:40 by jwe]
jwe
parents:
diff changeset
30 ## Author: Kai Habel <kai.habel@gmx.de>
63c75bc3db82 [project @ 2001-02-28 08:24:40 by jwe]
jwe
parents:
diff changeset
31 ## Adapted-by: jwe
63c75bc3db82 [project @ 2001-02-28 08:24:40 by jwe]
jwe
parents:
diff changeset
32
63c75bc3db82 [project @ 2001-02-28 08:24:40 by jwe]
jwe
parents:
diff changeset
33 function [Theta, Phi, R] = cart2sph (X, Y, Z)
63c75bc3db82 [project @ 2001-02-28 08:24:40 by jwe]
jwe
parents:
diff changeset
34
63c75bc3db82 [project @ 2001-02-28 08:24:40 by jwe]
jwe
parents:
diff changeset
35 if (nargin != 3)
6046
34f96dd5441b [project @ 2006-10-10 16:10:25 by jwe]
jwe
parents: 5642
diff changeset
36 print_usage ();
3803
63c75bc3db82 [project @ 2001-02-28 08:24:40 by jwe]
jwe
parents:
diff changeset
37 endif
63c75bc3db82 [project @ 2001-02-28 08:24:40 by jwe]
jwe
parents:
diff changeset
38
6786
bb5958d3510a [project @ 2007-07-23 17:28:15 by jwe]
jwe
parents: 6785
diff changeset
39 if (! (ismatrix (X) && ismatrix (Y) && ismatrix (Z))
bb5958d3510a [project @ 2007-07-23 17:28:15 by jwe]
jwe
parents: 6785
diff changeset
40 || ! size_equal (X, Y)
bb5958d3510a [project @ 2007-07-23 17:28:15 by jwe]
jwe
parents: 6785
diff changeset
41 || ! size_equal (X, Z))
3803
63c75bc3db82 [project @ 2001-02-28 08:24:40 by jwe]
jwe
parents:
diff changeset
42 error ("cart2sph: arguments must be matrices of same size");
63c75bc3db82 [project @ 2001-02-28 08:24:40 by jwe]
jwe
parents:
diff changeset
43 endif
63c75bc3db82 [project @ 2001-02-28 08:24:40 by jwe]
jwe
parents:
diff changeset
44
63c75bc3db82 [project @ 2001-02-28 08:24:40 by jwe]
jwe
parents:
diff changeset
45 Theta = atan2 (Y, X);
63c75bc3db82 [project @ 2001-02-28 08:24:40 by jwe]
jwe
parents:
diff changeset
46 Phi = atan2 (Z, sqrt (X .^ 2 + Y .^ 2));
63c75bc3db82 [project @ 2001-02-28 08:24:40 by jwe]
jwe
parents:
diff changeset
47 R = sqrt (X .^ 2 + Y .^ 2 + Z .^ 2);
63c75bc3db82 [project @ 2001-02-28 08:24:40 by jwe]
jwe
parents:
diff changeset
48
63c75bc3db82 [project @ 2001-02-28 08:24:40 by jwe]
jwe
parents:
diff changeset
49 endfunction