scripts/general/sph2cart.m
| changeset 10289: |
4b124317dc38 |
| parent: | eb63fbe60fab |
| author: |
John W. Eaton <jwe@octave.org> |
| date: |
Tue Feb 09 20:58:55 2010 -0500 (49 minutes ago) |
| permissions: |
-rw-r--r-- |
| description: |
base_properties::set_children: account for hidden children |
1## Copyright (C) 2000, 2001, 2002, 2004, 2005, 2006, 2007, 2009 Kai Habel
3## This file is part of Octave.
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 3 of the License, or (at
8## your option) any later version.
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.
15## You should have received a copy of the GNU General Public License
16## along with Octave; see the file COPYING. If not, see
17## <http://www.gnu.org/licenses/>.
20## @deftypefn {Function File} {[@var{x}, @var{y}, @var{z}] =} sph2cart (@var{theta}, @var{phi}, @var{r})
21## Transform spherical to Cartesian coordinates.
22## @var{x}, @var{y} and @var{z} must be the same shape, or scalar.
23## @var{theta} describes the angle relative to the positive 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).
26## @seealso{pol2cart, cart2pol, cart2sph}
29## Author: Kai Habel <kai.habel@gmx.de>
32function [x, y, z] = sph2cart (theta, phi, r)
38 if ((ismatrix (theta) && ismatrix (phi) && ismatrix (r))
39 && (size_equal (theta, phi) || isscalar (theta) || isscalar (phi))
40 && (size_equal (theta, r) || isscalar (theta) || isscalar (r))
41 && (size_equal (phi, r) || isscalar (phi) || isscalar (r)))
43 x = r .* cos (phi) .* cos (theta);
44 y = r .* cos (phi) .* sin (theta);
48 error ("sph2cart: arguments must be matrices of same size, or scalar");
57%! [x, y, z] = sph2cart (t, p, r);
59%! assert (y, [0, 0, 0]);
60%! assert (z, [0, 0, 0]);
66%! [x, y, z] = sph2cart (t, p, r);
68%! assert (y, [0, 0, 0]);
69%! assert (z, [0, 0, 0]);
75%! [x, y, z] = sph2cart (t, p, r);
77%! assert (y, [0, 0, 0]);
78%! assert (z, [0, 0, 0]);
84%! [x, y, z] = sph2cart (t, p, r);
85%! assert (x, [1, 0, -1], eps);
86%! assert (y, [0, 1, 0], eps);
87%! assert (z, [0, 0, 0], eps);