Mercurial > hg > octave-lyh
annotate scripts/plot/sphere.m @ 17051:3e1b24a2454a
cylinder.m, ellipsoid.m, rectangle.m, sphere.m: Update to use new __plt_get_axis_arg__.
* scripts/plot/cylinder.m, scripts/plot/ellipsoid.m, scripts/plot/rectangle.m,
scripts/plot/sphere.m: Update to use new __plt_get_axis_arg__.
Rename ax to hax.
author | Pantxo Diribarne <pantxo.diribarne@gmail.com> |
---|---|
date | Tue, 23 Jul 2013 16:06:07 +0200 |
parents | 72c96de7a403 |
children | eaab03308c0b |
rev | line source |
---|---|
14138
72c96de7a403
maint: update copyright notices for 2012
John W. Eaton <jwe@octave.org>
parents:
12575
diff
changeset
|
1 ## Copyright (C) 2007-2012 Michael Goffioul |
7189 | 2 ## |
7224 | 3 ## This file is part of Octave. |
7189 | 4 ## |
7224 | 5 ## Octave is free software; you can redistribute it and/or modify it |
6 ## under the terms of the GNU General Public License as published by | |
7 ## the Free Software Foundation; either version 3 of the License, or (at | |
8 ## your option) any later version. | |
9 ## | |
10 ## Octave is distributed in the hope that it will be useful, but | |
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
13 ## General Public License for more details. | |
7189 | 14 ## |
15 ## You should have received a copy of the GNU General Public License | |
7224 | 16 ## along with Octave; see the file COPYING. If not, see |
17 ## <http://www.gnu.org/licenses/>. | |
7189 | 18 |
19 ## -*- texinfo -*- | |
10793
be55736a0783
Grammarcheck the documentation from m-files.
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
20 ## @deftypefn {Function File} {[@var{x}, @var{y}, @var{z}] =} sphere (@var{n}) |
7189 | 21 ## @deftypefnx {Function File} {} sphere (@var{h}, @dots{}) |
12575
d0b799dafede
Grammarcheck files for 3.4.1 release.
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
22 ## Generate three matrices in @code{meshgrid} format, such that |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
23 ## @code{surf (@var{x}, @var{y}, @var{z})} generates a unit sphere. |
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
24 ## The matrices of @code{@var{n}+1}-by-@code{@var{n}+1}. If @var{n} is |
7189 | 25 ## omitted then a default value of 20 is assumed. |
26 ## | |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
27 ## Called with no return arguments, @code{sphere} call directly |
9040
dbd0c77e575e
Cleanup documentation file plot.texi
Rik <rdrider0-list@yahoo.com>
parents:
7224
diff
changeset
|
28 ## @code{surf (@var{x}, @var{y}, @var{z})}. If an axes handle is passed |
dbd0c77e575e
Cleanup documentation file plot.texi
Rik <rdrider0-list@yahoo.com>
parents:
7224
diff
changeset
|
29 ## as the first argument, the surface is plotted to this set of axes. |
7189 | 30 ## @seealso{peaks} |
31 ## @end deftypefn | |
32 | |
7215 | 33 function [xx, yy, zz] = sphere (varargin) |
7189 | 34 |
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
|
35 [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
|
36 |
7215 | 37 if (nargin > 1) |
38 print_usage (); | |
7191 | 39 elseif (nargin == 1) |
7215 | 40 n = varargin{1}; |
7189 | 41 else |
7191 | 42 n = 20; |
7189 | 43 endif |
44 | |
45 theta = linspace (0, 2*pi, n+1); | |
46 phi = linspace (-pi/2, pi/2, n+1); | |
47 [theta,phi] = meshgrid (theta, phi); | |
48 | |
7191 | 49 x = cos (phi) .* cos (theta); |
50 y = cos (phi) .* sin (theta); | |
51 z = sin (phi); | |
7189 | 52 |
53 if (nargout > 0) | |
54 xx = x; | |
55 yy = y; | |
56 zz = z; | |
57 else | |
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
|
58 oldfig = ifelse (isempty (hax), [], get (0, "currentfigure")); |
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
|
59 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
|
60 hax = newplot (hax); |
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
|
61 |
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
|
62 surf (hax, x, y, z); |
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
|
63 |
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
|
64 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
|
65 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
|
66 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
|
67 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
|
68 end_unwind_protect |
7189 | 69 endif |
70 | |
71 endfunction |