annotate scripts/general/cart2sph.m @ 33625:d213a148b3f1 default tip @

ensure exp. terminal widget has focus at startup * main-window.cc (main_window): call focus_command_window only if event loop is idle by using a single shot timer * main-window.h: make focus_command_window a public slot
author Torsten Lilge <ttl-octave@mailbox.org>
date Sun, 26 May 2024 02:29:44 +0200
parents 2e484f9f1f18
children
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 ##
32632
2e484f9f1f18 maint: update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents: 31706
diff changeset
3 ## Copyright (C) 2000-2024 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: 6786
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: 20181
diff changeset
27 ## @deftypefn {} {[@var{theta}, @var{phi}, @var{r}] =} cart2sph (@var{x}, @var{y}, @var{z})
516bb87ea72e 2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents: 20181
diff changeset
28 ## @deftypefnx {} {[@var{theta}, @var{phi}, @var{r}] =} cart2sph (@var{C})
20158
7503499a252b doc: Update docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19697
diff changeset
29 ## Transform Cartesian coordinates to spherical coordinates.
10688
7357e37f34fa coordinate transforms: add option to operate on column matrix of coordinates.
Rik <octave@nomad.inbox5.com>
parents: 10687
diff changeset
30 ##
20158
7503499a252b doc: Update docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19697
diff changeset
31 ## The inputs @var{x}, @var{y}, and @var{z} must be the same shape, or scalar.
28171
a23da76e0693 Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents: 27978
diff changeset
32 ## If called with a single matrix argument then each row of @var{C} must
a23da76e0693 Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents: 27978
diff changeset
33 ## represent a Cartesian coordinate triplet (@var{x}, @var{y}, @var{z}).
20181
aa36fb998a4d maint: Remove unnecessary whitespace at end of lines.
Rik <rik@octave.org>
parents: 20158
diff changeset
34 ##
28171
a23da76e0693 Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents: 27978
diff changeset
35 ## The outputs @var{theta}, @var{phi}, @var{r} match the shape of the inputs.
a23da76e0693 Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents: 27978
diff changeset
36 ## For a matrix input @var{C} the outputs will be column vectors with rows
a23da76e0693 Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents: 27978
diff changeset
37 ## corresponding 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
38 ##
28171
a23da76e0693 Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents: 27978
diff changeset
39 ## @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
40 ## 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
41 ##
a23da76e0693 Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents: 27978
diff changeset
42 ## @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
43 ##
10687
a8ce6bdecce5 Improve documentation strings.
Rik <octave@nomad.inbox5.com>
parents: 9168
diff changeset
44 ## @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
45 ##
28171
a23da76e0693 Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents: 27978
diff changeset
46 ## 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
47 ##
a23da76e0693 Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents: 27978
diff changeset
48 ## @tex
a23da76e0693 Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents: 27978
diff changeset
49 ## $$ \theta = \arctan \left ({y \over x} \right ) $$
a23da76e0693 Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents: 27978
diff changeset
50 ## $$ \phi = \arctan \left ( {z \over {\sqrt{x^2+y^2}}} \right ) $$
a23da76e0693 Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents: 27978
diff changeset
51 ## $$ r = \sqrt{x^2 + y^2 + z^2} $$
a23da76e0693 Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents: 27978
diff changeset
52 ## @end tex
a23da76e0693 Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents: 27978
diff changeset
53 ## @ifnottex
a23da76e0693 Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents: 27978
diff changeset
54 ##
a23da76e0693 Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents: 27978
diff changeset
55 ## @example
a23da76e0693 Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents: 27978
diff changeset
56 ## @group
a23da76e0693 Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents: 27978
diff changeset
57 ## @var{theta} = arctan (@var{y} / @var{x})
a23da76e0693 Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents: 27978
diff changeset
58 ## @var{phi} = arctan (@var{z} / sqrt (@var{x}^2 + @var{y}^2))
a23da76e0693 Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents: 27978
diff changeset
59 ## @var{r} = sqrt (@var{x}^2 + @var{y}^2 + @var{z}^2)
a23da76e0693 Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents: 27978
diff changeset
60 ## @end group
a23da76e0693 Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents: 27978
diff changeset
61 ## @end example
a23da76e0693 Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents: 27978
diff changeset
62 ##
a23da76e0693 Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents: 27978
diff changeset
63 ## @end ifnottex
a23da76e0693 Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents: 27978
diff changeset
64 ##
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{sph2cart, cart2pol, pol2cart}
3803
63c75bc3db82 [project @ 2001-02-28 08:24:40 by jwe]
jwe
parents:
diff changeset
69 ## @end deftypefn
63c75bc3db82 [project @ 2001-02-28 08:24:40 by jwe]
jwe
parents:
diff changeset
70
8533
fb1b87ea4af9 Permit scalars when transforming coordinates.
Ben Abbott <bpabbott@mac.com>
parents: 8491
diff changeset
71 function [theta, phi, r] = cart2sph (x, y, z)
3803
63c75bc3db82 [project @ 2001-02-28 08:24:40 by jwe]
jwe
parents:
diff changeset
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
34f96dd5441b [project @ 2006-10-10 16:10:25 by jwe]
jwe
parents: 5642
diff changeset
74 print_usage ();
3803
63c75bc3db82 [project @ 2001-02-28 08:24:40 by jwe]
jwe
parents:
diff changeset
75 endif
63c75bc3db82 [project @ 2001-02-28 08:24:40 by jwe]
jwe
parents:
diff changeset
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 (x) && ismatrix (x)))
a23da76e0693 Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents: 27978
diff changeset
79 error ("cart2sph: matrix input C 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 elseif (columns (x) != 3 && numel (x) != 3)
a23da76e0693 Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents: 27978
diff changeset
81 error ("cart2sph: matrix input C 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
82 endif
28171
a23da76e0693 Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents: 27978
diff changeset
83
a23da76e0693 Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents: 27978
diff changeset
84 if (numel (x) == 3)
a23da76e0693 Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents: 27978
diff changeset
85 z = x(3);
a23da76e0693 Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents: 27978
diff changeset
86 y = x(2);
a23da76e0693 Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents: 27978
diff changeset
87 x = x(1);
a23da76e0693 Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents: 27978
diff changeset
88 else
a23da76e0693 Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents: 27978
diff changeset
89 z = x(:,3);
a23da76e0693 Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents: 27978
diff changeset
90 y = x(:,2);
a23da76e0693 Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents: 27978
diff changeset
91 x = x(:,1);
a23da76e0693 Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents: 27978
diff changeset
92 endif
a23da76e0693 Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents: 27978
diff changeset
93
21172
5f62b5dae8b1 Fix regression for coordinate transforms on 3-D arrays (partial fix bug #47036).
Colin Macdonald <cbm@m.fsf.org>
parents: 20181
diff changeset
94 else
28171
a23da76e0693 Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents: 27978
diff changeset
95 if (! (isnumeric (x) && isnumeric (y) && isnumeric (z)))
a23da76e0693 Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents: 27978
diff changeset
96 error ("cart2sph: X, Y, Z 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
97 endif
1e88747417e6 Allow mixed scalar/array inputs to cart2pol, cart2sph, pol2cart, sph2cart (bug #48950).
Rik <rik@octave.org>
parents: 21178
diff changeset
98 [err, x, y, z] = common_size (x, y, z);
1e88747417e6 Allow mixed scalar/array inputs to cart2pol, cart2sph, pol2cart, sph2cart (bug #48950).
Rik <rik@octave.org>
parents: 21178
diff changeset
99 if (err)
28171
a23da76e0693 Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents: 27978
diff changeset
100 error ("cart2sph: X, Y, Z 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
101 endif
7357e37f34fa coordinate transforms: add option to operate on column matrix of coordinates.
Rik <octave@nomad.inbox5.com>
parents: 10687
diff changeset
102 endif
8533
fb1b87ea4af9 Permit scalars when transforming coordinates.
Ben Abbott <bpabbott@mac.com>
parents: 8491
diff changeset
103
10688
7357e37f34fa coordinate transforms: add option to operate on column matrix of coordinates.
Rik <octave@nomad.inbox5.com>
parents: 10687
diff changeset
104 theta = atan2 (y, x);
7357e37f34fa coordinate transforms: add option to operate on column matrix of coordinates.
Rik <octave@nomad.inbox5.com>
parents: 10687
diff changeset
105 phi = atan2 (z, sqrt (x .^ 2 + y .^ 2));
7357e37f34fa coordinate transforms: add option to operate on column matrix of coordinates.
Rik <octave@nomad.inbox5.com>
parents: 10687
diff changeset
106 r = sqrt (x .^ 2 + y .^ 2 + z .^ 2);
8533
fb1b87ea4af9 Permit scalars when transforming coordinates.
Ben Abbott <bpabbott@mac.com>
parents: 8491
diff changeset
107
fb1b87ea4af9 Permit scalars when transforming coordinates.
Ben Abbott <bpabbott@mac.com>
parents: 8491
diff changeset
108 endfunction
fb1b87ea4af9 Permit scalars when transforming coordinates.
Ben Abbott <bpabbott@mac.com>
parents: 8491
diff changeset
109
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
110
8533
fb1b87ea4af9 Permit scalars when transforming coordinates.
Ben Abbott <bpabbott@mac.com>
parents: 8491
diff changeset
111 %!test
fb1b87ea4af9 Permit scalars when transforming coordinates.
Ben Abbott <bpabbott@mac.com>
parents: 8491
diff changeset
112 %! x = [0, 1, 2];
fb1b87ea4af9 Permit scalars when transforming coordinates.
Ben Abbott <bpabbott@mac.com>
parents: 8491
diff changeset
113 %! y = [0, 1, 2];
fb1b87ea4af9 Permit scalars when transforming coordinates.
Ben Abbott <bpabbott@mac.com>
parents: 8491
diff changeset
114 %! z = [0, 1, 2];
fb1b87ea4af9 Permit scalars when transforming coordinates.
Ben Abbott <bpabbott@mac.com>
parents: 8491
diff changeset
115 %! [t, p, r] = cart2sph (x, y, z);
fb1b87ea4af9 Permit scalars when transforming coordinates.
Ben Abbott <bpabbott@mac.com>
parents: 8491
diff changeset
116 %! assert (t, [0, pi/4, pi/4], eps);
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
117 %! assert (p, [0, 1, 1]*atan (sqrt (0.5)), eps);
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
118 %! assert (r, [0, 1, 2]*sqrt (3), eps);
3803
63c75bc3db82 [project @ 2001-02-28 08:24:40 by jwe]
jwe
parents:
diff changeset
119
8533
fb1b87ea4af9 Permit scalars when transforming coordinates.
Ben Abbott <bpabbott@mac.com>
parents: 8491
diff changeset
120 %!test
28171
a23da76e0693 Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents: 27978
diff changeset
121 %! x = [0; 1; 2];
a23da76e0693 Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents: 27978
diff changeset
122 %! y = [0; 1; 2];
a23da76e0693 Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents: 27978
diff changeset
123 %! z = [0; 1; 2];
a23da76e0693 Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents: 27978
diff changeset
124 %! [t, p, r] = cart2sph (x, y, z);
a23da76e0693 Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents: 27978
diff changeset
125 %! assert (t, [0; pi/4; pi/4], eps);
a23da76e0693 Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents: 27978
diff changeset
126 %! assert (p, [0; 1; 1] * atan (sqrt (0.5)), eps);
a23da76e0693 Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents: 27978
diff changeset
127 %! assert (r, [0; 1; 2] * sqrt (3), eps);
a23da76e0693 Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents: 27978
diff changeset
128
a23da76e0693 Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents: 27978
diff changeset
129 %!test
8533
fb1b87ea4af9 Permit scalars when transforming coordinates.
Ben Abbott <bpabbott@mac.com>
parents: 8491
diff changeset
130 %! x = 0;
fb1b87ea4af9 Permit scalars when transforming coordinates.
Ben Abbott <bpabbott@mac.com>
parents: 8491
diff changeset
131 %! y = [0, 1, 2];
fb1b87ea4af9 Permit scalars when transforming coordinates.
Ben Abbott <bpabbott@mac.com>
parents: 8491
diff changeset
132 %! z = [0, 1, 2];
28171
a23da76e0693 Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents: 27978
diff changeset
133 %! [t, p, r] = cart2sph (x, y, z);
a23da76e0693 Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents: 27978
diff changeset
134 %! assert (t, [0, 1, 1] * pi/2, eps);
a23da76e0693 Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents: 27978
diff changeset
135 %! assert (p, [0, 1, 1] * pi/4, eps);
a23da76e0693 Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents: 27978
diff changeset
136 %! assert (r, [0, 1, 2] * sqrt (2), eps);
8533
fb1b87ea4af9 Permit scalars when transforming coordinates.
Ben Abbott <bpabbott@mac.com>
parents: 8491
diff changeset
137
fb1b87ea4af9 Permit scalars when transforming coordinates.
Ben Abbott <bpabbott@mac.com>
parents: 8491
diff changeset
138 %!test
fb1b87ea4af9 Permit scalars when transforming coordinates.
Ben Abbott <bpabbott@mac.com>
parents: 8491
diff changeset
139 %! x = [0, 1, 2];
fb1b87ea4af9 Permit scalars when transforming coordinates.
Ben Abbott <bpabbott@mac.com>
parents: 8491
diff changeset
140 %! y = 0;
fb1b87ea4af9 Permit scalars when transforming coordinates.
Ben Abbott <bpabbott@mac.com>
parents: 8491
diff changeset
141 %! z = [0, 1, 2];
fb1b87ea4af9 Permit scalars when transforming coordinates.
Ben Abbott <bpabbott@mac.com>
parents: 8491
diff changeset
142 %! [t, p, r] = cart2sph (x, y, z);
fb1b87ea4af9 Permit scalars when transforming coordinates.
Ben Abbott <bpabbott@mac.com>
parents: 8491
diff changeset
143 %! assert (t, [0, 0, 0]);
28171
a23da76e0693 Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents: 27978
diff changeset
144 %! assert (p, [0, 1, 1] * pi/4, eps);
a23da76e0693 Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents: 27978
diff changeset
145 %! assert (r, [0, 1, 2] * sqrt (2), eps);
8533
fb1b87ea4af9 Permit scalars when transforming coordinates.
Ben Abbott <bpabbott@mac.com>
parents: 8491
diff changeset
146
fb1b87ea4af9 Permit scalars when transforming coordinates.
Ben Abbott <bpabbott@mac.com>
parents: 8491
diff changeset
147 %!test
fb1b87ea4af9 Permit scalars when transforming coordinates.
Ben Abbott <bpabbott@mac.com>
parents: 8491
diff changeset
148 %! x = [0, 1, 2];
fb1b87ea4af9 Permit scalars when transforming coordinates.
Ben Abbott <bpabbott@mac.com>
parents: 8491
diff changeset
149 %! y = [0, 1, 2];
fb1b87ea4af9 Permit scalars when transforming coordinates.
Ben Abbott <bpabbott@mac.com>
parents: 8491
diff changeset
150 %! z = 0;
fb1b87ea4af9 Permit scalars when transforming coordinates.
Ben Abbott <bpabbott@mac.com>
parents: 8491
diff changeset
151 %! [t, p, r] = cart2sph (x, y, z);
28171
a23da76e0693 Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents: 27978
diff changeset
152 %! assert (t, [0, 1, 1] * pi/4, eps);
8533
fb1b87ea4af9 Permit scalars when transforming coordinates.
Ben Abbott <bpabbott@mac.com>
parents: 8491
diff changeset
153 %! assert (p, [0, 0, 0]);
28171
a23da76e0693 Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents: 27978
diff changeset
154 %! assert (r, [0, 1, 2] * sqrt (2), eps);
8533
fb1b87ea4af9 Permit scalars when transforming coordinates.
Ben Abbott <bpabbott@mac.com>
parents: 8491
diff changeset
155
10688
7357e37f34fa coordinate transforms: add option to operate on column matrix of coordinates.
Rik <octave@nomad.inbox5.com>
parents: 10687
diff changeset
156 %!test
22432
1e88747417e6 Allow mixed scalar/array inputs to cart2pol, cart2sph, pol2cart, sph2cart (bug #48950).
Rik <rik@octave.org>
parents: 21178
diff changeset
157 %! x = 0;
1e88747417e6 Allow mixed scalar/array inputs to cart2pol, cart2sph, pol2cart, sph2cart (bug #48950).
Rik <rik@octave.org>
parents: 21178
diff changeset
158 %! y = 0;
1e88747417e6 Allow mixed scalar/array inputs to cart2pol, cart2sph, pol2cart, sph2cart (bug #48950).
Rik <rik@octave.org>
parents: 21178
diff changeset
159 %! z = [0, 1, 2];
1e88747417e6 Allow mixed scalar/array inputs to cart2pol, cart2sph, pol2cart, sph2cart (bug #48950).
Rik <rik@octave.org>
parents: 21178
diff changeset
160 %! [t, p, r] = cart2sph (x, y, z);
1e88747417e6 Allow mixed scalar/array inputs to cart2pol, cart2sph, pol2cart, sph2cart (bug #48950).
Rik <rik@octave.org>
parents: 21178
diff changeset
161 %! assert (t, [0, 0, 0]);
28171
a23da76e0693 Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents: 27978
diff changeset
162 %! assert (p, [0, 1, 1] * pi/2, eps);
22432
1e88747417e6 Allow mixed scalar/array inputs to cart2pol, cart2sph, pol2cart, sph2cart (bug #48950).
Rik <rik@octave.org>
parents: 21178
diff changeset
163 %! assert (r, [0, 1, 2]);
1e88747417e6 Allow mixed scalar/array inputs to cart2pol, cart2sph, pol2cart, sph2cart (bug #48950).
Rik <rik@octave.org>
parents: 21178
diff changeset
164
1e88747417e6 Allow mixed scalar/array inputs to cart2pol, cart2sph, pol2cart, sph2cart (bug #48950).
Rik <rik@octave.org>
parents: 21178
diff changeset
165 %!test
10688
7357e37f34fa coordinate transforms: add option to operate on column matrix of coordinates.
Rik <octave@nomad.inbox5.com>
parents: 10687
diff changeset
166 %! C = [0, 0, 0; 1, 0, 1; 2, 0, 2];
28171
a23da76e0693 Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents: 27978
diff changeset
167 %! [t, p, r] = cart2sph (C);
a23da76e0693 Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents: 27978
diff changeset
168 %! assert (t, [0; 0; 0]);
a23da76e0693 Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents: 27978
diff changeset
169 %! assert (p, [0; 1; 1] * pi/4, eps);
a23da76e0693 Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents: 27978
diff changeset
170 %! assert (r, [0; 1; 2] * sqrt (2), eps);
a23da76e0693 Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents: 27978
diff changeset
171
a23da76e0693 Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents: 27978
diff changeset
172 %!test
a23da76e0693 Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents: 27978
diff changeset
173 %! C = [0, 0, 0; 1, 0, 1; 2, 0, 2; 1, 0, 1];
a23da76e0693 Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents: 27978
diff changeset
174 %! [t, p, r] = cart2sph (C);
a23da76e0693 Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents: 27978
diff changeset
175 %! assert (t, [0; 0; 0; 0]);
a23da76e0693 Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents: 27978
diff changeset
176 %! assert (p, [0; 1; 1; 1] * pi/4, eps);
a23da76e0693 Matlab compatibility fixes for coordinate transform functions (bug #57794).
Nicholas R. Jankowski <jankowskin@asme.org>
parents: 27978
diff changeset
177 %! assert (r, [0; 1; 2; 1] * sqrt (2), eps);
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
178
21172
5f62b5dae8b1 Fix regression for coordinate transforms on 3-D arrays (partial fix bug #47036).
Colin Macdonald <cbm@m.fsf.org>
parents: 20181
diff changeset
179 %!test
5f62b5dae8b1 Fix regression for coordinate transforms on 3-D arrays (partial fix bug #47036).
Colin Macdonald <cbm@m.fsf.org>
parents: 20181
diff changeset
180 %! [x, y, z] = meshgrid ([0, 1], [0, 1], [0, 1]);
5f62b5dae8b1 Fix regression for coordinate transforms on 3-D arrays (partial fix bug #47036).
Colin Macdonald <cbm@m.fsf.org>
parents: 20181
diff changeset
181 %! [t, p, r] = cart2sph (x, y, z);
5f62b5dae8b1 Fix regression for coordinate transforms on 3-D arrays (partial fix bug #47036).
Colin Macdonald <cbm@m.fsf.org>
parents: 20181
diff changeset
182 %! T(:, :, 1) = [0, 0; pi/2, pi/4];
5f62b5dae8b1 Fix regression for coordinate transforms on 3-D arrays (partial fix bug #47036).
Colin Macdonald <cbm@m.fsf.org>
parents: 20181
diff changeset
183 %! T(:, :, 2) = T(:, :, 1);
5f62b5dae8b1 Fix regression for coordinate transforms on 3-D arrays (partial fix bug #47036).
Colin Macdonald <cbm@m.fsf.org>
parents: 20181
diff changeset
184 %! P(:, :, 1) = zeros (2, 2);
5f62b5dae8b1 Fix regression for coordinate transforms on 3-D arrays (partial fix bug #47036).
Colin Macdonald <cbm@m.fsf.org>
parents: 20181
diff changeset
185 %! P(:, :, 2) = [pi/2, pi/4; pi/4, acos(sqrt(2/3))];
5f62b5dae8b1 Fix regression for coordinate transforms on 3-D arrays (partial fix bug #47036).
Colin Macdonald <cbm@m.fsf.org>
parents: 20181
diff changeset
186 %! R = sqrt (x .^ 2 + y .^ 2 + z .^ 2);
5f62b5dae8b1 Fix regression for coordinate transforms on 3-D arrays (partial fix bug #47036).
Colin Macdonald <cbm@m.fsf.org>
parents: 20181
diff changeset
187 %! assert (t, T, eps);
5f62b5dae8b1 Fix regression for coordinate transforms on 3-D arrays (partial fix bug #47036).
Colin Macdonald <cbm@m.fsf.org>
parents: 20181
diff changeset
188 %! assert (p, P, eps);
5f62b5dae8b1 Fix regression for coordinate transforms on 3-D arrays (partial fix bug #47036).
Colin Macdonald <cbm@m.fsf.org>
parents: 20181
diff changeset
189 %! assert (r, R, eps);
5f62b5dae8b1 Fix regression for coordinate transforms on 3-D arrays (partial fix bug #47036).
Colin Macdonald <cbm@m.fsf.org>
parents: 20181
diff changeset
190
5f62b5dae8b1 Fix regression for coordinate transforms on 3-D arrays (partial fix bug #47036).
Colin Macdonald <cbm@m.fsf.org>
parents: 20181
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: 28171
diff changeset
192 %!error <Invalid call> cart2sph ()
90fea9cc9caa test: Add expected error message <Invalid call> to BIST tests for nargin.
Rik <rik@octave.org>
parents: 28171
diff changeset
193 %!error <Invalid call> cart2sph (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 C must be a 2-D numeric array> cart2sph ({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 C must be a 2-D numeric array> cart2sph (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 C must be a 3-element> cart2sph ([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 C must be a 3-element> cart2sph ([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> cart2sph ({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> cart2sph ([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> cart2sph ([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> cart2sph ([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> cart2sph (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> cart2sph (ones (3,3,3), ones (3,2,3), 1)