scripts/general/pol2cart.m
| changeset 10289: |
4b124317dc38 |
| parent: | eb63fbe60fab |
| author: |
John W. Eaton <jwe@octave.org> |
| date: |
Tue Feb 09 20:58:55 2010 -0500 (44 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}] =} pol2cart (@var{theta}, @var{r})
21## @deftypefnx {Function File} {[@var{x}, @var{y}, @var{z}] =} pol2cart (@var{theta}, @var{r}, @var{z})
22## Transform polar or cylindrical to Cartesian coordinates.
23## @var{theta}, @var{r} (and @var{z}) must be the same shape, or scalar.
24## @var{theta} describes the angle relative to the positive x-axis.
25## @var{r} is the distance to the z-axis (0, 0, z).
26## @seealso{cart2pol, cart2sph, sph2cart}
29## Author: Kai Habel <kai.habel@gmx.de>
32function [x, y, z] = pol2cart (theta, r, z)
34 if (nargin < 2 || nargin > 3)
35 error ("pol2cart: number of arguments must be 2 or 3");
38 if (nargin == 2 && nargout > 2)
39 error ("pol2cart: number of output arguments must not be greater than number of input arguments");
42 if ((ismatrix (theta) && ismatrix (r) && (nargin == 2 || ismatrix (z)))
43 && (size_equal (theta, r) || isscalar (theta) || isscalar (r))
44 && (nargin == 2 || size_equal (theta, z) || isscalar (theta) || isscalar (z))
45 && (nargin == 2 || size_equal (r, z) || isscalar (r) || isscalar (z)))
51 error ("pol2cart: arguments must be matrices of same size, or scalar");
57%! t = [0, 0.5, 1] * pi;
59%! [x, y] = pol2cart (t, r);
60%! assert (x, [1, 0, -1], sqrt(eps));
61%! assert (y, [0, 1, 0], sqrt(eps));
64%! t = [0, 1, 1] * pi/4;
65%! r = sqrt(2) * [0, 1, 2];
66%! [x, y] = pol2cart (t, r);
67%! assert (x, [0, 1, 2], sqrt(eps));
68%! assert (y, [0, 1, 2], sqrt(eps));
71%! t = [0, 1, 1] * pi/4;
72%! r = sqrt(2) * [0, 1, 2];
74%! [x, y, z2] = pol2cart (t, r, z);
75%! assert (x, [0, 1, 2], sqrt(eps));
76%! assert (y, [0, 1, 2], sqrt(eps));
83%! [x, y, z2] = pol2cart (t, r, z);
84%! assert (x, [0, 1, 2], sqrt(eps));
85%! assert (y, [0, 0, 0], sqrt(eps));
92%! [x, y, z2] = pol2cart (t, r, z);
93%! assert (x, [1, 1, 1] / sqrt(2), eps);
94%! assert (y, [1, 1, 1] / sqrt(2), eps);
101%! [x, y, z2] = pol2cart (t, r, z);
102%! assert (x, [1, 2, 3], eps);
103%! assert (y, [0, 0, 0] / sqrt(2), eps);