annotate scripts/general/sph2cart.m @ 28171:a23da76e0693

Matlab compatibility fixes for coordinate transform functions (bug #57794). * cart2pol.m, cart2sph.m, pol2cart.m, sph2cart.m: Modified to allow row or column vector inputs, remove full matrix single output argument option, and clarified coordinate definitions in help text. * lightangle.m, surfl.m: Fix existing instances where single output was used and a matrix was expected. * NEWS: Added coordinate transform changes to Matlab compatibility section.
author Nicholas R. Jankowski <jankowskin@asme.org>
date Sun, 16 Feb 2020 20:19:05 -0500
parents a4268efb7334
children e82484e1b2f6
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
27923
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
1 ########################################################################
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
2 ##
27919
1891570abac8 update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents: 27918
diff changeset
3 ## Copyright (C) 2000-2020 The Octave Project Developers
27918
b442ec6dda5c use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents: 27898
diff changeset
4 ##
27923
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
5 ## See the file COPYRIGHT.md in the top-level directory of this
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
6 ## distribution or <https://octave.org/copyright/>.
3803
63c75bc3db82 [project @ 2001-02-28 08:24:40 by jwe]
jwe
parents:
diff changeset
7 ##
63c75bc3db82 [project @ 2001-02-28 08:24:40 by jwe]
jwe
parents:
diff changeset
8 ## This file is part of Octave.
63c75bc3db82 [project @ 2001-02-28 08:24:40 by jwe]
jwe
parents:
diff changeset
9 ##
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 23220
diff changeset
10 ## Octave is free software: you can redistribute it and/or modify it
3803
63c75bc3db82 [project @ 2001-02-28 08:24:40 by jwe]
jwe
parents:
diff changeset
11 ## under the terms of the GNU General Public License as published by
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 23220
diff changeset
12 ## the Free Software Foundation, either version 3 of the License, or
22755
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22432
diff changeset
13 ## (at your option) any later version.
3803
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 ## 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
16 ## WITHOUT ANY WARRANTY; without even the implied warranty of
22755
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22432
diff changeset
17 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22432
diff changeset
18 ## GNU General Public License for more details.
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 ## You should have received a copy of the GNU General Public License
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6157
diff changeset
21 ## along with Octave; see the file COPYING. If not, see
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 23220
diff changeset
22 ## <https://www.gnu.org/licenses/>.
27923
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
23 ##
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
24 ########################################################################
3803
63c75bc3db82 [project @ 2001-02-28 08:24:40 by jwe]
jwe
parents:
diff changeset
25
63c75bc3db82 [project @ 2001-02-28 08:24:40 by jwe]
jwe
parents:
diff changeset
26 ## -*- texinfo -*-
20852
516bb87ea72e 2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents: 20158
diff changeset
27 ## @deftypefn {} {[@var{x}, @var{y}, @var{z}] =} sph2cart (@var{theta}, @var{phi}, @var{r})
516bb87ea72e 2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents: 20158
diff changeset
28 ## @deftypefnx {} {[@var{x}, @var{y}, @var{z}] =} sph2cart (@var{S})
20158
7503499a252b doc: Update docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19697
diff changeset
29 ## Transform spherical coordinates to Cartesian coordinates.
7503499a252b doc: Update docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19697
diff changeset
30 ##
7503499a252b doc: Update docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19697
diff changeset
31 ## The inputs @var{theta}, @var{phi}, and @var{r} must be the same shape, or
7503499a252b doc: Update docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19697
diff changeset
32 ## scalar. If called with a single matrix argument then each row of @var{S}
28171
a23da76e0693 Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents: 27978
diff changeset
33 ## must represent a spherical coordinate triplet (@var{theta}, @var{phi},
a23da76e0693 Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents: 27978
diff changeset
34 ## @var{r}).
10688
7357e37f34fa coordinate transforms: add option to operate on column matrix of coordinates.
Rik <octave@nomad.inbox5.com>
parents: 10687
diff changeset
35 ##
28171
a23da76e0693 Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents: 27978
diff changeset
36 ## The outputs @var{x}, @var{y}, @var{z} match the shape of the inputs. For a
a23da76e0693 Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents: 27978
diff changeset
37 ## matrix input @var{S} the outputs are column vectors with rows corresponding
a23da76e0693 Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents: 27978
diff changeset
38 ## to the rows of the input matrix.
20158
7503499a252b doc: Update docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19697
diff changeset
39 ##
28171
a23da76e0693 Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents: 27978
diff changeset
40 ## @var{theta} describes the azimuth angle relative to the positive x-axis
a23da76e0693 Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents: 27978
diff changeset
41 ## measured in the xy-plane.
a23da76e0693 Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents: 27978
diff changeset
42 ##
a23da76e0693 Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents: 27978
diff changeset
43 ## @var{phi} is the elevation angle measured relative to the xy-plane.
20158
7503499a252b doc: Update docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19697
diff changeset
44 ##
10687
a8ce6bdecce5 Improve documentation strings.
Rik <octave@nomad.inbox5.com>
parents: 9168
diff changeset
45 ## @var{r} is the distance to the origin @w{(0, 0, 0)}.
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
46 ##
28171
a23da76e0693 Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents: 27978
diff changeset
47 ## The coordinate transformation is computed using:
a23da76e0693 Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents: 27978
diff changeset
48 ##
a23da76e0693 Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents: 27978
diff changeset
49 ## @tex
a23da76e0693 Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents: 27978
diff changeset
50 ## $$ x = r \cos \phi \cos \theta $$
a23da76e0693 Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents: 27978
diff changeset
51 ## $$ y = r \cos \phi \sin \theta $$
a23da76e0693 Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents: 27978
diff changeset
52 ## $$ z = r \sin \phi $$
a23da76e0693 Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents: 27978
diff changeset
53 ## @end tex
a23da76e0693 Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents: 27978
diff changeset
54 ## @ifnottex
a23da76e0693 Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents: 27978
diff changeset
55 ##
a23da76e0693 Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents: 27978
diff changeset
56 ## @example
a23da76e0693 Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents: 27978
diff changeset
57 ## @var{x} = r * cos (@var{phi}) * cos (@var{theta})
a23da76e0693 Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents: 27978
diff changeset
58 ## @var{y} = r * cos (@var{phi}) * sin (@var{theta})
a23da76e0693 Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents: 27978
diff changeset
59 ## @var{z} = r * sin (@var{phi})
a23da76e0693 Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents: 27978
diff changeset
60 ## @end example
a23da76e0693 Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents: 27978
diff changeset
61 ##
a23da76e0693 Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents: 27978
diff changeset
62 ## @end ifnottex
a23da76e0693 Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents: 27978
diff changeset
63 ## @c FIXME: Remove this note in Octave 9.1 (two releases after 7.1).
a23da76e0693 Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents: 27978
diff changeset
64 ## Note: For @sc{matlab} compatibility, this function no longer returns a full
a23da76e0693 Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents: 27978
diff changeset
65 ## coordinate matrix when called with a single return argument.
10688
7357e37f34fa coordinate transforms: add option to operate on column matrix of coordinates.
Rik <octave@nomad.inbox5.com>
parents: 10687
diff changeset
66 ## @seealso{cart2sph, pol2cart, cart2pol}
3803
63c75bc3db82 [project @ 2001-02-28 08:24:40 by jwe]
jwe
parents:
diff changeset
67 ## @end deftypefn
63c75bc3db82 [project @ 2001-02-28 08:24:40 by jwe]
jwe
parents:
diff changeset
68
8533
fb1b87ea4af9 Permit scalars when transforming coordinates.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
69 function [x, y, z] = sph2cart (theta, phi, r)
3803
63c75bc3db82 [project @ 2001-02-28 08:24:40 by jwe]
jwe
parents:
diff changeset
70
10688
7357e37f34fa coordinate transforms: add option to operate on column matrix of coordinates.
Rik <octave@nomad.inbox5.com>
parents: 10687
diff changeset
71 if (nargin != 1 && nargin != 3)
6046
34f96dd5441b [project @ 2006-10-10 16:10:25 by jwe]
jwe
parents: 5642
diff changeset
72 print_usage ();
3803
63c75bc3db82 [project @ 2001-02-28 08:24:40 by jwe]
jwe
parents:
diff changeset
73 endif
63c75bc3db82 [project @ 2001-02-28 08:24:40 by jwe]
jwe
parents:
diff changeset
74
10688
7357e37f34fa coordinate transforms: add option to operate on column matrix of coordinates.
Rik <octave@nomad.inbox5.com>
parents: 10687
diff changeset
75 if (nargin == 1)
28171
a23da76e0693 Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents: 27978
diff changeset
76 if (! (isnumeric (theta) && ismatrix (theta)))
a23da76e0693 Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents: 27978
diff changeset
77 error ("sph2cart: matrix input must be a 2-D numeric array");
a23da76e0693 Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents: 27978
diff changeset
78 endif
a23da76e0693 Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents: 27978
diff changeset
79 if (columns (theta) != 3 && numel (theta) != 3)
a23da76e0693 Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents: 27978
diff changeset
80 error ("sph2cart: matrix input must be a 3-element vector or 3-column array");
10688
7357e37f34fa coordinate transforms: add option to operate on column matrix of coordinates.
Rik <octave@nomad.inbox5.com>
parents: 10687
diff changeset
81 endif
28171
a23da76e0693 Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents: 27978
diff changeset
82
a23da76e0693 Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents: 27978
diff changeset
83 if (numel (theta) == 3)
a23da76e0693 Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents: 27978
diff changeset
84 r = theta(3);
a23da76e0693 Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents: 27978
diff changeset
85 phi = theta(2);
a23da76e0693 Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents: 27978
diff changeset
86 theta = theta(1);
a23da76e0693 Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents: 27978
diff changeset
87 else
a23da76e0693 Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents: 27978
diff changeset
88 r = theta(:,3);
a23da76e0693 Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents: 27978
diff changeset
89 phi = theta(:,2);
a23da76e0693 Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents: 27978
diff changeset
90 theta = theta(:,1);
a23da76e0693 Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents: 27978
diff changeset
91 endif
a23da76e0693 Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents: 27978
diff changeset
92
21172
5f62b5dae8b1 Fix regression for coordinate transforms on 3-D arrays (partial fix bug #47036).
Colin Macdonald <cbm@m.fsf.org>
parents: 20158
diff changeset
93 else
28171
a23da76e0693 Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents: 27978
diff changeset
94 if (! (isnumeric (theta) && isnumeric (phi) && isnumeric (r)))
a23da76e0693 Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents: 27978
diff changeset
95 error ("sph2cart: THETA, PHI, R must be numeric arrays or scalars");
22432
1e88747417e6 Allow mixed scalar/array inputs to cart2pol, cart2sph, pol2cart, sph2cart (bug #48950).
Rik <rik@octave.org>
parents: 21178
diff changeset
96 endif
1e88747417e6 Allow mixed scalar/array inputs to cart2pol, cart2sph, pol2cart, sph2cart (bug #48950).
Rik <rik@octave.org>
parents: 21178
diff changeset
97 [err, theta, phi, r] = common_size (theta, phi, r);
1e88747417e6 Allow mixed scalar/array inputs to cart2pol, cart2sph, pol2cart, sph2cart (bug #48950).
Rik <rik@octave.org>
parents: 21178
diff changeset
98 if (err)
28171
a23da76e0693 Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents: 27978
diff changeset
99 error ("sph2cart: THETA, PHI, R must be the same size or scalars");
10688
7357e37f34fa coordinate transforms: add option to operate on column matrix of coordinates.
Rik <octave@nomad.inbox5.com>
parents: 10687
diff changeset
100 endif
7357e37f34fa coordinate transforms: add option to operate on column matrix of coordinates.
Rik <octave@nomad.inbox5.com>
parents: 10687
diff changeset
101 endif
8533
fb1b87ea4af9 Permit scalars when transforming coordinates.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
102
10688
7357e37f34fa coordinate transforms: add option to operate on column matrix of coordinates.
Rik <octave@nomad.inbox5.com>
parents: 10687
diff changeset
103 x = r .* cos (phi) .* cos (theta);
7357e37f34fa coordinate transforms: add option to operate on column matrix of coordinates.
Rik <octave@nomad.inbox5.com>
parents: 10687
diff changeset
104 y = r .* cos (phi) .* sin (theta);
7357e37f34fa coordinate transforms: add option to operate on column matrix of coordinates.
Rik <octave@nomad.inbox5.com>
parents: 10687
diff changeset
105 z = r .* sin (phi);
8533
fb1b87ea4af9 Permit scalars when transforming coordinates.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
106
fb1b87ea4af9 Permit scalars when transforming coordinates.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
107 endfunction
fb1b87ea4af9 Permit scalars when transforming coordinates.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
108
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
109
8533
fb1b87ea4af9 Permit scalars when transforming coordinates.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
110 %!test
fb1b87ea4af9 Permit scalars when transforming coordinates.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
111 %! t = [0, 0, 0];
fb1b87ea4af9 Permit scalars when transforming coordinates.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
112 %! p = [0, 0, 0];
fb1b87ea4af9 Permit scalars when transforming coordinates.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
113 %! r = [0, 1, 2];
fb1b87ea4af9 Permit scalars when transforming coordinates.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
114 %! [x, y, z] = sph2cart (t, p, r);
fb1b87ea4af9 Permit scalars when transforming coordinates.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
115 %! assert (x, r);
fb1b87ea4af9 Permit scalars when transforming coordinates.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
116 %! assert (y, [0, 0, 0]);
fb1b87ea4af9 Permit scalars when transforming coordinates.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
117 %! assert (z, [0, 0, 0]);
3803
63c75bc3db82 [project @ 2001-02-28 08:24:40 by jwe]
jwe
parents:
diff changeset
118
8533
fb1b87ea4af9 Permit scalars when transforming coordinates.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
119 %!test
28171
a23da76e0693 Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents: 27978
diff changeset
120 %! t = [0; 0; 0];
a23da76e0693 Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents: 27978
diff changeset
121 %! p = [0; 0; 0];
a23da76e0693 Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents: 27978
diff changeset
122 %! r = [0; 1; 2];
a23da76e0693 Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents: 27978
diff changeset
123 %! [x, y, z] = sph2cart (t, p, r);
a23da76e0693 Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents: 27978
diff changeset
124 %! assert (x, [0; 1; 2]);
a23da76e0693 Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents: 27978
diff changeset
125 %! assert (y, [0; 0; 0]);
a23da76e0693 Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents: 27978
diff changeset
126 %! assert (z, [0; 0; 0]);
a23da76e0693 Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents: 27978
diff changeset
127
a23da76e0693 Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents: 27978
diff changeset
128 %!test
8533
fb1b87ea4af9 Permit scalars when transforming coordinates.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
129 %! t = 0;
fb1b87ea4af9 Permit scalars when transforming coordinates.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
130 %! p = [0, 0, 0];
fb1b87ea4af9 Permit scalars when transforming coordinates.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
131 %! r = [0, 1, 2];
28171
a23da76e0693 Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents: 27978
diff changeset
132 %! [x, y, z] = sph2cart (t, p, r);
a23da76e0693 Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents: 27978
diff changeset
133 %! assert (x, [0, 1, 2]);
a23da76e0693 Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents: 27978
diff changeset
134 %! assert (y, [0, 0, 0]);
a23da76e0693 Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents: 27978
diff changeset
135 %! assert (z, [0, 0, 0]);
8533
fb1b87ea4af9 Permit scalars when transforming coordinates.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
136
fb1b87ea4af9 Permit scalars when transforming coordinates.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
137 %!test
fb1b87ea4af9 Permit scalars when transforming coordinates.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
138 %! t = [0, 0, 0];
fb1b87ea4af9 Permit scalars when transforming coordinates.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
139 %! p = 0;
fb1b87ea4af9 Permit scalars when transforming coordinates.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
140 %! r = [0, 1, 2];
fb1b87ea4af9 Permit scalars when transforming coordinates.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
141 %! [x, y, z] = sph2cart (t, p, r);
fb1b87ea4af9 Permit scalars when transforming coordinates.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
142 %! assert (x, r);
fb1b87ea4af9 Permit scalars when transforming coordinates.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
143 %! assert (y, [0, 0, 0]);
fb1b87ea4af9 Permit scalars when transforming coordinates.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
144 %! assert (z, [0, 0, 0]);
fb1b87ea4af9 Permit scalars when transforming coordinates.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
145
fb1b87ea4af9 Permit scalars when transforming coordinates.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
146 %!test
fb1b87ea4af9 Permit scalars when transforming coordinates.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
147 %! t = [0, 0.5, 1]*pi;
fb1b87ea4af9 Permit scalars when transforming coordinates.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
148 %! p = [0, 0, 0];
fb1b87ea4af9 Permit scalars when transforming coordinates.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
149 %! r = 1;
fb1b87ea4af9 Permit scalars when transforming coordinates.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
150 %! [x, y, z] = sph2cart (t, p, r);
fb1b87ea4af9 Permit scalars when transforming coordinates.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
151 %! assert (x, [1, 0, -1], eps);
fb1b87ea4af9 Permit scalars when transforming coordinates.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
152 %! assert (y, [0, 1, 0], eps);
fb1b87ea4af9 Permit scalars when transforming coordinates.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
153 %! assert (z, [0, 0, 0], eps);
fb1b87ea4af9 Permit scalars when transforming coordinates.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
154
10688
7357e37f34fa coordinate transforms: add option to operate on column matrix of coordinates.
Rik <octave@nomad.inbox5.com>
parents: 10687
diff changeset
155 %!test
22432
1e88747417e6 Allow mixed scalar/array inputs to cart2pol, cart2sph, pol2cart, sph2cart (bug #48950).
Rik <rik@octave.org>
parents: 21178
diff changeset
156 %! [x, y, z] = sph2cart ([0 0 0], 0, 1);
1e88747417e6 Allow mixed scalar/array inputs to cart2pol, cart2sph, pol2cart, sph2cart (bug #48950).
Rik <rik@octave.org>
parents: 21178
diff changeset
157 %! assert (x, [1, 1, 1], eps);
1e88747417e6 Allow mixed scalar/array inputs to cart2pol, cart2sph, pol2cart, sph2cart (bug #48950).
Rik <rik@octave.org>
parents: 21178
diff changeset
158 %! assert (y, [0, 0, 0], eps);
1e88747417e6 Allow mixed scalar/array inputs to cart2pol, cart2sph, pol2cart, sph2cart (bug #48950).
Rik <rik@octave.org>
parents: 21178
diff changeset
159 %! assert (z, [0, 0, 0], eps);
1e88747417e6 Allow mixed scalar/array inputs to cart2pol, cart2sph, pol2cart, sph2cart (bug #48950).
Rik <rik@octave.org>
parents: 21178
diff changeset
160
1e88747417e6 Allow mixed scalar/array inputs to cart2pol, cart2sph, pol2cart, sph2cart (bug #48950).
Rik <rik@octave.org>
parents: 21178
diff changeset
161 %!test
10688
7357e37f34fa coordinate transforms: add option to operate on column matrix of coordinates.
Rik <octave@nomad.inbox5.com>
parents: 10687
diff changeset
162 %! S = [ 0, 0, 1; 0.5*pi, 0, 1; pi, 0, 1];
28171
a23da76e0693 Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents: 27978
diff changeset
163 %! [x, y, z] = sph2cart (S);
a23da76e0693 Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents: 27978
diff changeset
164 %! assert (x, [1; 0; -1], eps);
a23da76e0693 Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents: 27978
diff changeset
165 %! assert (y, [0; 1; 0], eps);
a23da76e0693 Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents: 27978
diff changeset
166 %! assert (z, [0; 0; 0], eps);
a23da76e0693 Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents: 27978
diff changeset
167
a23da76e0693 Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents: 27978
diff changeset
168 %!test
a23da76e0693 Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents: 27978
diff changeset
169 %! S = [ 0, 0, 1; 0.5*pi, 0, 1; pi, 0, 1; pi, pi, 1];
a23da76e0693 Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents: 27978
diff changeset
170 %! [x, y, z] = sph2cart (S);
a23da76e0693 Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents: 27978
diff changeset
171 %! assert (x, [1; 0; -1; 1], eps);
a23da76e0693 Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents: 27978
diff changeset
172 %! assert (y, [0; 1; 0; 0], eps);
a23da76e0693 Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents: 27978
diff changeset
173 %! assert (z, [0; 0; 0; 0], eps);
a23da76e0693 Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents: 27978
diff changeset
174
10688
7357e37f34fa coordinate transforms: add option to operate on column matrix of coordinates.
Rik <octave@nomad.inbox5.com>
parents: 10687
diff changeset
175
21172
5f62b5dae8b1 Fix regression for coordinate transforms on 3-D arrays (partial fix bug #47036).
Colin Macdonald <cbm@m.fsf.org>
parents: 20158
diff changeset
176 %!test
5f62b5dae8b1 Fix regression for coordinate transforms on 3-D arrays (partial fix bug #47036).
Colin Macdonald <cbm@m.fsf.org>
parents: 20158
diff changeset
177 %! [t, p, r] = meshgrid ([0, pi/2], [0, pi/2], [0, 1]);
5f62b5dae8b1 Fix regression for coordinate transforms on 3-D arrays (partial fix bug #47036).
Colin Macdonald <cbm@m.fsf.org>
parents: 20158
diff changeset
178 %! [x, y, z] = sph2cart (t, p, r);
5f62b5dae8b1 Fix regression for coordinate transforms on 3-D arrays (partial fix bug #47036).
Colin Macdonald <cbm@m.fsf.org>
parents: 20158
diff changeset
179 %! X = zeros(2, 2, 2);
5f62b5dae8b1 Fix regression for coordinate transforms on 3-D arrays (partial fix bug #47036).
Colin Macdonald <cbm@m.fsf.org>
parents: 20158
diff changeset
180 %! X(1, 1, 2) = 1;
5f62b5dae8b1 Fix regression for coordinate transforms on 3-D arrays (partial fix bug #47036).
Colin Macdonald <cbm@m.fsf.org>
parents: 20158
diff changeset
181 %! Y = zeros(2, 2, 2);
5f62b5dae8b1 Fix regression for coordinate transforms on 3-D arrays (partial fix bug #47036).
Colin Macdonald <cbm@m.fsf.org>
parents: 20158
diff changeset
182 %! Y(1, 2, 2) = 1;
5f62b5dae8b1 Fix regression for coordinate transforms on 3-D arrays (partial fix bug #47036).
Colin Macdonald <cbm@m.fsf.org>
parents: 20158
diff changeset
183 %! Z = zeros(2, 2, 2);
5f62b5dae8b1 Fix regression for coordinate transforms on 3-D arrays (partial fix bug #47036).
Colin Macdonald <cbm@m.fsf.org>
parents: 20158
diff changeset
184 %! Z(2, :, 2) = [1 1];
5f62b5dae8b1 Fix regression for coordinate transforms on 3-D arrays (partial fix bug #47036).
Colin Macdonald <cbm@m.fsf.org>
parents: 20158
diff changeset
185 %! assert (x, X, eps);
5f62b5dae8b1 Fix regression for coordinate transforms on 3-D arrays (partial fix bug #47036).
Colin Macdonald <cbm@m.fsf.org>
parents: 20158
diff changeset
186 %! assert (y, Y, eps);
5f62b5dae8b1 Fix regression for coordinate transforms on 3-D arrays (partial fix bug #47036).
Colin Macdonald <cbm@m.fsf.org>
parents: 20158
diff changeset
187 %! assert (z, Z);
5f62b5dae8b1 Fix regression for coordinate transforms on 3-D arrays (partial fix bug #47036).
Colin Macdonald <cbm@m.fsf.org>
parents: 20158
diff changeset
188
5f62b5dae8b1 Fix regression for coordinate transforms on 3-D arrays (partial fix bug #47036).
Colin Macdonald <cbm@m.fsf.org>
parents: 20158
diff changeset
189 ## Test input validation
5f62b5dae8b1 Fix regression for coordinate transforms on 3-D arrays (partial fix bug #47036).
Colin Macdonald <cbm@m.fsf.org>
parents: 20158
diff changeset
190 %!error sph2cart ()
5f62b5dae8b1 Fix regression for coordinate transforms on 3-D arrays (partial fix bug #47036).
Colin Macdonald <cbm@m.fsf.org>
parents: 20158
diff changeset
191 %!error sph2cart (1,2)
5f62b5dae8b1 Fix regression for coordinate transforms on 3-D arrays (partial fix bug #47036).
Colin Macdonald <cbm@m.fsf.org>
parents: 20158
diff changeset
192 %!error sph2cart (1,2,3,4)
28171
a23da76e0693 Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents: 27978
diff changeset
193 %!error <matrix input must be a 2-D numeric array> sph2cart ({1,2,3})
a23da76e0693 Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents: 27978
diff changeset
194 %!error <matrix input must be a 2-D numeric array> sph2cart (ones (3,3,2))
a23da76e0693 Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents: 27978
diff changeset
195 %!error <matrix input must be a 3-element> sph2cart ([1,2,3,4])
a23da76e0693 Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents: 27978
diff changeset
196 %!error <matrix input must be a 3-element> sph2cart ([1,2,3,4; 1,2,3,4; 1,2,3,4])
a23da76e0693 Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents: 27978
diff changeset
197 %!error <must be numeric arrays or scalars> sph2cart ({1,2,3}, [1,2,3], [1,2,3])
a23da76e0693 Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents: 27978
diff changeset
198 %!error <must be numeric arrays or scalars> sph2cart ([1,2,3], {1,2,3}, [1,2,3])
a23da76e0693 Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents: 27978
diff changeset
199 %!error <must be numeric arrays or scalars> sph2cart ([1,2,3], [1,2,3], {1,2,3})
a23da76e0693 Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents: 27978
diff changeset
200 %!error <must be the same size or scalars> sph2cart ([1,2,3], [1,2,3], [1,2,3]')
a23da76e0693 Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents: 27978
diff changeset
201 %!error <must be the same size or scalars> sph2cart (ones (3,3,3), 1, ones (3,2,3))
a23da76e0693 Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents: 27978
diff changeset
202 %!error <must be the same size or scalars> sph2cart (ones (3,3,3), ones (3,2,3), 1)