comparison scripts/general/pol2cart.m @ 17585:36b9fa789d8e

Overhaul polar, spherical, cartesian conversion routiens when nargout == 1. * scripts/general/cart2pol.m: Use @var{P} (capital) in docstring. Initialize z to []. Return 3-column matrix when nargout == 1. Modify %!test to check this behavior. * scripts/general/cart2sph.m: Use @var{C} (capital) in docstring. Return 3-column matrix when nargout == 1. Modify %!test to check this behavior. scripts/general/pol2cart.m: Use @var{P} (capital) in docstring. Use 'C' in %!test to refer to single Cartesian matrix of coordinates. scripts/general/sph2cart.m: Use @var{C} (capital) in docstring. Return 3-column matrix when nargout == 1. Modify %!test to check this behavior.
author Rik <rik@octave.org>
date Sun, 06 Oct 2013 21:01:10 -0700
parents 6278085742b7
children d63878346099
comparison
equal deleted inserted replaced
17584:6278085742b7 17585:36b9fa789d8e
17 ## <http://www.gnu.org/licenses/>. 17 ## <http://www.gnu.org/licenses/>.
18 18
19 ## -*- texinfo -*- 19 ## -*- texinfo -*-
20 ## @deftypefn {Function File} {[@var{x}, @var{y}] =} pol2cart (@var{theta}, @var{r}) 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}) 21 ## @deftypefnx {Function File} {[@var{x}, @var{y}, @var{z}] =} pol2cart (@var{theta}, @var{r}, @var{z})
22 ## @deftypefnx {Function File} {[@var{x}, @var{y}] =} pol2cart (@var{p}) 22 ## @deftypefnx {Function File} {[@var{x}, @var{y}] =} pol2cart (@var{P})
23 ## @deftypefnx {Function File} {[@var{x}, @var{y}, @var{z}] =} pol2cart (@var{p}) 23 ## @deftypefnx {Function File} {[@var{x}, @var{y}, @var{z}] =} pol2cart (@var{P})
24 ## @deftypefnx {Function File} {@var{C} =} pol2cart (@dots{}) 24 ## @deftypefnx {Function File} {@var{C} =} pol2cart (@dots{})
25 ## Transform polar or cylindrical to Cartesian coordinates. 25 ## Transform polar or cylindrical to Cartesian coordinates.
26 ## 26 ##
27 ## @var{theta}, @var{r}, (and @var{z}) must be the same shape, or scalar. 27 ## @var{theta}, @var{r}, (and @var{z}) must be the same shape, or scalar.
28 ## @var{theta} describes the angle relative to the positive x-axis. 28 ## @var{theta} describes the angle relative to the positive x-axis.
29 ## @var{r} is the distance to the z-axis (0, 0, z). 29 ## @var{r} is the distance to the z-axis (0, 0, z).
30 ## If called with a single matrix argument then each row of @var{p} 30 ## If called with a single matrix argument then each row of @var{P}
31 ## represents the polar/(cylindrical) coordinate (@var{theta}, @var{r} (, 31 ## represents the polar/(cylindrical) coordinate (@var{theta}, @var{r} (,
32 ## @var{z})). 32 ## @var{z})).
33 ## 33 ##
34 ## If only a single return argument is requested then return a matrix 34 ## If only a single return argument is requested then return a matrix
35 ## @var{C} where each row represents one Cartesian coordinate 35 ## @var{C} where each row represents one Cartesian coordinate
88 %! assert (y, [0, 1, 0], sqrt (eps)); 88 %! assert (y, [0, 1, 0], sqrt (eps));
89 89
90 %!test 90 %!test
91 %! t = [0, 1, 1] * pi/4; 91 %! t = [0, 1, 1] * pi/4;
92 %! r = sqrt (2) * [0, 1, 2]; 92 %! r = sqrt (2) * [0, 1, 2];
93 %! cart = pol2cart (t, r); 93 %! C = pol2cart (t, r);
94 %! assert (cart(:,1), [0; 1; 2], sqrt (eps)); 94 %! assert (C(:,1), [0; 1; 2], sqrt (eps));
95 %! assert (cart(:,2), [0; 1; 2], sqrt (eps)); 95 %! assert (C(:,2), [0; 1; 2], sqrt (eps));
96 96
97 %!test 97 %!test
98 %! t = [0, 1, 1] * pi/4; 98 %! t = [0, 1, 1] * pi/4;
99 %! r = sqrt (2) * [0, 1, 2]; 99 %! r = sqrt (2) * [0, 1, 2];
100 %! z = [0, 1, 2]; 100 %! z = [0, 1, 2];