annotate scripts/plot/draw/sphere.m @ 27919:1891570abac8

update Octave Project Developers copyright for the new year In files that have the "Octave Project Developers" copyright notice, update for 2020.
author John W. Eaton <jwe@octave.org>
date Mon, 06 Jan 2020 22:29:51 -0500
parents b442ec6dda5c
children bd51beb6205e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
27919
1891570abac8 update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents: 27918
diff changeset
1 ## Copyright (C) 2007-2020 The Octave Project Developers
27918
b442ec6dda5c use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
2 ##
b442ec6dda5c use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
3 ## See the file COPYRIGHT.md in the top-level directory of this distribution
b442ec6dda5c use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
4 ## or <https://octave.org/COPYRIGHT.html/>.
b442ec6dda5c use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
5 ##
7189
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
6 ##
7224
a3435f7017c4 [project @ 2007-11-30 06:40:37 by jwe]
jwe
parents: 7215
diff changeset
7 ## This file is part of Octave.
7189
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
8 ##
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 24432
diff changeset
9 ## Octave is free software: you can redistribute it and/or modify it
7224
a3435f7017c4 [project @ 2007-11-30 06:40:37 by jwe]
jwe
parents: 7215
diff changeset
10 ## 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: 24432
diff changeset
11 ## the Free Software Foundation, either version 3 of the License, or
22755
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22323
diff changeset
12 ## (at your option) any later version.
7224
a3435f7017c4 [project @ 2007-11-30 06:40:37 by jwe]
jwe
parents: 7215
diff changeset
13 ##
a3435f7017c4 [project @ 2007-11-30 06:40:37 by jwe]
jwe
parents: 7215
diff changeset
14 ## Octave is distributed in the hope that it will be useful, but
a3435f7017c4 [project @ 2007-11-30 06:40:37 by jwe]
jwe
parents: 7215
diff changeset
15 ## WITHOUT ANY WARRANTY; without even the implied warranty of
22755
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22323
diff changeset
16 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22323
diff changeset
17 ## GNU General Public License for more details.
7189
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
18 ##
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
19 ## You should have received a copy of the GNU General Public License
7224
a3435f7017c4 [project @ 2007-11-30 06:40:37 by jwe]
jwe
parents: 7215
diff changeset
20 ## 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: 24432
diff changeset
21 ## <https://www.gnu.org/licenses/>.
7189
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
22
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
23 ## -*- texinfo -*-
20852
516bb87ea72e 2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents: 20173
diff changeset
24 ## @deftypefn {} {} sphere ()
516bb87ea72e 2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents: 20173
diff changeset
25 ## @deftypefnx {} {} sphere (@var{n})
516bb87ea72e 2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents: 20173
diff changeset
26 ## @deftypefnx {} {} sphere (@var{hax}, @dots{})
516bb87ea72e 2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents: 20173
diff changeset
27 ## @deftypefnx {} {[@var{x}, @var{y}, @var{z}] =} sphere (@dots{})
17122
eaab03308c0b doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents: 17051
diff changeset
28 ## Plot a 3-D unit sphere.
eaab03308c0b doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents: 17051
diff changeset
29 ##
eaab03308c0b doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents: 17051
diff changeset
30 ## The optional input @var{n} determines the number of faces around the
20173
777f26aa8e3e doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19697
diff changeset
31 ## circumference of the sphere. The default value is 20.
17122
eaab03308c0b doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents: 17051
diff changeset
32 ##
24431
0c6cedafc71e doc: Use 'axes' rather than 'axis' appropriately in docstrings.
Rik <rik@octave.org>
parents: 23219
diff changeset
33 ## If the first argument @var{hax} is an axes handle, then plot into this axes,
17122
eaab03308c0b doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents: 17051
diff changeset
34 ## rather than the current axes returned by @code{gca}.
7189
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
35 ##
17122
eaab03308c0b doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents: 17051
diff changeset
36 ## If outputs are requested @code{sphere} returns three matrices in
eaab03308c0b doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents: 17051
diff changeset
37 ## @code{meshgrid} format such that @code{surf (@var{x}, @var{y}, @var{z})}
eaab03308c0b doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents: 17051
diff changeset
38 ## generates a unit sphere.
eaab03308c0b doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents: 17051
diff changeset
39 ##
eaab03308c0b doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents: 17051
diff changeset
40 ## Example:
eaab03308c0b doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents: 17051
diff changeset
41 ##
eaab03308c0b doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents: 17051
diff changeset
42 ## @example
eaab03308c0b doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents: 17051
diff changeset
43 ## @group
eaab03308c0b doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents: 17051
diff changeset
44 ## [x, y, z] = sphere (40);
eaab03308c0b doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents: 17051
diff changeset
45 ## surf (3*x, 3*y, 3*z);
eaab03308c0b doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents: 17051
diff changeset
46 ## axis equal;
eaab03308c0b doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents: 17051
diff changeset
47 ## title ("sphere of radius 3");
eaab03308c0b doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents: 17051
diff changeset
48 ## @end group
eaab03308c0b doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents: 17051
diff changeset
49 ## @end example
eaab03308c0b doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents: 17051
diff changeset
50 ## @seealso{cylinder, ellipsoid, rectangle}
7189
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
51 ## @end deftypefn
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
52
7215
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7191
diff changeset
53 function [xx, yy, zz] = sphere (varargin)
7189
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
54
17051
3e1b24a2454a cylinder.m, ellipsoid.m, rectangle.m, sphere.m: Update to use new __plt_get_axis_arg__.
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 14138
diff changeset
55 [hax, varargin, nargin] = __plt_get_axis_arg__ ("sphere", varargin{:});
3e1b24a2454a cylinder.m, ellipsoid.m, rectangle.m, sphere.m: Update to use new __plt_get_axis_arg__.
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 14138
diff changeset
56
7215
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7191
diff changeset
57 if (nargin > 1)
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7191
diff changeset
58 print_usage ();
7191
b48a21816f2e [project @ 2007-11-26 21:24:32 by jwe]
jwe
parents: 7189
diff changeset
59 elseif (nargin == 1)
7215
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7191
diff changeset
60 n = varargin{1};
7189
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
61 else
7191
b48a21816f2e [project @ 2007-11-26 21:24:32 by jwe]
jwe
parents: 7189
diff changeset
62 n = 20;
7189
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
63 endif
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
64
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
65 theta = linspace (0, 2*pi, n+1);
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
66 phi = linspace (-pi/2, pi/2, n+1);
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
67 [theta,phi] = meshgrid (theta, phi);
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
68
7191
b48a21816f2e [project @ 2007-11-26 21:24:32 by jwe]
jwe
parents: 7189
diff changeset
69 x = cos (phi) .* cos (theta);
b48a21816f2e [project @ 2007-11-26 21:24:32 by jwe]
jwe
parents: 7189
diff changeset
70 y = cos (phi) .* sin (theta);
b48a21816f2e [project @ 2007-11-26 21:24:32 by jwe]
jwe
parents: 7189
diff changeset
71 z = sin (phi);
7189
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
72
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
73 if (nargout > 0)
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
74 xx = x;
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
75 yy = y;
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
76 zz = z;
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
77 else
17476
f0f4b524b6d0 maint: Correct indentation for several plot routines.
Rik <rik@octave.org>
parents: 17338
diff changeset
78 oldfig = [];
f0f4b524b6d0 maint: Correct indentation for several plot routines.
Rik <rik@octave.org>
parents: 17338
diff changeset
79 if (! isempty (hax))
f0f4b524b6d0 maint: Correct indentation for several plot routines.
Rik <rik@octave.org>
parents: 17338
diff changeset
80 oldfig = get (0, "currentfigure");
f0f4b524b6d0 maint: Correct indentation for several plot routines.
Rik <rik@octave.org>
parents: 17338
diff changeset
81 endif
17051
3e1b24a2454a cylinder.m, ellipsoid.m, rectangle.m, sphere.m: Update to use new __plt_get_axis_arg__.
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 14138
diff changeset
82 unwind_protect
3e1b24a2454a cylinder.m, ellipsoid.m, rectangle.m, sphere.m: Update to use new __plt_get_axis_arg__.
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 14138
diff changeset
83 hax = newplot (hax);
19593
446c46af4b42 strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 17744
diff changeset
84
17126
26589abbc78d Don't pass axis handle unnecessarily from high level to low level plot functions.
Rik <rik@octave.org>
parents: 17122
diff changeset
85 surf (x, y, z);
17051
3e1b24a2454a cylinder.m, ellipsoid.m, rectangle.m, sphere.m: Update to use new __plt_get_axis_arg__.
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 14138
diff changeset
86 unwind_protect_cleanup
3e1b24a2454a cylinder.m, ellipsoid.m, rectangle.m, sphere.m: Update to use new __plt_get_axis_arg__.
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 14138
diff changeset
87 if (! isempty (oldfig))
3e1b24a2454a cylinder.m, ellipsoid.m, rectangle.m, sphere.m: Update to use new __plt_get_axis_arg__.
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 14138
diff changeset
88 set (0, "currentfigure", oldfig);
3e1b24a2454a cylinder.m, ellipsoid.m, rectangle.m, sphere.m: Update to use new __plt_get_axis_arg__.
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 14138
diff changeset
89 endif
3e1b24a2454a cylinder.m, ellipsoid.m, rectangle.m, sphere.m: Update to use new __plt_get_axis_arg__.
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 14138
diff changeset
90 end_unwind_protect
7189
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
91 endif
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
92
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
93 endfunction