Mercurial > octave
annotate scripts/general/sph2cart.m @ 31205:b0e90ca8e679 stable
quad2d: fix unintended complex conjugate return (bug #62972)
quad2d: use .' instead of ' to avoid complex conjugate in q and qerr.
author | Arun Giridhar <arungiridhar@gmail.com> |
---|---|
date | Sun, 28 Aug 2022 12:21:17 -0400 |
parents | 796f54d4ddbf |
children | 597f3ee61a48 |
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 ## |
30564
796f54d4ddbf
update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents:
29359
diff
changeset
|
3 ## Copyright (C) 2000-2022 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 | 7 ## |
8 ## This file is part of Octave. | |
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 | 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 | 14 ## |
15 ## Octave is distributed in the hope that it will be useful, but | |
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 | 19 ## |
20 ## You should have received a copy of the GNU General Public License | |
7016 | 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 | 25 |
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 |
28753 | 57 ## @group |
28171
a23da76e0693
Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
27978
diff
changeset
|
58 ## @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
|
59 ## @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
|
60 ## @var{z} = r * sin (@var{phi}) |
28753 | 61 ## @end group |
28171
a23da76e0693
Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
27978
diff
changeset
|
62 ## @end example |
a23da76e0693
Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
27978
diff
changeset
|
63 ## |
a23da76e0693
Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
27978
diff
changeset
|
64 ## @end ifnottex |
a23da76e0693
Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
27978
diff
changeset
|
65 ## @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
|
66 ## 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
|
67 ## 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
|
68 ## @seealso{cart2sph, pol2cart, cart2pol} |
3803 | 69 ## @end deftypefn |
70 | |
8533
fb1b87ea4af9
Permit scalars when transforming coordinates.
Ben Abbott <bpabbott@mac.com>
parents:
7017
diff
changeset
|
71 function [x, y, z] = sph2cart (theta, phi, r) |
3803 | 72 |
10688
7357e37f34fa
coordinate transforms: add option to operate on column matrix of coordinates.
Rik <octave@nomad.inbox5.com>
parents:
10687
diff
changeset
|
73 if (nargin != 1 && nargin != 3) |
6046 | 74 print_usage (); |
3803 | 75 endif |
76 | |
10688
7357e37f34fa
coordinate transforms: add option to operate on column matrix of coordinates.
Rik <octave@nomad.inbox5.com>
parents:
10687
diff
changeset
|
77 if (nargin == 1) |
28171
a23da76e0693
Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
27978
diff
changeset
|
78 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
|
79 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
|
80 endif |
a23da76e0693
Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
27978
diff
changeset
|
81 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
|
82 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
|
83 endif |
28171
a23da76e0693
Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
27978
diff
changeset
|
84 |
a23da76e0693
Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
27978
diff
changeset
|
85 if (numel (theta) == 3) |
a23da76e0693
Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
27978
diff
changeset
|
86 r = theta(3); |
a23da76e0693
Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
27978
diff
changeset
|
87 phi = theta(2); |
a23da76e0693
Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
27978
diff
changeset
|
88 theta = theta(1); |
a23da76e0693
Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
27978
diff
changeset
|
89 else |
a23da76e0693
Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
27978
diff
changeset
|
90 r = theta(:,3); |
a23da76e0693
Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
27978
diff
changeset
|
91 phi = theta(:,2); |
a23da76e0693
Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
27978
diff
changeset
|
92 theta = theta(:,1); |
a23da76e0693
Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
27978
diff
changeset
|
93 endif |
a23da76e0693
Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
27978
diff
changeset
|
94 |
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
|
95 else |
28171
a23da76e0693
Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
27978
diff
changeset
|
96 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
|
97 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
|
98 endif |
1e88747417e6
Allow mixed scalar/array inputs to cart2pol, cart2sph, pol2cart, sph2cart (bug #48950).
Rik <rik@octave.org>
parents:
21178
diff
changeset
|
99 [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
|
100 if (err) |
28171
a23da76e0693
Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
27978
diff
changeset
|
101 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
|
102 endif |
7357e37f34fa
coordinate transforms: add option to operate on column matrix of coordinates.
Rik <octave@nomad.inbox5.com>
parents:
10687
diff
changeset
|
103 endif |
8533
fb1b87ea4af9
Permit scalars when transforming coordinates.
Ben Abbott <bpabbott@mac.com>
parents:
7017
diff
changeset
|
104 |
10688
7357e37f34fa
coordinate transforms: add option to operate on column matrix of coordinates.
Rik <octave@nomad.inbox5.com>
parents:
10687
diff
changeset
|
105 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
|
106 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
|
107 z = r .* sin (phi); |
8533
fb1b87ea4af9
Permit scalars when transforming coordinates.
Ben Abbott <bpabbott@mac.com>
parents:
7017
diff
changeset
|
108 |
fb1b87ea4af9
Permit scalars when transforming coordinates.
Ben Abbott <bpabbott@mac.com>
parents:
7017
diff
changeset
|
109 endfunction |
fb1b87ea4af9
Permit scalars when transforming coordinates.
Ben Abbott <bpabbott@mac.com>
parents:
7017
diff
changeset
|
110 |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
111 |
8533
fb1b87ea4af9
Permit scalars when transforming coordinates.
Ben Abbott <bpabbott@mac.com>
parents:
7017
diff
changeset
|
112 %!test |
fb1b87ea4af9
Permit scalars when transforming coordinates.
Ben Abbott <bpabbott@mac.com>
parents:
7017
diff
changeset
|
113 %! t = [0, 0, 0]; |
fb1b87ea4af9
Permit scalars when transforming coordinates.
Ben Abbott <bpabbott@mac.com>
parents:
7017
diff
changeset
|
114 %! p = [0, 0, 0]; |
fb1b87ea4af9
Permit scalars when transforming coordinates.
Ben Abbott <bpabbott@mac.com>
parents:
7017
diff
changeset
|
115 %! r = [0, 1, 2]; |
fb1b87ea4af9
Permit scalars when transforming coordinates.
Ben Abbott <bpabbott@mac.com>
parents:
7017
diff
changeset
|
116 %! [x, y, z] = sph2cart (t, p, r); |
fb1b87ea4af9
Permit scalars when transforming coordinates.
Ben Abbott <bpabbott@mac.com>
parents:
7017
diff
changeset
|
117 %! assert (x, r); |
fb1b87ea4af9
Permit scalars when transforming coordinates.
Ben Abbott <bpabbott@mac.com>
parents:
7017
diff
changeset
|
118 %! assert (y, [0, 0, 0]); |
fb1b87ea4af9
Permit scalars when transforming coordinates.
Ben Abbott <bpabbott@mac.com>
parents:
7017
diff
changeset
|
119 %! assert (z, [0, 0, 0]); |
3803 | 120 |
8533
fb1b87ea4af9
Permit scalars when transforming coordinates.
Ben Abbott <bpabbott@mac.com>
parents:
7017
diff
changeset
|
121 %!test |
28171
a23da76e0693
Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
27978
diff
changeset
|
122 %! t = [0; 0; 0]; |
a23da76e0693
Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
27978
diff
changeset
|
123 %! p = [0; 0; 0]; |
a23da76e0693
Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
27978
diff
changeset
|
124 %! r = [0; 1; 2]; |
a23da76e0693
Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
27978
diff
changeset
|
125 %! [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
|
126 %! 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
|
127 %! 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
|
128 %! 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
|
129 |
a23da76e0693
Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
27978
diff
changeset
|
130 %!test |
8533
fb1b87ea4af9
Permit scalars when transforming coordinates.
Ben Abbott <bpabbott@mac.com>
parents:
7017
diff
changeset
|
131 %! t = 0; |
fb1b87ea4af9
Permit scalars when transforming coordinates.
Ben Abbott <bpabbott@mac.com>
parents:
7017
diff
changeset
|
132 %! p = [0, 0, 0]; |
fb1b87ea4af9
Permit scalars when transforming coordinates.
Ben Abbott <bpabbott@mac.com>
parents:
7017
diff
changeset
|
133 %! 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
|
134 %! [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
|
135 %! 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
|
136 %! 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
|
137 %! assert (z, [0, 0, 0]); |
8533
fb1b87ea4af9
Permit scalars when transforming coordinates.
Ben Abbott <bpabbott@mac.com>
parents:
7017
diff
changeset
|
138 |
fb1b87ea4af9
Permit scalars when transforming coordinates.
Ben Abbott <bpabbott@mac.com>
parents:
7017
diff
changeset
|
139 %!test |
fb1b87ea4af9
Permit scalars when transforming coordinates.
Ben Abbott <bpabbott@mac.com>
parents:
7017
diff
changeset
|
140 %! t = [0, 0, 0]; |
fb1b87ea4af9
Permit scalars when transforming coordinates.
Ben Abbott <bpabbott@mac.com>
parents:
7017
diff
changeset
|
141 %! p = 0; |
fb1b87ea4af9
Permit scalars when transforming coordinates.
Ben Abbott <bpabbott@mac.com>
parents:
7017
diff
changeset
|
142 %! r = [0, 1, 2]; |
fb1b87ea4af9
Permit scalars when transforming coordinates.
Ben Abbott <bpabbott@mac.com>
parents:
7017
diff
changeset
|
143 %! [x, y, z] = sph2cart (t, p, r); |
fb1b87ea4af9
Permit scalars when transforming coordinates.
Ben Abbott <bpabbott@mac.com>
parents:
7017
diff
changeset
|
144 %! assert (x, r); |
fb1b87ea4af9
Permit scalars when transforming coordinates.
Ben Abbott <bpabbott@mac.com>
parents:
7017
diff
changeset
|
145 %! assert (y, [0, 0, 0]); |
fb1b87ea4af9
Permit scalars when transforming coordinates.
Ben Abbott <bpabbott@mac.com>
parents:
7017
diff
changeset
|
146 %! assert (z, [0, 0, 0]); |
fb1b87ea4af9
Permit scalars when transforming coordinates.
Ben Abbott <bpabbott@mac.com>
parents:
7017
diff
changeset
|
147 |
fb1b87ea4af9
Permit scalars when transforming coordinates.
Ben Abbott <bpabbott@mac.com>
parents:
7017
diff
changeset
|
148 %!test |
fb1b87ea4af9
Permit scalars when transforming coordinates.
Ben Abbott <bpabbott@mac.com>
parents:
7017
diff
changeset
|
149 %! t = [0, 0.5, 1]*pi; |
fb1b87ea4af9
Permit scalars when transforming coordinates.
Ben Abbott <bpabbott@mac.com>
parents:
7017
diff
changeset
|
150 %! p = [0, 0, 0]; |
fb1b87ea4af9
Permit scalars when transforming coordinates.
Ben Abbott <bpabbott@mac.com>
parents:
7017
diff
changeset
|
151 %! r = 1; |
fb1b87ea4af9
Permit scalars when transforming coordinates.
Ben Abbott <bpabbott@mac.com>
parents:
7017
diff
changeset
|
152 %! [x, y, z] = sph2cart (t, p, r); |
fb1b87ea4af9
Permit scalars when transforming coordinates.
Ben Abbott <bpabbott@mac.com>
parents:
7017
diff
changeset
|
153 %! assert (x, [1, 0, -1], eps); |
fb1b87ea4af9
Permit scalars when transforming coordinates.
Ben Abbott <bpabbott@mac.com>
parents:
7017
diff
changeset
|
154 %! assert (y, [0, 1, 0], eps); |
fb1b87ea4af9
Permit scalars when transforming coordinates.
Ben Abbott <bpabbott@mac.com>
parents:
7017
diff
changeset
|
155 %! assert (z, [0, 0, 0], eps); |
fb1b87ea4af9
Permit scalars when transforming coordinates.
Ben Abbott <bpabbott@mac.com>
parents:
7017
diff
changeset
|
156 |
10688
7357e37f34fa
coordinate transforms: add option to operate on column matrix of coordinates.
Rik <octave@nomad.inbox5.com>
parents:
10687
diff
changeset
|
157 %!test |
22432
1e88747417e6
Allow mixed scalar/array inputs to cart2pol, cart2sph, pol2cart, sph2cart (bug #48950).
Rik <rik@octave.org>
parents:
21178
diff
changeset
|
158 %! [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
|
159 %! 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
|
160 %! 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
|
161 %! 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
|
162 |
1e88747417e6
Allow mixed scalar/array inputs to cart2pol, cart2sph, pol2cart, sph2cart (bug #48950).
Rik <rik@octave.org>
parents:
21178
diff
changeset
|
163 %!test |
10688
7357e37f34fa
coordinate transforms: add option to operate on column matrix of coordinates.
Rik <octave@nomad.inbox5.com>
parents:
10687
diff
changeset
|
164 %! 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
|
165 %! [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
|
166 %! 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
|
167 %! 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
|
168 %! 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
|
169 |
a23da76e0693
Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
27978
diff
changeset
|
170 %!test |
a23da76e0693
Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
27978
diff
changeset
|
171 %! 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
|
172 %! [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
|
173 %! 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
|
174 %! 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
|
175 %! 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
|
176 |
10688
7357e37f34fa
coordinate transforms: add option to operate on column matrix of coordinates.
Rik <octave@nomad.inbox5.com>
parents:
10687
diff
changeset
|
177 |
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
|
178 %!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
|
179 %! [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
|
180 %! [x, y, z] = sph2cart (t, p, r); |
28912
0de38a6ef693
maint: Use Octave convention of space after function name in scripts dir.
Rik <rik@octave.org>
parents:
28896
diff
changeset
|
181 %! X = zeros (2, 2, 2); |
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
|
182 %! X(1, 1, 2) = 1; |
28912
0de38a6ef693
maint: Use Octave convention of space after function name in scripts dir.
Rik <rik@octave.org>
parents:
28896
diff
changeset
|
183 %! Y = zeros (2, 2, 2); |
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
|
184 %! Y(1, 2, 2) = 1; |
28912
0de38a6ef693
maint: Use Octave convention of space after function name in scripts dir.
Rik <rik@octave.org>
parents:
28896
diff
changeset
|
185 %! Z = zeros (2, 2, 2); |
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
|
186 %! 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
|
187 %! 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
|
188 %! 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
|
189 %! 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
|
190 |
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 ## Test input validation |
28896
90fea9cc9caa
test: Add expected error message <Invalid call> to BIST tests for nargin.
Rik <rik@octave.org>
parents:
28753
diff
changeset
|
192 %!error <Invalid call> sph2cart () |
90fea9cc9caa
test: Add expected error message <Invalid call> to BIST tests for nargin.
Rik <rik@octave.org>
parents:
28753
diff
changeset
|
193 %!error <Invalid call> sph2cart (1,2) |
28171
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 ({1,2,3}) |
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 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
|
196 %!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
|
197 %!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
|
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 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
|
201 %!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
|
202 %!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
|
203 %!error <must be the same size or scalars> sph2cart (ones (3,3,3), ones (3,2,3), 1) |